From: Fabien Potencier Date: Tue, 29 Jun 2010 14:28:02 +0000 (+0200) Subject: fixed inheritance X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=478fe2ed181b2ce137c688c2f40acff60d4a4f06;p=web%2Fkonrad%2Ftwig.git fixed inheritance --- diff --git a/CHANGELOG b/CHANGELOG index b91e3d7..8410b1b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ Backward incompatibilities: * the self special variable has been renamed to _self + * fixed inheritance * added the special _context variable to reference the current context * renamed self to _self (to avoid conflict) * fixed Twig_Template::getAttribute() for protected properties diff --git a/lib/Twig/Node/Module.php b/lib/Twig/Node/Module.php index 2f4f97d..7ffa28c 100644 --- a/lib/Twig/Node/Module.php +++ b/lib/Twig/Node/Module.php @@ -72,7 +72,7 @@ class Twig_Node_Module extends Twig_Node if ($this->parent instanceof Twig_Node_Expression_Constant) { $compiler - ->write("\$this->parent = \$this->env->loadTemplate(") + ->write("\$this->parent = clone \$this->env->loadTemplate(") ->subcompile($this->parent) ->raw(");\n") ; @@ -84,7 +84,7 @@ class Twig_Node_Module extends Twig_Node ->write("if (!\$this->parent") ->raw(" instanceof Twig_Template) {\n") ->indent() - ->write("\$this->parent = \$this->env->loadTemplate(\$this->parent);\n") + ->write("\$this->parent = clone \$this->env->loadTemplate(\$this->parent);\n") ->outdent() ->write("}\n") ; diff --git a/test/Twig/Tests/Fixtures/tags/inheritance/parent_isolation.test b/test/Twig/Tests/Fixtures/tags/inheritance/parent_isolation.test new file mode 100644 index 0000000..4cfa895 --- /dev/null +++ b/test/Twig/Tests/Fixtures/tags/inheritance/parent_isolation.test @@ -0,0 +1,16 @@ +--TEST-- +"extends" tag +--TEMPLATE-- +{% extends "base.twig" %} +{% block content %}{% include "included.twig" %}{% endblock %} +{% block footer %}Footer{% endblock %} +--TEMPLATE(included.twig)-- +{% extends "base.twig" %} +{% block content %}{% endblock %} +--TEMPLATE(base.twig)-- +{% block content %}{% endblock %} +{% block footer %}{% endblock %} +--DATA-- +return array() +--EXPECT-- +Footer diff --git a/test/Twig/Tests/Node/ModuleTest.php b/test/Twig/Tests/Node/ModuleTest.php index 261c05b..be6d8d8 100644 --- a/test/Twig/Tests/Node/ModuleTest.php +++ b/test/Twig/Tests/Node/ModuleTest.php @@ -94,7 +94,7 @@ class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template { \$context['macro'] = \$this->env->loadTemplate("foo.twig", true); if (null === \$this->parent) { - \$this->parent = \$this->env->loadTemplate("layout.twig"); + \$this->parent = clone \$this->env->loadTemplate("layout.twig"); \$this->parent->pushBlocks(\$this->blocks); } \$this->parent->display(\$context); @@ -126,7 +126,7 @@ class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template if (null === \$this->parent) { \$this->parent = (true) ? ("foo") : ("foo"); if (!\$this->parent instanceof Twig_Template) { - \$this->parent = \$this->env->loadTemplate(\$this->parent); + \$this->parent = clone \$this->env->loadTemplate(\$this->parent); } \$this->parent->pushBlocks(\$this->blocks); } diff --git a/test/Twig/Tests/Node/SandboxedModuleTest.php b/test/Twig/Tests/Node/SandboxedModuleTest.php index 2769aa9..e823741 100644 --- a/test/Twig/Tests/Node/SandboxedModuleTest.php +++ b/test/Twig/Tests/Node/SandboxedModuleTest.php @@ -102,7 +102,7 @@ class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template public function display(array \$context) { if (null === \$this->parent) { - \$this->parent = \$this->env->loadTemplate("layout.twig"); + \$this->parent = clone \$this->env->loadTemplate("layout.twig"); \$this->parent->pushBlocks(\$this->blocks); } \$this->parent->display(\$context);