From: Fabien Potencier Date: Fri, 6 Dec 2013 10:06:49 +0000 (+0100) Subject: added an error message when trying to import an undefined block from a trait X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=a2c6db7ea7d2c90923e6708019ec1442526d1c30;p=web%2Fkonrad%2Ftwig.git added an error message when trying to import an undefined block from a trait --- diff --git a/CHANGELOG b/CHANGELOG index 51a25a6..6d0a147 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,6 @@ * 1.15.1 (2013-XX-XX) - * n/a + * added an error message when trying to import an undefined block from a trait * 1.15.0 (2013-12-06) diff --git a/lib/Twig/Node/Module.php b/lib/Twig/Node/Module.php index 585048b..3f80175 100644 --- a/lib/Twig/Node/Module.php +++ b/lib/Twig/Node/Module.php @@ -170,6 +170,18 @@ class Twig_Node_Module extends Twig_Node foreach ($trait->getNode('targets') as $key => $value) { $compiler + ->write(sprintf("if (!isset(\$_trait_%s_blocks[", $i)) + ->string($key) + ->raw("])) {\n") + ->indent() + ->write("throw new Twig_Error_Runtime(sprintf('Block ") + ->string($key) + ->raw(" is not defined in trait ") + ->subcompile($trait->getNode('template')) + ->raw(".'));\n") + ->outdent() + ->write("}\n\n") + ->write(sprintf("\$_trait_%s_blocks[", $i)) ->subcompile($value) ->raw(sprintf("] = \$_trait_%s_blocks[", $i)) diff --git a/test/Twig/Tests/Fixtures/exceptions/undefined_trait.test b/test/Twig/Tests/Fixtures/exceptions/undefined_trait.test new file mode 100644 index 0000000..026bd52 --- /dev/null +++ b/test/Twig/Tests/Fixtures/exceptions/undefined_trait.test @@ -0,0 +1,9 @@ +--TEST-- +Exception for an undefined trait +--TEMPLATE-- +{% use 'foo' with foobar as bar %} +--TEMPLATE(foo)-- +{% block bar %} +{% endblock %} +--EXCEPTION-- +Twig_Error_Runtime: Block "foobar" is not defined in trait "foo" in "index.twig".