예제 #1
0
 public function testRelationProviderRelations()
 {
     $relations = array(new Relation('', ''), new Relation('', ''));
     $object = new \StdClass();
     $relationsRepository = new RelationsRepository($this->prophesizeMetadataFactory()->reveal(), $this->prophesizeRelationProvider($relations, $object)->reveal());
     $this->array($relationsRepository->getRelations($object))->isEqualTo($relations);
 }
예제 #2
0
 /**
  * @param object               $object
  * @param SerializationContext $context
  *
  * @return Link[]
  */
 public function createLinks($object, SerializationContext $context)
 {
     $links = array();
     foreach ($this->relationsRepository->getRelations($object) as $relation) {
         if ($this->exclusionManager->shouldSkipLink($object, $relation, $context)) {
             continue;
         }
         $links[] = $this->linkFactory->createLink($object, $relation);
     }
     return $links;
 }
예제 #3
0
 /**
  * @param object  $object
  * @param string  $rel
  * @param boolean $absolute
  *
  * @return string
  */
 public function getLinkHref($object, $rel, $absolute = false)
 {
     foreach ($this->relationsRepository->getRelations($object) as $relation) {
         if ($rel === $relation->getName()) {
             $relation = $this->patchAbsolute($relation, $absolute);
             if (null !== ($link = $this->linkFactory->createLink($object, $relation))) {
                 return $link->getHref();
             }
         }
     }
     return null;
 }
예제 #4
0
 /**
  * @param  object               $object
  * @param  SerializationContext $context
  * @return Embed[]
  */
 public function create($object, SerializationContext $context)
 {
     $embeds = array();
     foreach ($this->relationsRepository->getRelations($object) as $relation) {
         if ($this->exclusionManager->shouldSkipEmbed($object, $relation, $context)) {
             continue;
         }
         $rel = $this->expressionEvaluator->evaluate($relation->getName(), $object);
         $data = $this->expressionEvaluator->evaluate($relation->getEmbed()->getContent(), $object);
         $xmlElementName = $this->expressionEvaluator->evaluate($relation->getEmbed()->getXmlElementName(), $object);
         $embeds[] = new Embed($rel, $data, $xmlElementName);
     }
     return $embeds;
 }