FunctionNode.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\ExpressionLanguage\Node;
  11. use Symfony\Component\ExpressionLanguage\Compiler;
  12. /**
  13. * @author Fabien Potencier <fabien@symfony.com>
  14. *
  15. * @internal
  16. */
  17. class FunctionNode extends Node
  18. {
  19. public function __construct($name, Node $arguments)
  20. {
  21. parent::__construct(
  22. array('arguments' => $arguments),
  23. array('name' => $name)
  24. );
  25. }
  26. public function compile(Compiler $compiler)
  27. {
  28. $arguments = array();
  29. foreach ($this->nodes['arguments']->nodes as $node) {
  30. $arguments[] = $compiler->subcompile($node);
  31. }
  32. $function = $compiler->getFunction($this->attributes['name']);
  33. $compiler->raw(\call_user_func_array($function['compiler'], $arguments));
  34. }
  35. public function evaluate($functions, $values)
  36. {
  37. $arguments = array($values);
  38. foreach ($this->nodes['arguments']->nodes as $node) {
  39. $arguments[] = $node->evaluate($functions, $values);
  40. }
  41. return \call_user_func_array($functions[$this->attributes['name']]['evaluator'], $arguments);
  42. }
  43. }