public function getFunctionNode($name, $line) {
$args = $this
->parseArguments();
switch ($name) {
case 'parent':
if (!count($this->parser
->getBlockStack())) {
throw new Twig_Error_Syntax('Calling "parent" outside a block is forbidden', $line);
}
if (!$this->parser
->getParent() && !$this->parser
->hasTraits()) {
throw new Twig_Error_Syntax('Calling "parent" on a template that does not extend nor "use" another template is forbidden', $line);
}
return new Twig_Node_Expression_Parent($this->parser
->peekBlockStack(), $line);
case 'block':
return new Twig_Node_Expression_BlockReference($args
->getNode(0), false, $line);
case 'attribute':
if (count($args) < 2) {
throw new Twig_Error_Syntax('The "attribute" function takes at least two arguments (the variable and the attributes)', $line);
}
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))) {
$arguments = new Twig_Node_Expression_Array(array(), $line);
foreach ($args as $n) {
$arguments
->addElement($n);
}
$node = new Twig_Node_Expression_MethodCall($alias['node'], $alias['name'], $arguments, $line);
$node
->setAttribute('safe', true);
return $node;
}
$class = $this
->getFunctionNodeClass($name);
return new $class($name, $args, $line);
}
}