示例#1
0
 public function testConstructor()
 {
     $node = new Twig_Node_Expression_Name('foo', 1);
     $this->assertEquals('foo', $node->getAttribute('name'));
 }
示例#2
0
 public function getFunctionNode(Twig_Node_Expression_Name $node)
 {
     $args = $this->parseArguments();
     if ('parent' === $node->getAttribute('name')) {
         if (!count($this->parser->getBlockStack())) {
             throw new Twig_Error_Syntax('Calling "parent" outside a block is forbidden', $node->getLine());
         }
         if (!$this->parser->getParent()) {
             throw new Twig_Error_Syntax('Calling "parent" on a template that does not extend another one is forbidden', $node->getLine());
         }
         return new Twig_Node_Expression_Parent($this->parser->peekBlockStack(), $node->getLine());
     }
     if ('block' === $node->getAttribute('name')) {
         return new Twig_Node_Expression_BlockReference($args->getNode(0), false, $node->getLine());
     }
     if (null !== ($alias = $this->parser->getImportedFunction($node->getAttribute('name')))) {
         return new Twig_Node_Expression_GetAttr($alias['node'], new Twig_Node_Expression_Constant($alias['name'], $node->getLine()), $args, Twig_TemplateInterface::METHOD_CALL, $node->getLine());
     }
     return new Twig_Node_Expression_Function($node, $args, $node->getLine());
 }