Ejemplo n.º 1
0
 /**
  * @inheritDoc
  */
 public function injectSelfLink(LinkCollectionAwareInterface $resource, $route, $routeIdentifier = 'id')
 {
     $links = $resource->getLinks();
     if ($links->has('self')) {
         return;
     }
     $selfLink = $this->createSelfLink($resource, $route, $routeIdentifier);
     $links->add($selfLink, true);
 }
Ejemplo n.º 2
0
 /**
  * Inject a "self" relational link based on the route and identifier
  *
  * @param  LinkCollectionAwareInterface $resource
  * @param  string $route
  * @param  string $routeIdentifier
  */
 public function injectSelfLink(LinkCollectionAwareInterface $resource, $route, $routeIdentifier = 'id')
 {
     $links = $resource->getLinks();
     if ($links->has('self')) {
         return;
     }
     $self = new Link('self');
     $self->setRoute($route);
     $routeParams = [];
     $routeOptions = [];
     if ($resource instanceof Entity && null !== $resource->id) {
         $routeParams = [$routeIdentifier => $resource->id];
     }
     if ($resource instanceof Collection) {
         $routeParams = $resource->getCollectionRouteParams();
         $routeOptions = $resource->getCollectionRouteOptions();
     }
     if (!empty($routeParams)) {
         $self->setRouteParams($routeParams);
     }
     if (!empty($routeOptions)) {
         $self->setRouteOptions($routeOptions);
     }
     $links->add($self, true);
 }
Ejemplo n.º 3
0
 /**
  * Create HAL links "object" from an entity or collection
  *
  * @param  LinkCollectionAwareInterface $resource
  * @return array
  */
 public function fromResource(LinkCollectionAwareInterface $resource)
 {
     return $this->fromLinkCollection($resource->getLinks());
 }