summaryrefslogtreecommitdiff
path: root/inc/lib/Twig/Node/Expression/Function.php
diff options
context:
space:
mode:
authorMichael Foster <savetheinternet@tinyboard.org>2013-08-01 15:20:12 -0400
committerMichael Foster <savetheinternet@tinyboard.org>2013-08-01 15:20:12 -0400
commit0fe552857468aa12097a74e08f51f5aaa983be07 (patch)
tree22dbca1be90d7086b20a077752552296abf23325 /inc/lib/Twig/Node/Expression/Function.php
parent22f3a95e0e421de05a11633eac846df96a2a4768 (diff)
Upgrade Twig library
Diffstat (limited to 'inc/lib/Twig/Node/Expression/Function.php')
-rw-r--r--inc/lib/Twig/Node/Expression/Function.php38
1 files changed, 12 insertions, 26 deletions
diff --git a/inc/lib/Twig/Node/Expression/Function.php b/inc/lib/Twig/Node/Expression/Function.php
index 3f457199..3e1f6b55 100644
--- a/inc/lib/Twig/Node/Expression/Function.php
+++ b/inc/lib/Twig/Node/Expression/Function.php
@@ -8,7 +8,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-class Twig_Node_Expression_Function extends Twig_Node_Expression
+class Twig_Node_Expression_Function extends Twig_Node_Expression_Call
{
public function __construct($name, Twig_NodeInterface $arguments, $lineno)
{
@@ -17,33 +17,19 @@ class Twig_Node_Expression_Function extends Twig_Node_Expression
public function compile(Twig_Compiler $compiler)
{
- $function = $compiler->getEnvironment()->getFunction($this->getAttribute('name'));
- if (false === $function) {
- throw new Twig_Error_Syntax(sprintf('The function "%s" does not exist', $this->getAttribute('name')), $this->getLine());
- }
-
- $compiler
- ->raw($function->compile().'(')
- ->raw($function->needsEnvironment() ? '$this->env' : '')
- ;
-
- if ($function->needsContext()) {
- $compiler->raw($function->needsEnvironment() ? ', $context' : '$context');
- }
+ $name = $this->getAttribute('name');
+ $function = $compiler->getEnvironment()->getFunction($name);
- $first = true;
- foreach ($this->getNode('arguments') as $node) {
- if (!$first) {
- $compiler->raw(', ');
- } else {
- if ($function->needsEnvironment() || $function->needsContext()) {
- $compiler->raw(', ');
- }
- $first = false;
- }
- $compiler->subcompile($node);
+ $this->setAttribute('name', $name);
+ $this->setAttribute('type', 'function');
+ $this->setAttribute('thing', $function);
+ $this->setAttribute('needs_environment', $function->needsEnvironment());
+ $this->setAttribute('needs_context', $function->needsContext());
+ $this->setAttribute('arguments', $function->getArguments());
+ if ($function instanceof Twig_FunctionCallableInterface || $function instanceof Twig_SimpleFunction) {
+ $this->setAttribute('callable', $function->getCallable());
}
- $compiler->raw(')');
+ $this->compileCallable($compiler);
}
}