Changeset 1101:7273894e61b8 for inc/libs/twig/Node/Expression/Function.php
- Timestamp:
- 02/15/13 08:35:19 (13 years ago)
- Branch:
- twig
- Children:
- 1106:a4487f3ca4b4, 1147:2e5cb79e4782
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/libs/twig/Node/Expression/Function.php
r991 r1101 9 9 * file that was distributed with this source code. 10 10 */ 11 class Twig_Node_Expression_Function extends Twig_Node_Expression 11 class Twig_Node_Expression_Function extends Twig_Node_Expression_Call 12 12 { 13 13 public function __construct($name, Twig_NodeInterface $arguments, $lineno) … … 19 19 { 20 20 $name = $this->getAttribute('name'); 21 $function = $compiler->getEnvironment()->getFunction($name); 21 22 22 if (false === $function = $compiler->getEnvironment()->getFunction($name)) { 23 $message = sprintf('The function "%s" does not exist', $name); 24 if ($alternatives = $compiler->getEnvironment()->computeAlternatives($name, array_keys($compiler->getEnvironment()->getFunctions()))) { 25 $message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives)); 26 } 27 28 throw new Twig_Error_Syntax($message, $this->getLine(), $compiler->getFilename()); 23 $this->setAttribute('name', $name); 24 $this->setAttribute('type', 'function'); 25 $this->setAttribute('thing', $function); 26 $this->setAttribute('needs_environment', $function->needsEnvironment()); 27 $this->setAttribute('needs_context', $function->needsContext()); 28 $this->setAttribute('arguments', $function->getArguments()); 29 if ($function instanceof Twig_FunctionCallableInterface || $function instanceof Twig_SimpleFunction) { 30 $this->setAttribute('callable', $function->getCallable()); 29 31 } 30 32 31 $compiler->raw($function->compile().'('); 32 33 $first = true; 34 35 if ($function->needsEnvironment()) { 36 $compiler->raw('$this->env'); 37 $first = false; 38 } 39 40 if ($function->needsContext()) { 41 if (!$first) { 42 $compiler->raw(', '); 43 } 44 $compiler->raw('$context'); 45 $first = false; 46 } 47 48 foreach ($function->getArguments() as $argument) { 49 if (!$first) { 50 $compiler->raw(', '); 51 } 52 $compiler->string($argument); 53 $first = false; 54 } 55 56 foreach ($this->getNode('arguments') as $node) { 57 if (!$first) { 58 $compiler->raw(', '); 59 } 60 $compiler->subcompile($node); 61 $first = false; 62 } 63 64 $compiler->raw(')'); 33 $this->compileCallable($compiler); 65 34 } 66 35 }
Note: See TracChangeset
for help on using the changeset viewer.