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

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