Fix blocks not available under some circumstancies

This commit is contained in:
Fabien Potencier
2024-05-11 08:44:27 +02:00
parent 00c43a9c38
commit d30b72c364
4 changed files with 4 additions and 10 deletions
+1 -1
View File
@@ -40,7 +40,7 @@ class CacheNode extends AbstractExpression
->addDebugInfo($this)
->raw('$this->env->getRuntime(\'Twig\Extra\Cache\CacheRuntime\')->getCache()->get(')
->subcompile($this->getNode('key'))
->raw(", function (\Symfony\Contracts\Cache\ItemInterface \$item) use (\$context, \$macros) {\n")
->raw(", function (\Symfony\Contracts\Cache\ItemInterface \$item) use (\$context, \$macros, \$blocks) {\n")
->indent()
;
+3 -7
View File
@@ -24,7 +24,7 @@ class CaptureNode extends Node
{
public function __construct(Node $body, int $lineno, ?string $tag = null)
{
parent::__construct(['body' => $body], ['raw' => false, 'with_blocks' => false], $lineno, $tag);
parent::__construct(['body' => $body], ['raw' => false], $lineno, $tag);
}
public function compile(Compiler $compiler): void
@@ -34,13 +34,9 @@ class CaptureNode extends Node
if (!$this->getAttribute('raw')) {
$compiler->raw("('' === \$tmp = ");
}
$compiler->raw($useYield ? "implode('', iterator_to_array(" : '\\Twig\\Extension\\CoreExtension::captureOutput(');
if ($this->getAttribute('with_blocks')) {
$compiler->raw("(function () use (&\$context, \$macros, \$blocks) {\n");
} else {
$compiler->raw("(function () use (&\$context, \$macros) {\n");
}
$compiler
->raw($useYield ? "implode('', iterator_to_array(" : '\\Twig\\Extension\\CoreExtension::captureOutput(')
->raw("(function () use (&\$context, \$macros, \$blocks) {\n")
->indent()
->subcompile($this->getNode('body'))
->write("return; yield '';\n")
-1
View File
@@ -80,7 +80,6 @@ class MacroNode extends Node
}
$node = new CaptureNode($this->getNode('body'), $this->getNode('body')->lineno, $this->getNode('body')->tag);
$node->setAttribute('with_blocks', true);
$compiler
->write('')
-1
View File
@@ -38,7 +38,6 @@ class SetNode extends Node implements NodeCaptureInterface
$capture = false;
} else {
$values = new CaptureNode($values, $values->getTemplateLine());
$values->setAttribute('with_blocks', true);
}
}