Source for file document.php
Documentation is available at document.php
* @package FrameworkOnFramework
* @copyright Copyright (C) 2010 - 2012 Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* Implementation of the Hypertext Application Language document in PHP. It can
* be used to provide hypermedia in a web service context.
* @package FrameworkOnFramework
* The collection of links of this document
* The data (resource state or collection of resource state objects) of the
* Embedded documents. This is an array of FOFHalDocument instances.
private $_embedded =
array();
* When $_data is an array we'll output the list of data under this key
private $_dataKey =
'_list';
* @param mixed $data The data of the document (usually, the resource state)
* Add a link to the document
* @param string $rel The relation of the link to the document.
* See RFC 5988 http://tools.ietf.org/html/rfc5988#section-6.2.2 A document MUST always have
* @param FOFHalLink $link The actual link object
* @param boolean $overwrite When false and a link of $rel relation exists, an array of links is created. Otherwise the
* existing link is overwriten with the new one
* @see FOFHalLinks::addLink
* @return boolean True if the link was added to the collection
public function addLink($rel, FOFHalLink $link, $overwrite =
true)
return $this->_links->addLink($rel, $link, $overwrite);
* Add links to the document
* @param string $rel The relation of the link to the document. See RFC 5988
* @param array $links An array of FOFHalLink objects
* @param boolean $overwrite When false and a link of $rel relation exists, an array of
* links is created. Otherwise the existing link is overwriten
* @see FOFHalLinks::addLinks
public function addLinks($rel, array $links, $overwrite =
true)
return $this->_links->addLinks($rel, $links, $overwrite);
* Add data to the document
* @param stdClass $data The data to add
* @param boolean $overwrite Should I overwrite existing data?
public function addData($data, $overwrite =
true)
$this->_data =
array($this->_data);
* Add an embedded document
* @param string $rel The relation of the embedded document to its container document
* @param FOFHalDocument $document The document to add
* @param boolean $overwrite Should I overwrite existing data with the same relation?
public function addEmbedded($rel, FOFHalDocument $document, $overwrite =
true)
$this->_embedded[$rel] =
$document;
$this->_embedded[$rel] =
array($this->_embedded[$rel]);
$this->_embedded[$rel][] =
$document;
* Returns the collection of links of this document
* @param string $rel The relation of the links to fetch. Skip to get all links.
* Returns the collection of embedded documents
* @param string $rel Optional; the relation to return the embedded documents for
* @return array|FOFHalDocument
elseif (isset
($this->_embedded[$rel]))
return $this->_embedded[$rel];
* Return the data attached to this document
* Instantiate and call a suitable renderer class to render this document
* into the specified format.
* @param string $format The format to render the document into, e.g. 'json'
* @return string The rendered document
* @throws RuntimeException If the format is unknown, i.e. there is no suitable renderer
public function render($format =
'json')
$class_name =
'FOFHalRender' .
ucfirst($format);
throw
new RuntimeException("Unsupported HAL Document format '$format'. Render aborted.");
$renderer =
new $class_name($this);
'data_key' =>
$this->_dataKey
Documentation generated on Tue, 19 Nov 2013 15:01:37 +0100 by phpDocumentor 1.4.3