mirror of
https://github.com/twigphp/Twig.git
synced 2026-10-11 06:15:43 +00:00
Add #[YieldReady] to allow extensions to tell when they're ready for yielding
This commit is contained in:
@@ -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')))
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user