vendor/twig/twig/src/TokenParser/IncludeTokenParser.php line 36

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\TokenParser;
  12. use Twig\Node\IncludeNode;
  13. use Twig\Node\Node;
  14. use Twig\Token;
  15. /**
  16.  * Includes a template.
  17.  *
  18.  *   {% include 'header.html' %}
  19.  *     Body
  20.  *   {% include 'footer.html' %}
  21.  *
  22.  * @internal
  23.  */
  24. class IncludeTokenParser extends AbstractTokenParser
  25. {
  26.     public function parse(Token $token): Node
  27.     {
  28.         $expr $this->parser->getExpressionParser()->parseExpression();
  29.         list($variables$only$ignoreMissing) = $this->parseArguments();
  30.         return new IncludeNode($expr$variables$only$ignoreMissing$token->getLine(), $this->getTag());
  31.     }
  32.     protected function parseArguments()
  33.     {
  34.         $stream $this->parser->getStream();
  35.         $ignoreMissing false;
  36.         if ($stream->nextIf(/* Token::NAME_TYPE */ 5'ignore')) {
  37.             $stream->expect(/* Token::NAME_TYPE */ 5'missing');
  38.             $ignoreMissing true;
  39.         }
  40.         $variables null;
  41.         if ($stream->nextIf(/* Token::NAME_TYPE */ 5'with')) {
  42.             $variables $this->parser->getExpressionParser()->parseExpression();
  43.         }
  44.         $only false;
  45.         if ($stream->nextIf(/* Token::NAME_TYPE */ 5'only')) {
  46.             $only true;
  47.         }
  48.         $stream->expect(/* Token::BLOCK_END_TYPE */ 3);
  49.         return [$variables$only$ignoreMissing];
  50.     }
  51.     public function getTag(): string
  52.     {
  53.         return 'include';
  54.     }
  55. }