public function getSourceContext($name) { if ($this->loader instanceof \Twig_SourceContextLoaderInterface) { $source = $this->loader->getSourceContext($name); } else { if ($this->loader instanceof \Twig_ExistsLoaderInterface && !$this->loader->exists($name)) { throw new \Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name)); } $source = new \Twig_Source($this->loader->getSource($name), $name); } return new \Twig_Source($this->parser->parse($source->getCode(), ['filename' => $name]), $source->getName(), $source->getPath()); }
public function testConstructor() { $body = new Twig_Node_Text('foo', 1); $parent = new Twig_Node_Expression_Constant('layout.twig', 1); $blocks = new Twig_Node(); $macros = new Twig_Node(); $traits = new Twig_Node(); $source = new Twig_Source('{{ foo }}', 'foo.twig'); $node = new Twig_Node_Module($body, $parent, $blocks, $macros, $traits, new Twig_Node(array()), $source); $this->assertEquals($body, $node->getNode('body')); $this->assertEquals($blocks, $node->getNode('blocks')); $this->assertEquals($macros, $node->getNode('macros')); $this->assertEquals($parent, $node->getNode('parent')); $this->assertEquals($source->getName(), $node->getTemplateName()); }