vendor/twig/twig/src/Node/BlockNode.php line 31

Open in your IDE?
  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. /**
  15.  * Represents a block node.
  16.  *
  17.  * @author Fabien Potencier <fabien@symfony.com>
  18.  */
  19. #[YieldReady]
  20. class BlockNode extends Node
  21. {
  22.     public function __construct(string $nameNode $bodyint $lineno, ?string $tag null)
  23.     {
  24.         parent::__construct(['body' => $body], ['name' => $name], $lineno$tag);
  25.     }
  26.     public function compile(Compiler $compiler): void
  27.     {
  28.         $compiler
  29.             ->addDebugInfo($this)
  30.             ->write(sprintf("public function block_%s(\$context, array \$blocks = [])\n"$this->getAttribute('name')), "{\n")
  31.             ->indent()
  32.             ->write("\$macros = \$this->macros;\n")
  33.         ;
  34.         $compiler
  35.             ->subcompile($this->getNode('body'))
  36.             ->write("return; yield '';\n"// needed when body doesn't yield anything
  37.             ->outdent()
  38.             ->write("}\n\n")
  39.         ;
  40.     }
  41. }