コード例 #1
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;
 }