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());
     }
 }
Example #2
0
 public function onPostSerialize(ObjectEvent $event)
 {
     $object = $event->getObject();
     $context = $event->getContext();
     $embeddeds = $this->embeddedsFactory->create($object, $context);
     $links = $this->linksFactory->create($object, $context);
     $embeddeds = $this->embeddedsInlineDeferrer->handleItems($object, $embeddeds, $context);
     $links = $this->linksInlineDeferrer->handleItems($object, $links, $context);
     if (count($links) > 0) {
         $this->jsonSerializer->serializeLinks($links, $event->getVisitor(), $context);
     }
     if (count($embeddeds) > 0) {
         $this->jsonSerializer->serializeEmbeddeds($embeddeds, $event->getVisitor(), $context);
     }
 }
 public function onPostSerialize(ObjectEvent $event)
 {
     $object = $event->getObject();
     $context = $event->getContext();
     $context->startVisiting($object);
     $embeddeds = $this->embeddedsFactory->create($object, $context);
     $links = $this->linksFactory->create($object, $context);
     if (count($links) > 0) {
         $this->xmlSerializer->serializeLinks($links, $event->getVisitor(), $context);
     }
     if (count($embeddeds) > 0) {
         $this->xmlSerializer->serializeEmbeddeds($embeddeds, $event->getVisitor(), $context);
     }
     $context->stopVisiting($object);
 }
 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);
 }