Function.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. /*
  3. * This file is part of Twig.
  4. *
  5. * (c) 2010 Fabien Potencier
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. class Twig_Node_Expression_Function extends Twig_Node_Expression_Call
  11. {
  12. public function __construct($name, Twig_NodeInterface $arguments, $lineno)
  13. {
  14. parent::__construct(array('arguments' => $arguments), array('name' => $name), $lineno);
  15. }
  16. public function compile(Twig_Compiler $compiler)
  17. {
  18. $name = $this->getAttribute('name');
  19. $function = $compiler->getEnvironment()->getFunction($name);
  20. $this->setAttribute('name', $name);
  21. $this->setAttribute('type', 'function');
  22. $this->setAttribute('thing', $function);
  23. $this->setAttribute('needs_environment', $function->needsEnvironment());
  24. $this->setAttribute('needs_context', $function->needsContext());
  25. $this->setAttribute('arguments', $function->getArguments());
  26. if ($function instanceof Twig_FunctionCallableInterface || $function instanceof Twig_SimpleFunction) {
  27. $this->setAttribute('callable', $function->getCallable());
  28. }
  29. $this->compileCallable($compiler);
  30. }
  31. }