Add #[YieldReady] to allow extensions to tell when they're ready for yielding

This commit is contained in:
Nicolas Grekas
2024-02-06 11:31:19 +01:00
parent 7f5958c5e3
commit e70777405d
59 changed files with 654 additions and 760 deletions
+6 -11
View File
@@ -12,6 +12,7 @@
namespace Twig\Node;
use Twig\Attribute\YieldReady;
use Twig\Compiler;
/**
@@ -19,6 +20,7 @@ use Twig\Compiler;
*
* @author Fabien Potencier <fabien@symfony.com>
*/
#[YieldReady]
class BlockReferenceNode extends Node implements NodeOutputInterface
{
public function __construct(string $name, int $lineno, ?string $tag = null)
@@ -28,16 +30,9 @@ class BlockReferenceNode extends Node implements NodeOutputInterface
public function compile(Compiler $compiler): void
{
if ($compiler->getEnvironment()->useYield()) {
$compiler
->addDebugInfo($this)
->write(sprintf("yield from \$this->unwrap()->yieldBlock('%s', \$context, \$blocks);\n", $this->getAttribute('name')))
;
} else {
$compiler
->addDebugInfo($this)
->write(sprintf("\$this->displayBlock('%s', \$context, \$blocks);\n", $this->getAttribute('name')))
;
}
$compiler
->addDebugInfo($this)
->write(sprintf("yield from \$this->unwrap()->yieldBlock('%s', \$context, \$blocks);\n", $this->getAttribute('name')))
;
}
}