From: Fabien Potencier Date: Wed, 25 Apr 2012 07:17:16 +0000 (+0200) Subject: ensured that each template (Twig_Node_Module) is only visited once X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=feaaca216cb41cfe764c5f9e64802443a7df22ab;p=web%2Fkonrad%2Ftwig.git ensured that each template (Twig_Node_Module) is only visited once --- diff --git a/lib/Twig/Node/Module.php b/lib/Twig/Node/Module.php index 8a5b002..2b8ae2f 100644 --- a/lib/Twig/Node/Module.php +++ b/lib/Twig/Node/Module.php @@ -20,7 +20,8 @@ class Twig_Node_Module extends Twig_Node { public function __construct(Twig_NodeInterface $body, Twig_Node_Expression $parent = null, Twig_NodeInterface $blocks, Twig_NodeInterface $macros, Twig_NodeInterface $traits, Twig_NodeInterface $embeddedTemplates, $filename) { - parent::__construct(array('parent' => $parent, 'body' => $body, 'blocks' => $blocks, 'macros' => $macros, 'traits' => $traits, 'embedded_templates' => $embeddedTemplates), array('filename' => $filename, 'index' => null), 1); + // embedded templates are set as attributes so that they are only visited once by the visitors + parent::__construct(array('parent' => $parent, 'body' => $body, 'blocks' => $blocks, 'macros' => $macros, 'traits' => $traits), array('filename' => $filename, 'index' => null, 'embedded_templates' => $embeddedTemplates), 1); } public function setIndex($index) @@ -37,7 +38,7 @@ class Twig_Node_Module extends Twig_Node { $this->compileTemplate($compiler); - foreach ($this->getNode('embedded_templates') as $template) { + foreach ($this->getAttribute('embedded_templates') as $template) { $compiler->subcompile($template); } } diff --git a/lib/Twig/Node/SandboxedModule.php b/lib/Twig/Node/SandboxedModule.php index 464819a..6dd63e5 100644 --- a/lib/Twig/Node/SandboxedModule.php +++ b/lib/Twig/Node/SandboxedModule.php @@ -24,7 +24,7 @@ class Twig_Node_SandboxedModule extends Twig_Node_Module public function __construct(Twig_Node_Module $node, array $usedFilters, array $usedTags, array $usedFunctions) { - parent::__construct($node->getNode('body'), $node->getNode('parent'), $node->getNode('blocks'), $node->getNode('macros'), $node->getNode('traits'), $node->getNode('embedded_templates'), $node->getAttribute('filename'), $node->getLine(), $node->getNodeTag()); + parent::__construct($node->getNode('body'), $node->getNode('parent'), $node->getNode('blocks'), $node->getNode('macros'), $node->getNode('traits'), $node->getAttribute('embedded_templates'), $node->getAttribute('filename'), $node->getLine(), $node->getNodeTag()); $this->setAttribute('index', $node->getAttribute('index'));