From 99e9d1cf4131790ef6b2676ea37999997e601d90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Proch=C3=A1zka?= Date: Fri, 13 May 2016 12:08:51 +0200 Subject: [PATCH 1/4] handle Throwable --- lib/Twig/Environment.php | 4 ++++ lib/Twig/Node/Macro.php | 5 +++++ lib/Twig/Template.php | 6 ++++++ test/Twig/Tests/Node/MacroTest.php | 4 ++++ 4 files changed, 19 insertions(+) diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php index 48eaad397..0b3c167c1 100644 --- a/lib/Twig/Environment.php +++ b/lib/Twig/Environment.php @@ -438,6 +438,10 @@ class Twig_Environment } catch (Exception $e) { $this->setLoader($current); + throw $e; + } catch (Throwable $e) { + $this->setLoader($current); + throw $e; } $this->setLoader($current); diff --git a/lib/Twig/Node/Macro.php b/lib/Twig/Node/Macro.php index 932e795f0..c186cd0b9 100644 --- a/lib/Twig/Node/Macro.php +++ b/lib/Twig/Node/Macro.php @@ -109,6 +109,11 @@ class Twig_Node_Macro extends Twig_Node ->write("ob_end_clean();\n\n") ->write("throw \$e;\n") ->outdent() + ->write("} catch (Throwable \$e) {\n") + ->indent() + ->write("ob_end_clean();\n\n") + ->write("throw \$e;\n") + ->outdent() ->write("}\n\n") ->write("return ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());\n") ->outdent() diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index f0ce0fda1..7f7f62a52 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -369,6 +369,12 @@ abstract class Twig_Template implements Twig_TemplateInterface ob_end_clean(); } + throw $e; + } catch (Throwable $e) { + while (ob_get_level() > $level) { + ob_end_clean(); + } + throw $e; } diff --git a/test/Twig/Tests/Node/MacroTest.php b/test/Twig/Tests/Node/MacroTest.php index 901e57b91..c7edfa251 100644 --- a/test/Twig/Tests/Node/MacroTest.php +++ b/test/Twig/Tests/Node/MacroTest.php @@ -58,6 +58,10 @@ public function getfoo(\$__foo__ = null, \$__bar__ = "Foo"$declaration) } catch (Exception \$e) { ob_end_clean(); + throw \$e; + } catch (Throwable \$e) { + ob_end_clean(); + throw \$e; } From 1a1ba8bba4f1f3ea433aedc3e8d1e360b34351ed Mon Sep 17 00:00:00 2001 From: JakeFr Date: Fri, 13 May 2016 18:05:38 +0200 Subject: [PATCH 2/4] [DOC] recipes.rst uses Twig_Function_Function Hello, Here's a minor update for recipes.rst I rewrite the code sample for registerUndefinedFunctionCallback to remove usage of deprecated class Twig_Function_Function. --- doc/recipes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/recipes.rst b/doc/recipes.rst index 6627418f1..b035adb8b 100644 --- a/doc/recipes.rst +++ b/doc/recipes.rst @@ -280,7 +280,7 @@ For functions, use ``registerUndefinedFunctionCallback()``:: // don't try this at home as it's not secure at all! $twig->registerUndefinedFunctionCallback(function ($name) { if (function_exists($name)) { - return new Twig_Function_Function($name); + return new Twig_SimpleFunction($name, $name); } return false; From 6dd784a2d5c1d6f22c332f766de3f6e6b9a0091e Mon Sep 17 00:00:00 2001 From: Owen Kieffer-Jones Date: Thu, 28 Apr 2016 16:31:26 +0200 Subject: [PATCH 3/4] Grammar --- doc/tags/extends.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/tags/extends.rst b/doc/tags/extends.rst index 1ad2b12b1..a31df89df 100644 --- a/doc/tags/extends.rst +++ b/doc/tags/extends.rst @@ -131,8 +131,8 @@ to variables from outer scopes: Block Shortcuts --------------- -For blocks with few content, it's possible to use a shortcut syntax. The -following constructs do the same: +For blocks with little content, it's possible to use a shortcut syntax. The +following constructs do the same thing: .. code-block:: jinja From e81e698187a8ba01cb2e2918a471b0ac9936e27e Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 19 May 2016 19:38:54 +0200 Subject: [PATCH 4/4] Small fixes --- doc/intro.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/intro.rst b/doc/intro.rst index 9b38c97d4..352286927 100644 --- a/doc/intro.rst +++ b/doc/intro.rst @@ -19,11 +19,11 @@ The key-features are... may modify the template design. * *Flexible*: Twig is powered by a flexible lexer and parser. This allows the - developer to define its own custom tags and filters, and create its own DSL. + developer to define their own custom tags and filters, and to create their own DSL. Twig is used by many Open-Source projects like Symfony, Drupal8, eZPublish, -phpBB, Piwik, OroCRM, and many frameworks have support for it as well like -Slim, Yii, Laravel, Codeigniter, and Kohana, just to name a few. +phpBB, Piwik, OroCRM; and many frameworks have support for it as well like +Slim, Yii, Laravel, Codeigniter and Kohana — just to name a few. Prerequisites -------------