Exemplo n.º 1
0
 public function testCanSetRouteParamsSeparately()
 {
     $route = 'api/docs';
     $params = ['version' => '1.1'];
     $property = new Property('describedby');
     $property->setRoute($route);
     $property->setRouteParams($params);
     $this->assertEquals($route, $property->getRoute());
     $this->assertEquals($params, $property->getRouteParams());
 }
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);
 }
 public function setUpChildEntity($id, $name)
 {
     $this->child = (object) ['id' => $id, 'name' => $name];
     $entity = new Entity($this->child, $id);
     $property = new Property('some');
     $property->setRoute('parent/child');
     $property->setRouteParams(['child' => $id]);
     $entity->getProperties()->add($property);
     return $entity;
 }