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

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\WithNode;
  12. use Twig\Token;
  13. /**
  14. * Creates a nested scope.
  15. *
  16. * @author Fabien Potencier <fabien@symfony.com>
  17. */
  18. final class WithTokenParser extends AbstractTokenParser
  19. {
  20. public function parse(Token $token)
  21. {
  22. $stream = $this->parser->getStream();
  23. $variables = null;
  24. $only = false;
  25. if (!$stream->test(/* Token::BLOCK_END_TYPE */ 3)) {
  26. $variables = $this->parser->getExpressionParser()->parseExpression();
  27. $only = (bool) $stream->nextIf(/* Token::NAME_TYPE */ 5, 'only');
  28. }
  29. $stream->expect(/* Token::BLOCK_END_TYPE */ 3);
  30. $body = $this->parser->subparse([$this, 'decideWithEnd'], true);
  31. $stream->expect(/* Token::BLOCK_END_TYPE */ 3);
  32. return new WithNode($body, $variables, $only, $token->getLine(), $this->getTag());
  33. }
  34. public function decideWithEnd(Token $token)
  35. {
  36. return $token->test('endwith');
  37. }
  38. public function getTag()
  39. {
  40. return 'with';
  41. }
  42. }
  43. class_alias('Twig\TokenParser\WithTokenParser', 'Twig_TokenParser_With');