added an error message when trying to import an undefined block from a trait

This commit is contained in:
Fabien Potencier
2013-12-06 11:06:49 +01:00
parent 7066ce68ad
commit a2c6db7ea7
3 changed files with 22 additions and 1 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
* 1.15.1 (2013-XX-XX) * 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) * 1.15.0 (2013-12-06)
+12
View File
@@ -170,6 +170,18 @@ class Twig_Node_Module extends Twig_Node
foreach ($trait->getNode('targets') as $key => $value) { foreach ($trait->getNode('targets') as $key => $value) {
$compiler $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)) ->write(sprintf("\$_trait_%s_blocks[", $i))
->subcompile($value) ->subcompile($value)
->raw(sprintf("] = \$_trait_%s_blocks[", $i)) ->raw(sprintf("] = \$_trait_%s_blocks[", $i))
@@ -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".