* 1.6.0-DEV
+ * made a speed optimization to macro calls when imported via the "from" tag
* fixed globals, parsers, visitors, filters, tests, and functions management in Twig_Environment when a new one or new extension is added
* fixed the attribute function when passing arguments
* added slice notation support for the [] operator (syntactic sugar for the slice operator)
$arguments->addElement($n);
}
- return new Twig_Node_Expression_GetAttr($alias['node'], new Twig_Node_Expression_Constant($alias['name'], $line), $arguments, Twig_TemplateInterface::METHOD_CALL, $line);
+ $node = new Twig_Node_Expression_MethodCall($alias['node'], $alias['name'], $arguments, $line);
+ $node->setAttribute('safe', true);
+
+ return $node;
}
$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_Node_Expression_Array $arguments, $lineno)
+ {
+ parent::__construct(array('node' => $node, 'arguments' => $arguments), array('method' => $method, 'safe' => false), $lineno);
+ }
+
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->subcompile($this->getNode('node'))
+ ->raw('->')
+ ->raw($this->getAttribute('method'))
+ ->raw('(')
+ ;
+ $first = true;
+ foreach ($this->getNode('arguments')->getKeyValuePairs() as $pair) {
+ if (!$first) {
+ $compiler->raw(', ');
+ }
+ $first = false;
+
+ $compiler->subcompile($pair['value']);
+ }
+ $compiler->raw(')');
+ }
+}
} else {
$this->setSafe($node, array());
}
+ } elseif ($node instanceof Twig_Node_Expression_MethodCall) {
+ if ($node->getAttribute('safe')) {
+ $this->setSafe($node, array('all'));
+ } else {
+ $this->setSafe($node, array());
+ }
} else {
$this->setSafe($node, array());
}
$ret = call_user_func_array(array($object, $method), $arguments);
+ // hack to be removed when macro calls are refactored
if ($object instanceof Twig_TemplateInterface) {
return new Twig_Markup($ret, $this->env->getCharset());
}
$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;