1<?php 2 3/* 4 * This file is part of Twig. 5 * 6 * (c) Fabien Potencier 7 * (c) Armin Ronacher 8 * 9 * For the full copyright and license information, please view the LICENSE 10 * file that was distributed with this source code. 11 */ 12 13namespace Twig\TokenParser; 14 15use Twig\Node\IncludeNode; 16use Twig\Token; 17 18/** 19 * Includes a template. 20 * 21 * {% include 'header.html' %} 22 * Body 23 * {% include 'footer.html' %} 24 */ 25class IncludeTokenParser extends AbstractTokenParser 26{ 27 public function parse(Token $token) 28 { 29 $expr = $this->parser->getExpressionParser()->parseExpression(); 30 31 list($variables, $only, $ignoreMissing) = $this->parseArguments(); 32 33 return new IncludeNode($expr, $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); 34 } 35 36 protected function parseArguments() 37 { 38 $stream = $this->parser->getStream(); 39 40 $ignoreMissing = false; 41 if ($stream->nextIf(/* Token::NAME_TYPE */ 5, 'ignore')) { 42 $stream->expect(/* Token::NAME_TYPE */ 5, 'missing'); 43 44 $ignoreMissing = true; 45 } 46 47 $variables = null; 48 if ($stream->nextIf(/* Token::NAME_TYPE */ 5, 'with')) { 49 $variables = $this->parser->getExpressionParser()->parseExpression(); 50 } 51 52 $only = false; 53 if ($stream->nextIf(/* Token::NAME_TYPE */ 5, 'only')) { 54 $only = true; 55 } 56 57 $stream->expect(/* Token::BLOCK_END_TYPE */ 3); 58 59 return [$variables, $only, $ignoreMissing]; 60 } 61 62 public function getTag() 63 { 64 return 'include'; 65 } 66} 67 68class_alias('Twig\TokenParser\IncludeTokenParser', 'Twig_TokenParser_Include'); 69