fixed using a Twig_TemplateWrapper instance as an argument to extends

This commit is contained in:
Fabien Potencier
2019-01-12 11:26:03 +01:00
parent 15912f8f6b
commit 547fc6120e
4 changed files with 23 additions and 10 deletions
+1
View File
@@ -1,5 +1,6 @@
* 1.37.0 (2019-XX-XX)
* fixed using a Twig_TemplateWrapper instance as an argument to extends
* switched generated code to use the PHP short array notation
* dropped PHP 5.3 support
* fixed float representation in compiled templates
+4 -8
View File
@@ -108,7 +108,7 @@ abstract class Twig_Template implements Twig_TemplateInterface
*
* @param array $context
*
* @return Twig_TemplateInterface|false The parent template or false if there is no parent
* @return Twig_TemplateInterface|Twig_TemplateWrapper|false The parent template or false if there is no parent
*
* @internal
*/
@@ -125,8 +125,8 @@ abstract class Twig_Template implements Twig_TemplateInterface
return false;
}
if ($parent instanceof self) {
return $this->parents[$parent->getTemplateName()] = $parent;
if ($parent instanceof self || $parent instanceof Twig_TemplateWrapper) {
return $this->parents[$parent->getSourceContext()->getName()] = $parent;
}
if (!isset($this->parents[$parent])) {
@@ -355,11 +355,7 @@ abstract class Twig_Template implements Twig_TemplateInterface
return $this->env->resolveTemplate($template);
}
if ($template instanceof self) {
return $template;
}
if ($template instanceof Twig_TemplateWrapper) {
if ($template instanceof self || $template instanceof Twig_TemplateWrapper) {
return $template;
}
+6 -2
View File
@@ -40,7 +40,9 @@ final class Twig_TemplateWrapper
*/
public function render($context = [])
{
return $this->template->render($context);
// using func_get_args() allows to not expose the blocks argument
// as it should only be used by internal code
return $this->template->render($context, func_num_args() >= 1 ? func_get_arg(1) : []);
}
/**
@@ -50,7 +52,9 @@ final class Twig_TemplateWrapper
*/
public function display($context = [])
{
$this->template->display($context);
// using func_get_args() allows to not expose the blocks argument
// as it should only be used by internal code
$this->template->display($context, func_num_args() >= 1 ? func_get_arg(1) : []);
}
/**
@@ -0,0 +1,12 @@
--TEST--
"extends" tag with a parent as a Twig_TemplateWrapper instance
--TEMPLATE--
{% extends foo %}
{% block content %}New{% endblock %}
--TEMPLATE(foo.twig)--
{% block content %}Default{% endblock %}
--DATA--
return ['foo' => $twig->load('foo.twig')]
--EXPECT--
New