From: Fabien Potencier Date: Thu, 8 Dec 2011 18:14:07 +0000 (+0100) Subject: moved some common compiled code to Twig_Template X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=3689745d35874fd05fde4251cca7868a7efadbf8;p=konrad%2Ftwig.git moved some common compiled code to Twig_Template --- diff --git a/lib/Twig/Node/Module.php b/lib/Twig/Node/Module.php index 7321e06..349ba68 100644 --- a/lib/Twig/Node/Module.php +++ b/lib/Twig/Node/Module.php @@ -62,24 +62,24 @@ class Twig_Node_Module extends Twig_Node protected function compileGetParent(Twig_Compiler $compiler) { + if (null === $this->getNode('parent')) { + return; + } + $compiler ->write("protected function doGetParent(array \$context)\n", "{\n") ->indent() ->write("return ") ; - if (null === $this->getNode('parent')) { - $compiler->raw("false"); + if ($this->getNode('parent') instanceof Twig_Node_Expression_Constant) { + $compiler->subcompile($this->getNode('parent')); } else { - if ($this->getNode('parent') instanceof Twig_Node_Expression_Constant) { - $compiler->subcompile($this->getNode('parent')); - } else { - $compiler - ->raw("\$this->env->resolveTemplate(") - ->subcompile($this->getNode('parent')) - ->raw(")") - ; - } + $compiler + ->raw("\$this->env->resolveTemplate(") + ->subcompile($this->getNode('parent')) + ->raw(")") + ; } $compiler @@ -285,6 +285,10 @@ class Twig_Node_Module extends Twig_Node } } + if ($traitable) { + return; + } + $compiler ->write("public function isTraitable()\n", "{\n") ->indent() diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index c4dfedf..9386196 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -76,7 +76,15 @@ abstract class Twig_Template implements Twig_TemplateInterface return $this->parents[$parent]; } - abstract protected function doGetParent(array $context); + protected function doGetParent(array $context) + { + return false; + } + + public function isTraitable() + { + return true; + } /** * Displays a parent block. diff --git a/test/Twig/Tests/Node/ModuleTest.php b/test/Twig/Tests/Node/ModuleTest.php index da7f942..9ad3b26 100644 --- a/test/Twig/Tests/Node/ModuleTest.php +++ b/test/Twig/Tests/Node/ModuleTest.php @@ -69,11 +69,6 @@ class Twig_Tests_Node_ModuleTest extends Twig_Tests_Node_TestCase /* foo.twig */ class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template { - protected function doGetParent(array \$context) - { - return false; - } - protected function doDisplay(array \$context, array \$blocks = array()) { echo "foo"; @@ -84,10 +79,6 @@ class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template return "foo.twig"; } - public function isTraitable() - { - return true; - } } EOF , $twig); diff --git a/test/Twig/Tests/Node/SandboxedModuleTest.php b/test/Twig/Tests/Node/SandboxedModuleTest.php index eb76cf2..a24857b 100644 --- a/test/Twig/Tests/Node/SandboxedModuleTest.php +++ b/test/Twig/Tests/Node/SandboxedModuleTest.php @@ -67,11 +67,6 @@ class Twig_Tests_Node_SandboxedModuleTest extends Twig_Tests_Node_TestCase /* foo.twig */ class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template { - protected function doGetParent(array \$context) - { - return false; - } - protected function doDisplay(array \$context, array \$blocks = array()) { \$this->checkSecurity(); @@ -91,10 +86,6 @@ class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template return "foo.twig"; } - public function isTraitable() - { - return true; - } } EOF , $twig);