Exemplo n.º 1
0
 public function shouldSkipEmbedded($object, Relation $relation, SerializationContext $context)
 {
     if (null === $relation->getEmbedded()) {
         return true;
     }
     if (null === $relation->getEmbedded()->getExclusion()) {
         return $this->shouldSkipRelation($object, $relation, $context);
     }
     return $this->shouldSkip($object, $relation, $relation->getEmbedded()->getExclusion(), $context);
 }
Exemplo n.º 2
0
 public function __construct(Exclusion $exclusion = null, Relation $relation = null)
 {
     if (null !== $relation) {
         $this->name = $relation->getName();
         $this->class = get_class($relation);
         $typeParser = new TypeParser();
         if (null !== $relation->getEmbedded()) {
             $this->type = $typeParser->parse('Hateoas\\Model\\Embedded');
         } elseif (null !== $relation->getHref()) {
             $this->type = $typeParser->parse('Hateoas\\Model\\Link');
         }
     }
     if (null === $exclusion) {
         return;
     }
     $this->groups = $exclusion->getGroups();
     $this->sinceVersion = $exclusion->getSinceVersion();
     $this->untilVersion = $exclusion->getUntilVersion();
     $this->maxDepth = $exclusion->getMaxDepth();
 }
Exemplo n.º 3
0
 /**
  * @param object   $object
  * @param Relation $relation
  *
  * @return Link
  */
 public function createLink($object, Relation $relation)
 {
     $rel = $this->expressionEvaluator->evaluate($relation->getName(), $object);
     $href = $relation->getHref();
     if ($href instanceof Route) {
         if (!$this->urlGeneratorRegistry->hasGenerators()) {
             throw new \RuntimeException('You cannot use a route without an url generator.');
         }
         $name = $this->expressionEvaluator->evaluate($href->getName(), $object);
         $parameters = is_array($href->getParameters()) ? $this->expressionEvaluator->evaluateArray($href->getParameters(), $object) : $this->expressionEvaluator->evaluate($href->getParameters(), $object);
         if (!is_array($parameters)) {
             throw new \RuntimeException(sprintf('The route parameters should be an array, %s given. Maybe you forgot to wrap the expression in expr(...).', gettype($parameters)));
         }
         $href = $this->urlGeneratorRegistry->get($href->getGenerator())->generate($name, $parameters, $href->isAbsolute());
     } else {
         $href = $this->expressionEvaluator->evaluate($href, $object);
     }
     $attributes = $this->expressionEvaluator->evaluateArray($relation->getAttributes(), $object);
     return new Link($rel, $href, $attributes);
 }
Exemplo n.º 4
0
 private function patchAbsolute(Relation $relation, $absolute)
 {
     $href = $relation->getHref();
     if ($href instanceof Route) {
         $href = new Route($href->getName(), $href->getParameters(), $absolute, $href->getGenerator());
     }
     return new Relation($relation->getName(), $href, $relation->getEmbed(), $relation->getAttributes(), $relation->getExclusion());
 }
Exemplo n.º 5
0
 public function canBeConstructedWithOnlyAnEmbed()
 {
     $relation = new Relation('self', null, 'foo');
     $this->assertSame('self', $relation->getName());
     $this->assertNull($relation->getHref());
     $this->assertEmpty($relation->getAttributes());
     $this->assertInstanceOf('Hateoas\\Configuration\\Embed', $relation->getEmbedded());
     $this->assertSame('foo', $relation->getEmbedded()->getContent());
 }
Exemplo n.º 6
0
 private function shouldSkipRelation($object, Relation $relation, SerializationContext $context)
 {
     return $this->shouldSkip($object, $relation->getExclusion(), $context);
 }
 /**
  * @param Relation $relation
  * @return Relation
  */
 private function transformRelation(Relation $relation)
 {
     return new Relation($relation->getName(), $relation->getHref(), $relation->getEmbedded(), $relation->getAttributes(), $this->transformExclusion($relation->getExclusion()));
 }