vendor/twig/twig/src/Node/PrintNode.php line 32

  1. <?php
  2. /*
  3.  * This file is part of Twig.
  4.  *
  5.  * (c) Fabien Potencier
  6.  * (c) Armin Ronacher
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace Twig\Node;
  12. use Twig\Attribute\YieldReady;
  13. use Twig\Compiler;
  14. use Twig\Node\Expression\AbstractExpression;
  15. /**
  16.  * Represents a node that outputs an expression.
  17.  *
  18.  * @author Fabien Potencier <fabien@symfony.com>
  19.  */
  20. #[YieldReady]
  21. class PrintNode extends Node implements NodeOutputInterface
  22. {
  23.     public function __construct(AbstractExpression $exprint $lineno, ?string $tag null)
  24.     {
  25.         parent::__construct(['expr' => $expr], [], $lineno$tag);
  26.     }
  27.     public function compile(Compiler $compiler): void
  28.     {
  29.         /** @var AbstractExpression */
  30.         $expr $this->getNode('expr');
  31.         $compiler
  32.             ->addDebugInfo($this)
  33.             ->write($expr->isGenerator() ? 'yield from ' 'yield ')
  34.             ->subcompile($expr)
  35.             ->raw(";\n")
  36.         ;
  37.     }
  38. }