use try-finally for macro compilation

This commit is contained in:
Tobias Schultze
2015-09-24 16:26:19 +02:00
parent eea6849837
commit 53d01ffed7
2 changed files with 8 additions and 10 deletions
+5 -5
View File
@@ -108,14 +108,14 @@ class Twig_Node_Macro extends Twig_Node
->write("try {\n") ->write("try {\n")
->indent() ->indent()
->subcompile($this->getNode('body')) ->subcompile($this->getNode('body'))
->raw("\n")
->write("return ('' === \$tmp = ob_get_contents()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());\n")
->outdent() ->outdent()
->write("} catch (Exception \$e) {\n") ->write("} finally {\n")
->indent() ->indent()
->write("ob_end_clean();\n\n") ->write("ob_end_clean();\n")
->write("throw \$e;\n")
->outdent() ->outdent()
->write("}\n\n") ->write("}\n")
->write("return ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());\n")
->outdent() ->outdent()
->write("}\n\n") ->write("}\n\n")
; ;
+3 -5
View File
@@ -55,13 +55,11 @@ public function macro_foo(\$__foo__ = null, \$__bar__ = "Foo"$declaration)
ob_start(); ob_start();
try { try {
echo "foo"; echo "foo";
} catch (Exception \$e) {
return ('' === \$tmp = ob_get_contents()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());
} finally {
ob_end_clean(); ob_end_clean();
throw \$e;
} }
return ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());
} }
EOF EOF
), ),