Esempio n. 1
0
 public function testConstructor()
 {
     $expr = new Twig_Node_Expression_Constant('foo.twig', 1);
     $node = new Twig_Node_Include($expr, null, false, false, 1);
     $this->assertNull($node->getNode('variables'));
     $this->assertEquals($expr, $node->getNode('expr'));
     $this->assertFalse($node->getAttribute('only'));
     $vars = new Twig_Node_Expression_Array(array(new Twig_Node_Expression_Constant('foo', 1), new Twig_Node_Expression_Constant(true, 1)), 1);
     $node = new Twig_Node_Include($expr, $vars, true, false, 1);
     $this->assertEquals($vars, $node->getNode('variables'));
     $this->assertTrue($node->getAttribute('only'));
 }
Esempio n. 2
0
 /**
  * Compiles the node to PHP.
  *
  * @param \Twig_Compiler A Twig_Compiler instance
  */
 public function compile(\Twig_Compiler $compiler)
 {
     $compiler->addDebugInfo($this);
     $compiler->write("\$location = ")->subcompile($this->getNode('expr'))->raw(";\n")->write("\$namespace = false;\n")->write("if (strpos(\$location, '@') === 0) {\n")->indent()->write("\$namespace = substr(\$location, 1, strpos(\$location, '/') - 1);\n")->write("\$previous_look_up_order = \$this->env->getNamespaceLookUpOrder();\n")->write("\$this->env->setNamespaceLookUpOrder(array(\$namespace, '__main__'));\n")->outdent()->write("}\n");
     parent::compile($compiler);
     $compiler->write("if (\$namespace) {\n")->indent()->write("\$this->env->setNamespaceLookUpOrder(\$previous_look_up_order);\n")->outdent()->write("}\n");
 }
Esempio n. 3
0
 public function __construct($name, $index, Twig_Node_Expression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null)
 {
     parent::__construct(new Twig_Node_Expression_Constant('not_used', $lineno), $variables, $only, $ignoreMissing, $lineno, $tag);
     $this->setAttribute('name', $name);
     // to be removed in 2.0, used name instead
     $this->setAttribute('filename', $name);
     $this->setAttribute('index', $index);
 }
 public function __construct(\Twig_Node_Include $originalNode, $data)
 {
     parent::__construct($originalNode->getNode('expr'), $originalNode->getNode('variables'), $originalNode->getAttribute('only'), $originalNode->getAttribute('ignore_missing'), $originalNode->getLine(), $originalNode->getNodeTag());
     $this->setData($data);
 }