vendor/twig/twig/src/TokenParser/WithTokenParser.php line 44

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Twig.
  4.  *
  5.  * (c) Fabien Potencier
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Twig\TokenParser;
  11. use Twig\Node\Node;
  12. use Twig\Node\WithNode;
  13. use Twig\Token;
  14. /**
  15.  * Creates a nested scope.
  16.  *
  17.  * @author Fabien Potencier <fabien@symfony.com>
  18.  *
  19.  * @internal
  20.  */
  21. final class WithTokenParser extends AbstractTokenParser
  22. {
  23.     public function parse(Token $token): Node
  24.     {
  25.         $stream $this->parser->getStream();
  26.         $variables null;
  27.         $only false;
  28.         if (!$stream->test(/* Token::BLOCK_END_TYPE */ 3)) {
  29.             $variables $this->parser->getExpressionParser()->parseExpression();
  30.             $only = (bool) $stream->nextIf(/* Token::NAME_TYPE */ 5'only');
  31.         }
  32.         $stream->expect(/* Token::BLOCK_END_TYPE */ 3);
  33.         $body $this->parser->subparse([$this'decideWithEnd'], true);
  34.         $stream->expect(/* Token::BLOCK_END_TYPE */ 3);
  35.         return new WithNode($body$variables$only$token->getLine(), $this->getTag());
  36.     }
  37.     public function decideWithEnd(Token $token): bool
  38.     {
  39.         return $token->test('endwith');
  40.     }
  41.     public function getTag(): string
  42.     {
  43.         return 'with';
  44.     }
  45. }