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")
->indent()
->subcompile($this->getNode('body'))
->raw("\n")
->write("return ('' === \$tmp = ob_get_contents()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());\n")
->outdent()
->write("} catch (Exception \$e) {\n")
->write("} finally {\n")
->indent()
->write("ob_end_clean();\n\n")
->write("throw \$e;\n")
->write("ob_end_clean();\n")
->outdent()
->write("}\n\n")
->write("return ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());\n")
->write("}\n")
->outdent()
->write("}\n\n")
;
+3 -5
View File
@@ -55,13 +55,11 @@ public function macro_foo(\$__foo__ = null, \$__bar__ = "Foo"$declaration)
ob_start();
try {
echo "foo";
} catch (Exception \$e) {
return ('' === \$tmp = ob_get_contents()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());
} finally {
ob_end_clean();
throw \$e;
}
return ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());
}
EOF
),