leilukin-tumbleblog/includes/lib/Twig/Node/PrintNode.php

45 lines
1.0 KiB
PHP
Raw Normal View History

2024-06-20 14:10:42 +00:00
<?php
/*
* This file is part of Twig.
*
* (c) Fabien Potencier
* (c) Armin Ronacher
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Twig\Node;
use Twig\Attribute\YieldReady;
use Twig\Compiler;
use Twig\Node\Expression\AbstractExpression;
/**
* Represents a node that outputs an expression.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
#[YieldReady]
class PrintNode extends Node implements NodeOutputInterface
{
public function __construct(AbstractExpression $expr, int $lineno, ?string $tag = null)
{
parent::__construct(['expr' => $expr], [], $lineno, $tag);
}
public function compile(Compiler $compiler): void
{
2024-09-05 17:51:48 +00:00
/** @var AbstractExpression */
$expr = $this->getNode('expr');
2024-06-20 14:10:42 +00:00
$compiler
2024-09-05 17:51:48 +00:00
->addDebugInfo($this)
->write($expr->isGenerator() ? 'yield from ' : 'yield ')
->subcompile($expr)
2024-06-20 14:10:42 +00:00
->raw(";\n")
;
}
}