Ejemplo n.º 1
0
 public function onPostSerialize(ObjectEvent $event)
 {
     $embeds = $this->embedsFactory->create($event->getObject(), $event->getContext());
     $links = $this->linksFactory->createLinks($event->getObject(), $event->getContext());
     if (count($links) > 0) {
         $this->xmlSerializer->serializeLinks($links, $event->getVisitor());
     }
     if (count($embeds) > 0) {
         $this->xmlSerializer->serializeEmbedded($embeds, $event->getVisitor(), $event->getContext());
     }
 }
Ejemplo n.º 2
0
 public function onPostSerialize(ObjectEvent $event)
 {
     $object = $event->getObject();
     $context = $event->getContext();
     $embeds = $this->embedsFactory->create($object, $context);
     $links = $this->linksFactory->createLinks($object, $context);
     $embeds = $this->embedsInlineDeferrer->handleItems($object, $embeds, $context);
     $links = $this->linksInlineDeferrer->handleItems($object, $links, $context);
     if (count($links) > 0) {
         $this->jsonSerializer->serializeLinks($links, $event->getVisitor());
     }
     if (count($embeds) > 0) {
         $this->jsonSerializer->serializeEmbedded($embeds, $event->getVisitor(), $context);
     }
 }
Ejemplo n.º 3
0
 public function test()
 {
     $object = new \StdClass();
     $context = SerializationContext::create();
     $relations = array(new Relation('self', '/users/1'), new Relation('manager', '/users/2'));
     $link = new Link('', '');
     $relationsRepositoryProphecy = $this->prophesize('Hateoas\\Configuration\\RelationsRepository');
     $relationsRepositoryProphecy->getRelations($object)->willReturn($relations)->shouldBeCalledTimes(1);
     $linkFactoryProphecy = $this->prophesize('Hateoas\\Factory\\LinkFactory');
     $linkFactoryProphecy->createLink($object, $relations[1])->willReturn($link)->shouldBeCalledTimes(1);
     $exclusionManagerProphecy = $this->prophesize('Hateoas\\Serializer\\ExclusionManager');
     $exclusionManagerProphecy->shouldSkipLink($object, $relations[0], $context)->willReturn(true)->shouldBeCalledTimes(1);
     $exclusionManagerProphecy->shouldSkipLink($object, $relations[1], $context)->willReturn(false)->shouldBeCalledTimes(1);
     $linksFactory = new LinksFactory($relationsRepositoryProphecy->reveal(), $linkFactoryProphecy->reveal(), $exclusionManagerProphecy->reveal());
     $links = $linksFactory->createLinks($object, $context);
     $this->array($links)->hasSize(1)->contains($link);
 }