public function evaluateArray(array $array, $data) { if (!empty($this->functionsIds)) { $this->registerFunctions(); } return parent::evaluateArray($array, $data); }
/** * @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); }
public function testEvaluateArray() { $parsedExpressions = array(new ParsedExpression('a', new Node()), new ParsedExpression('aa', new Node()), new ParsedExpression('aaa', new Node())); $data = new \StdClass(); $ELProphecy = $this->prophesize('Symfony\\Component\\ExpressionLanguage\\ExpressionLanguage'); $ELProphecy->parse('a', array('object'))->willReturn($parsedExpressions[0])->shouldBeCalledTimes(1); $ELProphecy->parse('aa', array('object'))->willReturn($parsedExpressions[1])->shouldBeCalledTimes(1); $ELProphecy->parse('aaa', array('object'))->willReturn($parsedExpressions[2])->shouldBeCalledTimes(1); $ELProphecy->evaluate($parsedExpressions[0], array('object' => $data))->willReturn(1); $ELProphecy->evaluate($parsedExpressions[1], array('object' => $data))->willReturn(2); $ELProphecy->evaluate($parsedExpressions[2], array('object' => $data))->willReturn(3); $expressionEvaluator = new ExpressionEvaluator($ELProphecy->reveal()); $array = array('expr(a)' => 'expr(aa)', 'hello' => array('expr(aaa)')); $this->array($expressionEvaluator->evaluateArray($array, $data))->isEqualTo(array(1 => 2, 'hello' => array(3))); }
public function evaluateArray(array $array, $data) { $this->registerFunctions(); return parent::evaluateArray($array, $data); }