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->getImportedSymbol($name, 'function')) {
+ if (null !== $alias = $this->parser->getImportedSymbol('function', $name)) {
$arguments = new Twig_Node_Expression_Array(array(), $line);
foreach ($args as $n) {
$arguments->addElement($n);
$stream->expect(Twig_Token::PUNCTUATION_TYPE, ']');
}
- if ($node instanceof Twig_Node_Expression_Name && null !== $alias = $this->parser->getImportedSymbol($node->getAttribute('name'), 'template')) {
+ if ($node instanceof Twig_Node_Expression_Name && null !== $alias = $this->parser->getImportedSymbol('template', $node->getAttribute('name'))) {
$node = new Twig_Node_Expression_MethodCall($node, 'get'.$arg->getAttribute('value'), $arguments, $lineno);
$node->setAttribute('safe', true);
$this->embeddedTemplates[] = $template;
}
- public function addImportedSymbol($alias, $name, Twig_Node_Expression $node = null, $type)
+ public function addImportedSymbol($type, $alias, $name = null, Twig_Node_Expression $node = null)
{
- $this->importedSymbols[0][$alias] = array('name' => $name, 'node' => $node, 'type' => $type);
+ $this->importedSymbols[0][$type][$alias] = array('name' => $name, 'node' => $node);
}
- public function getImportedSymbol($alias, $type)
+ public function getImportedSymbol($type, $alias)
{
foreach ($this->importedSymbols as $functions) {
- if (isset($functions[$alias]) && $type === $functions[$alias]['type']) {
- return $functions[$alias];
+ if (isset($functions[$type][$alias])) {
+ return $functions[$type][$alias];
}
}
}
$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->addImportedSymbol($alias, 'get'.$name, $node->getNode('var'), 'function');
+ $this->parser->addImportedSymbol('function', $alias, 'get'.$name, $node->getNode('var'));
}
return $node;
$var = new Twig_Node_Expression_AssignName($this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue(), $token->getLine());
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
- $this->parser->addImportedSymbol($var->getAttribute('name'), null, null, 'template');
+ $this->parser->addImportedSymbol('template', $var->getAttribute('name'));
return new Twig_Node_Import($macro, $var, $token->getLine(), $this->getTag());
}