* 1.6.0-DEV
+ * made a speed optimization to macro calls when imported via the "from" tag
* added slice notation support for the [] operator (syntactic sugar for the slice operator)
* added a slice filter
* added string support for the reverse filter
return new Twig_Node_Expression_GetAttr($args->getNode(0), $args->getNode(1), count($args) > 2 ? $args->getNode(2) : new Twig_Node_Expression_Array(array(), $line), Twig_TemplateInterface::ANY_CALL, $line);
default:
if (null !== $alias = $this->parser->getImportedFunction($name)) {
- return new Twig_Node_Expression_GetAttr($alias['node'], new Twig_Node_Expression_Constant($alias['name'], $line), $args, Twig_TemplateInterface::METHOD_CALL, $line);
+ return new Twig_Node_Expression_MethodCall($alias['node'], $alias['name'], $args, $line);
}
$class = $this->getFunctionNodeClass($name);
--- /dev/null
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) 2012 Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+class Twig_Node_Expression_MethodCall extends Twig_Node_Expression
+{
+ public function __construct(Twig_Node_Expression $node, $method, Twig_NodeInterface $arguments, $lineno)
+ {
+ parent::__construct(array('node' => $node, 'arguments' => $arguments), array('method' => $method), $lineno);
+ }
+
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->subcompile($this->getNode('node'))
+ ->raw('->')
+ ->raw($this->getAttribute('method'))
+ ->raw('(')
+ ;
+ $nodes = $this->getNode('arguments');
+ for ($i = 0, $max = count($nodes); $i < $max; $i++) {
+ $compiler->subcompile($nodes->getNode($i));
+
+ if ($i < $max - 1) {
+ $compiler->raw(', ');
+ }
+ }
+ $compiler->raw(')');
+ }
+}
$node = new Twig_Node_Import($macro, new Twig_Node_Expression_AssignName($this->parser->getVarName(), $token->getLine()), $token->getLine(), $this->getTag());
foreach($targets as $name => $alias) {
- $this->parser->addImportedFunction($alias, $name, $node->getNode('var'));
+ $this->parser->addImportedFunction($alias, 'get'.$name, $node->getNode('var'));
}
return $node;