From b5d62a192e53a3b6622f3e9bc2a57bbf6bc91d3a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 21 Jul 2012 22:47:06 +0200 Subject: [PATCH] moved some macro related logic to the generated code --- lib/Twig/Node/Macro.php | 2 +- lib/Twig/Template.php | 9 +-------- test/Twig/Tests/Node/MacroTest.php | 2 +- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/Twig/Node/Macro.php b/lib/Twig/Node/Macro.php index e0c3dca..823131e 100644 --- a/lib/Twig/Node/Macro.php +++ b/lib/Twig/Node/Macro.php @@ -76,7 +76,7 @@ class Twig_Node_Macro extends Twig_Node ->write("throw \$e;\n") ->outdent() ->write("}\n\n") - ->write("return ob_get_clean();\n") + ->write("return ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());\n") ->outdent() ->write("}\n\n") ; diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index 7b98468..beed5c5 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -422,14 +422,7 @@ abstract class Twig_Template implements Twig_TemplateInterface $this->env->getExtension('sandbox')->checkMethodAllowed($object, $method); } - $ret = call_user_func_array(array($object, $method), $arguments); - - // hack to be removed when macro calls are refactored - if ($object instanceof Twig_TemplateInterface) { - return $ret === '' ? '' : new Twig_Markup($ret, $this->env->getCharset()); - } - - return $ret; + return call_user_func_array(array($object, $method), $arguments); } /** diff --git a/test/Twig/Tests/Node/MacroTest.php b/test/Twig/Tests/Node/MacroTest.php index 3dd57a6..5930728 100644 --- a/test/Twig/Tests/Node/MacroTest.php +++ b/test/Twig/Tests/Node/MacroTest.php @@ -61,7 +61,7 @@ public function getfoo(\$foo = null) throw \$e; } - return ob_get_clean(); + return ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset()); } EOF ), -- 1.7.2.5