コード例 #1
0
ファイル: HalXmlRenderer.php プロジェクト: solvire/hal
 /**
  * Render.
  *
  * @param \Nocarrier\Hal $resource
  * @param bool $pretty
  * @return string
  */
 public function render(Hal $resource, $pretty, $encode = true)
 {
     $doc = new \SimpleXMLElement('<resource></resource>');
     if (!is_null($resource->getUri())) {
         $doc->addAttribute('href', $resource->getUri());
     }
     $this->linksForXml($doc, $resource->getLinks());
     $this->arrayToXml($resource->getData(), $doc);
     foreach ($resource->getResources() as $rel => $resources) {
         $this->resourcesForXml($doc, $rel, $resources);
     }
     $dom = dom_import_simplexml($doc);
     if ($pretty) {
         $dom->ownerDocument->preserveWhiteSpace = false;
         $dom->ownerDocument->formatOutput = true;
     }
     return $dom->ownerDocument->saveXML();
 }
コード例 #2
0
ファイル: HalJsonRenderer.php プロジェクト: solvire/hal
 /**
  * Return an array (compatible with the hal+json format) representing the
  * complete response.
  *
  * @param \Nocarrier\Hal $resource
  * @return array
  */
 protected function arrayForJson(Hal $resource = null)
 {
     if ($resource == null) {
         return array();
     }
     $data = $resource->getData();
     if ($resource->getShouldStripAttributes()) {
         $data = $this->stripAttributeMarker($data);
     }
     $links = $this->linksForJson($resource->getUri(), $resource->getLinks(), $resource->getArrayLinkRels());
     if (count($links)) {
         $data['_links'] = $links;
     }
     foreach ($resource->getRawResources() as $rel => $resources) {
         if (count($resources) === 1 && !in_array($rel, $resource->getArrayResourceRels())) {
             $resources = $resources[0];
         }
         $data['_embedded'][$rel] = $this->resourcesForJson($resources);
     }
     return $data;
 }
コード例 #3
0
ファイル: HalJsonRenderer.php プロジェクト: natmchugh/hal
 /**
  * Return an array (compatible with the hal+json format) representing the
  * complete response
  *
  * @param Hal $resource
  * @return array
  */
 protected function arrayForJson(Hal $resource)
 {
     $data = $resource->getData();
     $data['_links'] = $this->linksForJson($resource->getUri(), $resource->getLinks());
     foreach ($resource->getResources() as $rel => $resources) {
         $data['_embedded'][$rel] = $this->resourcesForJson($resources);
     }
     return $data;
 }
コード例 #4
0
ファイル: HalJsonRenderer.php プロジェクト: BWorld/hal-1
 /**
  * Return an array (compatible with the hal+json format) representing the
  * complete response.
  *
  * @param \Nocarrier\Hal $resource
  * @return array
  */
 protected function arrayForJson(Hal $resource = null)
 {
     if ($resource == null) {
         return array();
     }
     $data = $resource->getData();
     $data = $this->stripAttributeMarker($data);
     $links = $this->linksForJson($resource->getUri(), $resource->getLinks());
     if (count($links)) {
         $data['_links'] = $links;
     }
     foreach ($resource->getResources() as $rel => $resources) {
         $data['_embedded'][$rel] = $this->resourcesForJson($resources);
     }
     return $data;
 }