DumpTokenParser.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  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 Symfony\Bridge\Twig\TokenParser;
  11. use Symfony\Bridge\Twig\Node\DumpNode;
  12. use Twig\Token;
  13. use Twig\TokenParser\AbstractTokenParser;
  14. /**
  15. * Token Parser for the 'dump' tag.
  16. *
  17. * Dump variables with:
  18. * <pre>
  19. * {% dump %}
  20. * {% dump foo %}
  21. * {% dump foo, bar %}
  22. * </pre>
  23. *
  24. * @author Julien Galenski <julien.galenski@gmail.com>
  25. */
  26. class DumpTokenParser extends AbstractTokenParser
  27. {
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function parse(Token $token)
  32. {
  33. $values = null;
  34. if (!$this->parser->getStream()->test(Token::BLOCK_END_TYPE)) {
  35. $values = $this->parser->getExpressionParser()->parseMultitargetExpression();
  36. }
  37. $this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
  38. return new DumpNode($this->parser->getVarName(), $values, $token->getLine(), $this->getTag());
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function getTag()
  44. {
  45. return 'dump';
  46. }
  47. }