/** * @dataProvider getTestSkipExcludeIfData */ public function testSkipExcludeIf($exclude) { $object = (object) array('name' => 'adrien'); $exclusion = new Exclusion(null, null, null, null, 'expr(stuff)'); $relation = new Relation('foo', 'foo', 'foo', array(), $exclusion); $context = SerializationContext::create(); $expressionEvaluatorProphecy = $this->prophesizeExpressionEvaluator(); $expressionEvaluatorProphecy->evaluate('expr(stuff)', $object)->willReturn($exclude); $exclusionManager = new ExclusionManager($expressionEvaluatorProphecy->reveal()); $this->boolean($exclusionManager->shouldSkipLink($object, $relation, $context))->isEqualTo($exclude)->boolean($exclusionManager->shouldSkipEmbed($object, $relation, $context))->isEqualTo($exclude); }
/** * @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; }
/** * @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; }