1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-12-19 10:55:56 +01:00
vichan/inc/lib/Twig/TokenParser/Include.php

66 lines
1.6 KiB
PHP
Raw Normal View History

2011-10-05 06:22:53 +02:00
<?php
/*
* This file is part of Twig.
*
2018-05-10 12:24:53 +02:00
* (c) Fabien Potencier
* (c) Armin Ronacher
2011-10-05 06:22:53 +02:00
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Includes a template.
*
* <pre>
* {% include 'header.html' %}
* Body
* {% include 'footer.html' %}
* </pre>
*/
class Twig_TokenParser_Include extends Twig_TokenParser
{
public function parse(Twig_Token $token)
{
$expr = $this->parser->getExpressionParser()->parseExpression();
2013-08-01 21:20:12 +02:00
list($variables, $only, $ignoreMissing) = $this->parseArguments();
return new Twig_Node_Include($expr, $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag());
}
protected function parseArguments()
{
$stream = $this->parser->getStream();
2011-10-05 06:22:53 +02:00
$ignoreMissing = false;
2018-05-10 12:24:53 +02:00
if ($stream->nextIf(Twig_Token::NAME_TYPE, 'ignore')) {
2013-08-01 21:20:12 +02:00
$stream->expect(Twig_Token::NAME_TYPE, 'missing');
2011-10-05 06:22:53 +02:00
$ignoreMissing = true;
}
$variables = null;
2018-05-10 12:24:53 +02:00
if ($stream->nextIf(Twig_Token::NAME_TYPE, 'with')) {
2011-10-05 06:22:53 +02:00
$variables = $this->parser->getExpressionParser()->parseExpression();
}
$only = false;
2018-05-10 12:24:53 +02:00
if ($stream->nextIf(Twig_Token::NAME_TYPE, 'only')) {
2011-10-05 06:22:53 +02:00
$only = true;
}
2013-08-01 21:20:12 +02:00
$stream->expect(Twig_Token::BLOCK_END_TYPE);
2011-10-05 06:22:53 +02:00
2013-08-01 21:20:12 +02:00
return array($variables, $only, $ignoreMissing);
2011-10-05 06:22:53 +02:00
}
public function getTag()
{
return 'include';
}
}
2018-05-10 12:24:53 +02:00
class_alias('Twig_TokenParser_Include', 'Twig\TokenParser\IncludeTokenParser', false);