/** * Get Embedded of current resource in XML format * * @param RApiHalDocumentResource $embed Embedded object * * @return SimpleXMLElement */ protected function _getEmbRes(RApiHalDocumentResource $embed) { $resource = $this->xml->addChild('resource'); return $embed->getXML($resource); }
/** * Loads Resource list from configuration file for specific method or task * * @param SimpleXMLElement $configuration Configuration for displaying object * * @return array */ public function loadResourceFromConfiguration($configuration) { if (isset($configuration->resources->resource)) { foreach ($configuration->resources->resource as $resourceXML) { $resource = RApiHalHelper::getXMLElementAttributes($resourceXML); // Filters out specified displayGroup values if ($this->options->get('filterOutResourcesGroups') != '' && in_array($resource['displayGroup'], $this->options->get('filterOutResourcesGroups'))) { continue; } // Filters out if the optional resourceSpecific filter is not the one defined if ($this->options->get('filterResourcesSpecific') != '' && $resource['resourceSpecific'] != $this->options->get('filterResourcesSpecific')) { continue; } // Filters out if the optional displayName filter is not the one defined if ($this->options->get('filterDisplayName') != '' && $resource['displayName'] != $this->options->get('filterDisplayName')) { continue; } if (!empty($resourceXML->description)) { $resource['description'] = $resourceXML->description; } $resource = RApiHalDocumentResource::defaultResourceField($resource); $resourceName = $resource['displayName']; $resourceSpecific = $resource['resourceSpecific']; $this->resources[$resourceSpecific][$resourceName] = $resource; } } return $this->resources; }
/** * Method to convert relative to absolute links. * * @param RApiHalDocumentResource $hal Hal object which contains links (_links). * @param boolean $absoluteHrefs Should we replace link Href with absolute. * * @return void */ protected function relToAbs($hal, $absoluteHrefs) { if ($links = $hal->getLinks()) { // Adjust hrefs in the _links object. /* @var $link RApiHalDocumentLink */ foreach ($links as $link) { if (is_array($link)) { foreach ($link as $group => $arrayLink) { $href = $arrayLink->getHref(); $href = $this->addUriParameters($href, $absoluteHrefs); $arrayLink->setHref($href); $hal->setReplacedLink($arrayLink, $group); } } else { $href = $link->getHref(); $href = $this->addUriParameters($href, $absoluteHrefs); $link->setHref($href); $hal->setReplacedLink($link); } } } // Adjust hrefs in the _embedded object (if there is one). if ($embedded = $hal->getEmbedded()) { foreach ($embedded as $resources) { if (is_object($resources)) { $this->relToAbs($resources, $absoluteHrefs); } elseif (is_array($resources)) { foreach ($resources as $resource) { if (is_object($resource)) { $this->relToAbs($resource, $absoluteHrefs); } } } } } }