Exemplo n.º 1
0
 public function testCanSetRouteOptionsSeparately()
 {
     $route = 'api/docs';
     $options = ['query' => 'version=1.1'];
     $property = new Property('describedby');
     $property->setRoute($route);
     $property->setRouteOptions($options);
     $this->assertEquals($route, $property->getRoute());
     $this->assertEquals($options, $property->getRouteOptions());
 }
Exemplo n.º 2
0
 /**
  * Inject a "id"  based on the route and identifier
  *
  * @param  PropertyCollectionAwareInterface $resource
  * @param  string $route
  * @param  string $routeIdentifier
  */
 public function injectIDProperty(PropertyCollectionAwareInterface $resource, $route, $routeIdentifier = 'id')
 {
     $properties = $resource->getProperties();
     if ($properties->has('id')) {
         return;
     }
     $id = new Property('id');
     $id->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)) {
         $id->setRouteParams($routeParams);
     }
     if (!empty($routeOptions)) {
         $id->setRouteOptions($routeOptions);
     }
     $properties->add($id, true);
 }