Example #1
0
 /**
  * Extract the relations of the resource to make a formatted array.
  *
  * @param ResourceInterface $resource
  *
  * @return array
  */
 protected function getRelations(ResourceInterface $resource)
 {
     $formattedRelations = [];
     /** @var Resource $subResource */
     foreach ($resource->getRelations() as $subResource) {
         $formattedRelations[] = [$subResource->getName() => ['data' => $subResource->getProperties()]];
     }
     return $formattedRelations;
 }
Example #2
0
 /**
  * @param ResourceInterface $resource
  *
  * @return array
  */
 protected function formatLinks(ResourceInterface $resource) : array
 {
     $links = ["links" => ["self" => $resource->getBaseUri() . $resource->getName()]];
     if ($this->hasPaginator()) {
         $links['links'] += ["first" => $resource->getBaseUri() . $resource->getName() . '?page=1', "last" => $resource->getBaseUri() . $resource->getName() . '?page=' . $this->getPaginator()->getLastPage()];
         if ($this->getPaginator()->getCurrentPage() < $this->getPaginator()->getLastPage()) {
             $links['links']['next'] = $resource->getBaseUri() . $resource->getName() . '?page=' . ($this->getPaginator()->getCurrentPage() + 1);
         }
         if ($this->getPaginator()->getCurrentPage() > 1) {
             $links['links']['prev'] = $resource->getBaseUri() . $resource->getName() . '?page=' . ($this->getPaginator()->getCurrentPage() - 1);
         }
     }
     return $links;
 }
Example #3
0
 /**
  * @param ResourceInterface $resource
  *
  * @return ResourceSet
  */
 public function addChild(ResourceInterface $resource) : ResourceSet
 {
     $this->resources[$resource->getId()] = $resource;
     return $this;
 }