mirror of
https://github.com/slawkens/myaac.git
synced 2025-10-17 11:13:27 +02:00
Update Twig from 1.35.0 to 1.42.4 (PHP 5.5 is now required!)
This fixes some errors on PHP 7.4 and contains even more fixes Also bumped PHP version to 5.5 as Twig requires it.
This commit is contained in:
34
system/libs/Twig/TokenParser/AbstractTokenParser.php
Normal file
34
system/libs/Twig/TokenParser/AbstractTokenParser.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Twig\TokenParser;
|
||||
|
||||
use Twig\Parser;
|
||||
|
||||
/**
|
||||
* Base class for all token parsers.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
abstract class AbstractTokenParser implements TokenParserInterface
|
||||
{
|
||||
/**
|
||||
* @var Parser
|
||||
*/
|
||||
protected $parser;
|
||||
|
||||
public function setParser(Parser $parser)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig\TokenParser\AbstractTokenParser', 'Twig_TokenParser');
|
58
system/libs/Twig/TokenParser/ApplyTokenParser.php
Normal file
58
system/libs/Twig/TokenParser/ApplyTokenParser.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Twig\TokenParser;
|
||||
|
||||
use Twig\Node\Expression\TempNameExpression;
|
||||
use Twig\Node\Node;
|
||||
use Twig\Node\PrintNode;
|
||||
use Twig\Node\SetNode;
|
||||
use Twig\Token;
|
||||
|
||||
/**
|
||||
* Applies filters on a section of a template.
|
||||
*
|
||||
* {% apply upper %}
|
||||
* This text becomes uppercase
|
||||
* {% endapplys %}
|
||||
*/
|
||||
final class ApplyTokenParser extends AbstractTokenParser
|
||||
{
|
||||
public function parse(Token $token)
|
||||
{
|
||||
$lineno = $token->getLine();
|
||||
$name = $this->parser->getVarName();
|
||||
|
||||
$ref = new TempNameExpression($name, $lineno);
|
||||
$ref->setAttribute('always_defined', true);
|
||||
|
||||
$filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag());
|
||||
|
||||
$this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
|
||||
$body = $this->parser->subparse([$this, 'decideApplyEnd'], true);
|
||||
$this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
|
||||
|
||||
return new Node([
|
||||
new SetNode(true, $ref, $body, $lineno, $this->getTag()),
|
||||
new PrintNode($filter, $lineno, $this->getTag()),
|
||||
]);
|
||||
}
|
||||
|
||||
public function decideApplyEnd(Token $token)
|
||||
{
|
||||
return $token->test('endapply');
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'apply';
|
||||
}
|
||||
}
|
@@ -1,83 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Marks a section of a template to be escaped or not.
|
||||
*
|
||||
* <pre>
|
||||
* {% autoescape true %}
|
||||
* Everything will be automatically escaped in this block
|
||||
* {% endautoescape %}
|
||||
*
|
||||
* {% autoescape false %}
|
||||
* Everything will be outputed as is in this block
|
||||
* {% endautoescape %}
|
||||
*
|
||||
* {% autoescape true js %}
|
||||
* Everything will be automatically escaped in this block
|
||||
* using the js escaping strategy
|
||||
* {% endautoescape %}
|
||||
* </pre>
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class Twig_TokenParser_AutoEscape extends Twig_TokenParser
|
||||
{
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$lineno = $token->getLine();
|
||||
$stream = $this->parser->getStream();
|
||||
|
||||
if ($stream->test(Twig_Token::BLOCK_END_TYPE)) {
|
||||
$value = 'html';
|
||||
} else {
|
||||
$expr = $this->parser->getExpressionParser()->parseExpression();
|
||||
if (!$expr instanceof Twig_Node_Expression_Constant) {
|
||||
throw new Twig_Error_Syntax('An escaping strategy must be a string or a bool.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
|
||||
}
|
||||
$value = $expr->getAttribute('value');
|
||||
|
||||
$compat = true === $value || false === $value;
|
||||
|
||||
if (true === $value) {
|
||||
$value = 'html';
|
||||
}
|
||||
|
||||
if ($compat && $stream->test(Twig_Token::NAME_TYPE)) {
|
||||
@trigger_error('Using the autoescape tag with "true" or "false" before the strategy name is deprecated since version 1.21.', E_USER_DEPRECATED);
|
||||
|
||||
if (false === $value) {
|
||||
throw new Twig_Error_Syntax('Unexpected escaping strategy as you set autoescaping to false.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
|
||||
}
|
||||
|
||||
$value = $stream->next()->getValue();
|
||||
}
|
||||
}
|
||||
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
$body = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
return new Twig_Node_AutoEscape($value, $body, $lineno, $this->getTag());
|
||||
}
|
||||
|
||||
public function decideBlockEnd(Twig_Token $token)
|
||||
{
|
||||
return $token->test('endautoescape');
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'autoescape';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_TokenParser_AutoEscape', 'Twig\TokenParser\AutoEscapeTokenParser', false);
|
88
system/libs/Twig/TokenParser/AutoEscapeTokenParser.php
Normal file
88
system/libs/Twig/TokenParser/AutoEscapeTokenParser.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Twig\TokenParser;
|
||||
|
||||
use Twig\Error\SyntaxError;
|
||||
use Twig\Node\AutoEscapeNode;
|
||||
use Twig\Node\Expression\ConstantExpression;
|
||||
use Twig\Token;
|
||||
|
||||
/**
|
||||
* Marks a section of a template to be escaped or not.
|
||||
*
|
||||
* {% autoescape true %}
|
||||
* Everything will be automatically escaped in this block
|
||||
* {% endautoescape %}
|
||||
*
|
||||
* {% autoescape false %}
|
||||
* Everything will be outputed as is in this block
|
||||
* {% endautoescape %}
|
||||
*
|
||||
* {% autoescape true js %}
|
||||
* Everything will be automatically escaped in this block
|
||||
* using the js escaping strategy
|
||||
* {% endautoescape %}
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class AutoEscapeTokenParser extends AbstractTokenParser
|
||||
{
|
||||
public function parse(Token $token)
|
||||
{
|
||||
$lineno = $token->getLine();
|
||||
$stream = $this->parser->getStream();
|
||||
|
||||
if ($stream->test(Token::BLOCK_END_TYPE)) {
|
||||
$value = 'html';
|
||||
} else {
|
||||
$expr = $this->parser->getExpressionParser()->parseExpression();
|
||||
if (!$expr instanceof ConstantExpression) {
|
||||
throw new SyntaxError('An escaping strategy must be a string or a bool.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
|
||||
}
|
||||
$value = $expr->getAttribute('value');
|
||||
|
||||
$compat = true === $value || false === $value;
|
||||
|
||||
if (true === $value) {
|
||||
$value = 'html';
|
||||
}
|
||||
|
||||
if ($compat && $stream->test(Token::NAME_TYPE)) {
|
||||
@trigger_error('Using the autoescape tag with "true" or "false" before the strategy name is deprecated since version 1.21.', E_USER_DEPRECATED);
|
||||
|
||||
if (false === $value) {
|
||||
throw new SyntaxError('Unexpected escaping strategy as you set autoescaping to false.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
|
||||
}
|
||||
|
||||
$value = $stream->next()->getValue();
|
||||
}
|
||||
}
|
||||
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
$body = $this->parser->subparse([$this, 'decideBlockEnd'], true);
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
|
||||
return new AutoEscapeNode($value, $body, $lineno, $this->getTag());
|
||||
}
|
||||
|
||||
public function decideBlockEnd(Token $token)
|
||||
{
|
||||
return $token->test('endautoescape');
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'autoescape';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig\TokenParser\AutoEscapeTokenParser', 'Twig_TokenParser_AutoEscape');
|
@@ -1,73 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
* (c) Armin Ronacher
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Marks a section of a template as being reusable.
|
||||
*
|
||||
* <pre>
|
||||
* {% block head %}
|
||||
* <link rel="stylesheet" href="style.css" />
|
||||
* <title>{% block title %}{% endblock %} - My Webpage</title>
|
||||
* {% endblock %}
|
||||
* </pre>
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class Twig_TokenParser_Block extends Twig_TokenParser
|
||||
{
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$lineno = $token->getLine();
|
||||
$stream = $this->parser->getStream();
|
||||
$name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
|
||||
if ($this->parser->hasBlock($name)) {
|
||||
throw new Twig_Error_Syntax(sprintf("The block '%s' has already been defined line %d.", $name, $this->parser->getBlock($name)->getTemplateLine()), $stream->getCurrent()->getLine(), $stream->getSourceContext());
|
||||
}
|
||||
$this->parser->setBlock($name, $block = new Twig_Node_Block($name, new Twig_Node(array()), $lineno));
|
||||
$this->parser->pushLocalScope();
|
||||
$this->parser->pushBlockStack($name);
|
||||
|
||||
if ($stream->nextIf(Twig_Token::BLOCK_END_TYPE)) {
|
||||
$body = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
|
||||
if ($token = $stream->nextIf(Twig_Token::NAME_TYPE)) {
|
||||
$value = $token->getValue();
|
||||
|
||||
if ($value != $name) {
|
||||
throw new Twig_Error_Syntax(sprintf('Expected endblock for block "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$body = new Twig_Node(array(
|
||||
new Twig_Node_Print($this->parser->getExpressionParser()->parseExpression(), $lineno),
|
||||
));
|
||||
}
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
$block->setNode('body', $body);
|
||||
$this->parser->popBlockStack();
|
||||
$this->parser->popLocalScope();
|
||||
|
||||
return new Twig_Node_BlockReference($name, $lineno, $this->getTag());
|
||||
}
|
||||
|
||||
public function decideBlockEnd(Twig_Token $token)
|
||||
{
|
||||
return $token->test('endblock');
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'block';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_TokenParser_Block', 'Twig\TokenParser\BlockTokenParser', false);
|
80
system/libs/Twig/TokenParser/BlockTokenParser.php
Normal file
80
system/libs/Twig/TokenParser/BlockTokenParser.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
* (c) Armin Ronacher
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Twig\TokenParser;
|
||||
|
||||
use Twig\Error\SyntaxError;
|
||||
use Twig\Node\BlockNode;
|
||||
use Twig\Node\BlockReferenceNode;
|
||||
use Twig\Node\Node;
|
||||
use Twig\Node\PrintNode;
|
||||
use Twig\Token;
|
||||
|
||||
/**
|
||||
* Marks a section of a template as being reusable.
|
||||
*
|
||||
* {% block head %}
|
||||
* <link rel="stylesheet" href="style.css" />
|
||||
* <title>{% block title %}{% endblock %} - My Webpage</title>
|
||||
* {% endblock %}
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class BlockTokenParser extends AbstractTokenParser
|
||||
{
|
||||
public function parse(Token $token)
|
||||
{
|
||||
$lineno = $token->getLine();
|
||||
$stream = $this->parser->getStream();
|
||||
$name = $stream->expect(Token::NAME_TYPE)->getValue();
|
||||
if ($this->parser->hasBlock($name)) {
|
||||
throw new SyntaxError(sprintf("The block '%s' has already been defined line %d.", $name, $this->parser->getBlock($name)->getTemplateLine()), $stream->getCurrent()->getLine(), $stream->getSourceContext());
|
||||
}
|
||||
$this->parser->setBlock($name, $block = new BlockNode($name, new Node([]), $lineno));
|
||||
$this->parser->pushLocalScope();
|
||||
$this->parser->pushBlockStack($name);
|
||||
|
||||
if ($stream->nextIf(Token::BLOCK_END_TYPE)) {
|
||||
$body = $this->parser->subparse([$this, 'decideBlockEnd'], true);
|
||||
if ($token = $stream->nextIf(Token::NAME_TYPE)) {
|
||||
$value = $token->getValue();
|
||||
|
||||
if ($value != $name) {
|
||||
throw new SyntaxError(sprintf('Expected endblock for block "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$body = new Node([
|
||||
new PrintNode($this->parser->getExpressionParser()->parseExpression(), $lineno),
|
||||
]);
|
||||
}
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
|
||||
$block->setNode('body', $body);
|
||||
$this->parser->popBlockStack();
|
||||
$this->parser->popLocalScope();
|
||||
|
||||
return new BlockReferenceNode($name, $lineno, $this->getTag());
|
||||
}
|
||||
|
||||
public function decideBlockEnd(Token $token)
|
||||
{
|
||||
return $token->test('endblock');
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'block';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig\TokenParser\BlockTokenParser', 'Twig_TokenParser_Block');
|
44
system/libs/Twig/TokenParser/DeprecatedTokenParser.php
Normal file
44
system/libs/Twig/TokenParser/DeprecatedTokenParser.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Twig\TokenParser;
|
||||
|
||||
use Twig\Node\DeprecatedNode;
|
||||
use Twig\Token;
|
||||
|
||||
/**
|
||||
* Deprecates a section of a template.
|
||||
*
|
||||
* {% deprecated 'The "base.twig" template is deprecated, use "layout.twig" instead.' %}
|
||||
* {% extends 'layout.html.twig' %}
|
||||
*
|
||||
* @author Yonel Ceruto <yonelceruto@gmail.com>
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class DeprecatedTokenParser extends AbstractTokenParser
|
||||
{
|
||||
public function parse(Token $token)
|
||||
{
|
||||
$expr = $this->parser->getExpressionParser()->parseExpression();
|
||||
|
||||
$this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
|
||||
|
||||
return new DeprecatedNode($expr, $token->getLine(), $this->getTag());
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'deprecated';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig\TokenParser\DeprecatedTokenParser', 'Twig_TokenParser_Deprecated');
|
15
system/libs/Twig/TokenParser/Do.php → system/libs/Twig/TokenParser/DoTokenParser.php
Executable file → Normal file
15
system/libs/Twig/TokenParser/Do.php → system/libs/Twig/TokenParser/DoTokenParser.php
Executable file → Normal file
@@ -9,20 +9,25 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Twig\TokenParser;
|
||||
|
||||
use Twig\Node\DoNode;
|
||||
use Twig\Token;
|
||||
|
||||
/**
|
||||
* Evaluates an expression, discarding the returned value.
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class Twig_TokenParser_Do extends Twig_TokenParser
|
||||
class DoTokenParser extends AbstractTokenParser
|
||||
{
|
||||
public function parse(Twig_Token $token)
|
||||
public function parse(Token $token)
|
||||
{
|
||||
$expr = $this->parser->getExpressionParser()->parseExpression();
|
||||
|
||||
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
$this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
|
||||
|
||||
return new Twig_Node_Do($expr, $token->getLine(), $this->getTag());
|
||||
return new DoNode($expr, $token->getLine(), $this->getTag());
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
@@ -31,4 +36,4 @@ class Twig_TokenParser_Do extends Twig_TokenParser
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_TokenParser_Do', 'Twig\TokenParser\DoTokenParser', false);
|
||||
class_alias('Twig\TokenParser\DoTokenParser', 'Twig_TokenParser_Do');
|
@@ -1,67 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Embeds a template.
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class Twig_TokenParser_Embed extends Twig_TokenParser_Include
|
||||
{
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$stream = $this->parser->getStream();
|
||||
|
||||
$parent = $this->parser->getExpressionParser()->parseExpression();
|
||||
|
||||
list($variables, $only, $ignoreMissing) = $this->parseArguments();
|
||||
|
||||
$parentToken = $fakeParentToken = new Twig_Token(Twig_Token::STRING_TYPE, '__parent__', $token->getLine());
|
||||
if ($parent instanceof Twig_Node_Expression_Constant) {
|
||||
$parentToken = new Twig_Token(Twig_Token::STRING_TYPE, $parent->getAttribute('value'), $token->getLine());
|
||||
} elseif ($parent instanceof Twig_Node_Expression_Name) {
|
||||
$parentToken = new Twig_Token(Twig_Token::NAME_TYPE, $parent->getAttribute('name'), $token->getLine());
|
||||
}
|
||||
|
||||
// inject a fake parent to make the parent() function work
|
||||
$stream->injectTokens(array(
|
||||
new Twig_Token(Twig_Token::BLOCK_START_TYPE, '', $token->getLine()),
|
||||
new Twig_Token(Twig_Token::NAME_TYPE, 'extends', $token->getLine()),
|
||||
$parentToken,
|
||||
new Twig_Token(Twig_Token::BLOCK_END_TYPE, '', $token->getLine()),
|
||||
));
|
||||
|
||||
$module = $this->parser->parse($stream, array($this, 'decideBlockEnd'), true);
|
||||
|
||||
// override the parent with the correct one
|
||||
if ($fakeParentToken === $parentToken) {
|
||||
$module->setNode('parent', $parent);
|
||||
}
|
||||
|
||||
$this->parser->embedTemplate($module);
|
||||
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
return new Twig_Node_Embed($module->getTemplateName(), $module->getAttribute('index'), $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag());
|
||||
}
|
||||
|
||||
public function decideBlockEnd(Twig_Token $token)
|
||||
{
|
||||
return $token->test('endembed');
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'embed';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_TokenParser_Embed', 'Twig\TokenParser\EmbedTokenParser', false);
|
74
system/libs/Twig/TokenParser/EmbedTokenParser.php
Normal file
74
system/libs/Twig/TokenParser/EmbedTokenParser.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Twig\TokenParser;
|
||||
|
||||
use Twig\Node\EmbedNode;
|
||||
use Twig\Node\Expression\ConstantExpression;
|
||||
use Twig\Node\Expression\NameExpression;
|
||||
use Twig\Token;
|
||||
|
||||
/**
|
||||
* Embeds a template.
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class EmbedTokenParser extends IncludeTokenParser
|
||||
{
|
||||
public function parse(Token $token)
|
||||
{
|
||||
$stream = $this->parser->getStream();
|
||||
|
||||
$parent = $this->parser->getExpressionParser()->parseExpression();
|
||||
|
||||
list($variables, $only, $ignoreMissing) = $this->parseArguments();
|
||||
|
||||
$parentToken = $fakeParentToken = new Token(Token::STRING_TYPE, '__parent__', $token->getLine());
|
||||
if ($parent instanceof ConstantExpression) {
|
||||
$parentToken = new Token(Token::STRING_TYPE, $parent->getAttribute('value'), $token->getLine());
|
||||
} elseif ($parent instanceof NameExpression) {
|
||||
$parentToken = new Token(Token::NAME_TYPE, $parent->getAttribute('name'), $token->getLine());
|
||||
}
|
||||
|
||||
// inject a fake parent to make the parent() function work
|
||||
$stream->injectTokens([
|
||||
new Token(Token::BLOCK_START_TYPE, '', $token->getLine()),
|
||||
new Token(Token::NAME_TYPE, 'extends', $token->getLine()),
|
||||
$parentToken,
|
||||
new Token(Token::BLOCK_END_TYPE, '', $token->getLine()),
|
||||
]);
|
||||
|
||||
$module = $this->parser->parse($stream, [$this, 'decideBlockEnd'], true);
|
||||
|
||||
// override the parent with the correct one
|
||||
if ($fakeParentToken === $parentToken) {
|
||||
$module->setNode('parent', $parent);
|
||||
}
|
||||
|
||||
$this->parser->embedTemplate($module);
|
||||
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
|
||||
return new EmbedNode($module->getTemplateName(), $module->getAttribute('index'), $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag());
|
||||
}
|
||||
|
||||
public function decideBlockEnd(Token $token)
|
||||
{
|
||||
return $token->test('endembed');
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'embed';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig\TokenParser\EmbedTokenParser', 'Twig_TokenParser_Embed');
|
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
* (c) Armin Ronacher
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Extends a template by another one.
|
||||
*
|
||||
* <pre>
|
||||
* {% extends "base.html" %}
|
||||
* </pre>
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class Twig_TokenParser_Extends extends Twig_TokenParser
|
||||
{
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$stream = $this->parser->getStream();
|
||||
|
||||
if (!$this->parser->isMainScope()) {
|
||||
throw new Twig_Error_Syntax('Cannot extend from a block.', $token->getLine(), $stream->getSourceContext());
|
||||
}
|
||||
|
||||
if (null !== $this->parser->getParent()) {
|
||||
throw new Twig_Error_Syntax('Multiple extends tags are forbidden.', $token->getLine(), $stream->getSourceContext());
|
||||
}
|
||||
$this->parser->setParent($this->parser->getExpressionParser()->parseExpression());
|
||||
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'extends';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_TokenParser_Extends', 'Twig\TokenParser\ExtendsTokenParser', false);
|
54
system/libs/Twig/TokenParser/ExtendsTokenParser.php
Normal file
54
system/libs/Twig/TokenParser/ExtendsTokenParser.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
* (c) Armin Ronacher
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Twig\TokenParser;
|
||||
|
||||
use Twig\Error\SyntaxError;
|
||||
use Twig\Node\Node;
|
||||
use Twig\Token;
|
||||
|
||||
/**
|
||||
* Extends a template by another one.
|
||||
*
|
||||
* {% extends "base.html" %}
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class ExtendsTokenParser extends AbstractTokenParser
|
||||
{
|
||||
public function parse(Token $token)
|
||||
{
|
||||
$stream = $this->parser->getStream();
|
||||
|
||||
if ($this->parser->peekBlockStack()) {
|
||||
throw new SyntaxError('Cannot use "extend" in a block.', $token->getLine(), $stream->getSourceContext());
|
||||
} elseif (!$this->parser->isMainScope()) {
|
||||
throw new SyntaxError('Cannot use "extend" in a macro.', $token->getLine(), $stream->getSourceContext());
|
||||
}
|
||||
|
||||
if (null !== $this->parser->getParent()) {
|
||||
throw new SyntaxError('Multiple extends tags are forbidden.', $token->getLine(), $stream->getSourceContext());
|
||||
}
|
||||
$this->parser->setParent($this->parser->getExpressionParser()->parseExpression());
|
||||
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
|
||||
return new Node();
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'extends';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig\TokenParser\ExtendsTokenParser', 'Twig_TokenParser_Extends');
|
@@ -1,53 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Filters a section of a template by applying filters.
|
||||
*
|
||||
* <pre>
|
||||
* {% filter upper %}
|
||||
* This text becomes uppercase
|
||||
* {% endfilter %}
|
||||
* </pre>
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class Twig_TokenParser_Filter extends Twig_TokenParser
|
||||
{
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$name = $this->parser->getVarName();
|
||||
$ref = new Twig_Node_Expression_BlockReference(new Twig_Node_Expression_Constant($name, $token->getLine()), null, $token->getLine(), $this->getTag());
|
||||
|
||||
$filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag());
|
||||
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
$body = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
|
||||
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
$block = new Twig_Node_Block($name, $body, $token->getLine());
|
||||
$this->parser->setBlock($name, $block);
|
||||
|
||||
return new Twig_Node_Print($filter, $token->getLine(), $this->getTag());
|
||||
}
|
||||
|
||||
public function decideBlockEnd(Twig_Token $token)
|
||||
{
|
||||
return $token->test('endfilter');
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'filter';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_TokenParser_Filter', 'Twig\TokenParser\FilterTokenParser', false);
|
59
system/libs/Twig/TokenParser/FilterTokenParser.php
Normal file
59
system/libs/Twig/TokenParser/FilterTokenParser.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Twig\TokenParser;
|
||||
|
||||
use Twig\Node\BlockNode;
|
||||
use Twig\Node\Expression\BlockReferenceExpression;
|
||||
use Twig\Node\Expression\ConstantExpression;
|
||||
use Twig\Node\PrintNode;
|
||||
use Twig\Token;
|
||||
|
||||
/**
|
||||
* Filters a section of a template by applying filters.
|
||||
*
|
||||
* {% filter upper %}
|
||||
* This text becomes uppercase
|
||||
* {% endfilter %}
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class FilterTokenParser extends AbstractTokenParser
|
||||
{
|
||||
public function parse(Token $token)
|
||||
{
|
||||
$name = $this->parser->getVarName();
|
||||
$ref = new BlockReferenceExpression(new ConstantExpression($name, $token->getLine()), null, $token->getLine(), $this->getTag());
|
||||
|
||||
$filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag());
|
||||
$this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
|
||||
|
||||
$body = $this->parser->subparse([$this, 'decideBlockEnd'], true);
|
||||
$this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
|
||||
|
||||
$block = new BlockNode($name, $body, $token->getLine());
|
||||
$this->parser->setBlock($name, $block);
|
||||
|
||||
return new PrintNode($filter, $token->getLine(), $this->getTag());
|
||||
}
|
||||
|
||||
public function decideBlockEnd(Token $token)
|
||||
{
|
||||
return $token->test('endfilter');
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'filter';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig\TokenParser\FilterTokenParser', 'Twig_TokenParser_Filter');
|
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Flushes the output to the client.
|
||||
*
|
||||
* @see flush()
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class Twig_TokenParser_Flush extends Twig_TokenParser
|
||||
{
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
return new Twig_Node_Flush($token->getLine(), $this->getTag());
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'flush';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_TokenParser_Flush', 'Twig\TokenParser\FlushTokenParser', false);
|
39
system/libs/Twig/TokenParser/FlushTokenParser.php
Normal file
39
system/libs/Twig/TokenParser/FlushTokenParser.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Twig\TokenParser;
|
||||
|
||||
use Twig\Node\FlushNode;
|
||||
use Twig\Token;
|
||||
|
||||
/**
|
||||
* Flushes the output to the client.
|
||||
*
|
||||
* @see flush()
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class FlushTokenParser extends AbstractTokenParser
|
||||
{
|
||||
public function parse(Token $token)
|
||||
{
|
||||
$this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
|
||||
|
||||
return new FlushNode($token->getLine(), $this->getTag());
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'flush';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig\TokenParser\FlushTokenParser', 'Twig_TokenParser_Flush');
|
@@ -1,127 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
* (c) Armin Ronacher
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Loops over each item of a sequence.
|
||||
*
|
||||
* <pre>
|
||||
* <ul>
|
||||
* {% for user in users %}
|
||||
* <li>{{ user.username|e }}</li>
|
||||
* {% endfor %}
|
||||
* </ul>
|
||||
* </pre>
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class Twig_TokenParser_For extends Twig_TokenParser
|
||||
{
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$lineno = $token->getLine();
|
||||
$stream = $this->parser->getStream();
|
||||
$targets = $this->parser->getExpressionParser()->parseAssignmentExpression();
|
||||
$stream->expect(Twig_Token::OPERATOR_TYPE, 'in');
|
||||
$seq = $this->parser->getExpressionParser()->parseExpression();
|
||||
|
||||
$ifexpr = null;
|
||||
if ($stream->nextIf(Twig_Token::NAME_TYPE, 'if')) {
|
||||
$ifexpr = $this->parser->getExpressionParser()->parseExpression();
|
||||
}
|
||||
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
$body = $this->parser->subparse(array($this, 'decideForFork'));
|
||||
if ($stream->next()->getValue() == 'else') {
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
$else = $this->parser->subparse(array($this, 'decideForEnd'), true);
|
||||
} else {
|
||||
$else = null;
|
||||
}
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
if (count($targets) > 1) {
|
||||
$keyTarget = $targets->getNode(0);
|
||||
$keyTarget = new Twig_Node_Expression_AssignName($keyTarget->getAttribute('name'), $keyTarget->getTemplateLine());
|
||||
$valueTarget = $targets->getNode(1);
|
||||
$valueTarget = new Twig_Node_Expression_AssignName($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine());
|
||||
} else {
|
||||
$keyTarget = new Twig_Node_Expression_AssignName('_key', $lineno);
|
||||
$valueTarget = $targets->getNode(0);
|
||||
$valueTarget = new Twig_Node_Expression_AssignName($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine());
|
||||
}
|
||||
|
||||
if ($ifexpr) {
|
||||
$this->checkLoopUsageCondition($stream, $ifexpr);
|
||||
$this->checkLoopUsageBody($stream, $body);
|
||||
}
|
||||
|
||||
return new Twig_Node_For($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, $lineno, $this->getTag());
|
||||
}
|
||||
|
||||
public function decideForFork(Twig_Token $token)
|
||||
{
|
||||
return $token->test(array('else', 'endfor'));
|
||||
}
|
||||
|
||||
public function decideForEnd(Twig_Token $token)
|
||||
{
|
||||
return $token->test('endfor');
|
||||
}
|
||||
|
||||
// the loop variable cannot be used in the condition
|
||||
protected function checkLoopUsageCondition(Twig_TokenStream $stream, Twig_NodeInterface $node)
|
||||
{
|
||||
if ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name && 'loop' == $node->getNode('node')->getAttribute('name')) {
|
||||
throw new Twig_Error_Syntax('The "loop" variable cannot be used in a looping condition.', $node->getTemplateLine(), $stream->getSourceContext());
|
||||
}
|
||||
|
||||
foreach ($node as $n) {
|
||||
if (!$n) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->checkLoopUsageCondition($stream, $n);
|
||||
}
|
||||
}
|
||||
|
||||
// check usage of non-defined loop-items
|
||||
// it does not catch all problems (for instance when a for is included into another or when the variable is used in an include)
|
||||
protected function checkLoopUsageBody(Twig_TokenStream $stream, Twig_NodeInterface $node)
|
||||
{
|
||||
if ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name && 'loop' == $node->getNode('node')->getAttribute('name')) {
|
||||
$attribute = $node->getNode('attribute');
|
||||
if ($attribute instanceof Twig_Node_Expression_Constant && in_array($attribute->getAttribute('value'), array('length', 'revindex0', 'revindex', 'last'))) {
|
||||
throw new Twig_Error_Syntax(sprintf('The "loop.%s" variable is not defined when looping with a condition.', $attribute->getAttribute('value')), $node->getTemplateLine(), $stream->getSourceContext());
|
||||
}
|
||||
}
|
||||
|
||||
// should check for parent.loop.XXX usage
|
||||
if ($node instanceof Twig_Node_For) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($node as $n) {
|
||||
if (!$n) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->checkLoopUsageBody($stream, $n);
|
||||
}
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'for';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_TokenParser_For', 'Twig\TokenParser\ForTokenParser', false);
|
136
system/libs/Twig/TokenParser/ForTokenParser.php
Normal file
136
system/libs/Twig/TokenParser/ForTokenParser.php
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
* (c) Armin Ronacher
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Twig\TokenParser;
|
||||
|
||||
use Twig\Error\SyntaxError;
|
||||
use Twig\Node\Expression\AssignNameExpression;
|
||||
use Twig\Node\Expression\ConstantExpression;
|
||||
use Twig\Node\Expression\GetAttrExpression;
|
||||
use Twig\Node\Expression\NameExpression;
|
||||
use Twig\Node\ForNode;
|
||||
use Twig\Token;
|
||||
use Twig\TokenStream;
|
||||
|
||||
/**
|
||||
* Loops over each item of a sequence.
|
||||
*
|
||||
* <ul>
|
||||
* {% for user in users %}
|
||||
* <li>{{ user.username|e }}</li>
|
||||
* {% endfor %}
|
||||
* </ul>
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class ForTokenParser extends AbstractTokenParser
|
||||
{
|
||||
public function parse(Token $token)
|
||||
{
|
||||
$lineno = $token->getLine();
|
||||
$stream = $this->parser->getStream();
|
||||
$targets = $this->parser->getExpressionParser()->parseAssignmentExpression();
|
||||
$stream->expect(Token::OPERATOR_TYPE, 'in');
|
||||
$seq = $this->parser->getExpressionParser()->parseExpression();
|
||||
|
||||
$ifexpr = null;
|
||||
if ($stream->nextIf(Token::NAME_TYPE, 'if')) {
|
||||
$ifexpr = $this->parser->getExpressionParser()->parseExpression();
|
||||
}
|
||||
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
$body = $this->parser->subparse([$this, 'decideForFork']);
|
||||
if ('else' == $stream->next()->getValue()) {
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
$else = $this->parser->subparse([$this, 'decideForEnd'], true);
|
||||
} else {
|
||||
$else = null;
|
||||
}
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
|
||||
if (\count($targets) > 1) {
|
||||
$keyTarget = $targets->getNode(0);
|
||||
$keyTarget = new AssignNameExpression($keyTarget->getAttribute('name'), $keyTarget->getTemplateLine());
|
||||
$valueTarget = $targets->getNode(1);
|
||||
$valueTarget = new AssignNameExpression($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine());
|
||||
} else {
|
||||
$keyTarget = new AssignNameExpression('_key', $lineno);
|
||||
$valueTarget = $targets->getNode(0);
|
||||
$valueTarget = new AssignNameExpression($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine());
|
||||
}
|
||||
|
||||
if ($ifexpr) {
|
||||
$this->checkLoopUsageCondition($stream, $ifexpr);
|
||||
$this->checkLoopUsageBody($stream, $body);
|
||||
}
|
||||
|
||||
return new ForNode($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, $lineno, $this->getTag());
|
||||
}
|
||||
|
||||
public function decideForFork(Token $token)
|
||||
{
|
||||
return $token->test(['else', 'endfor']);
|
||||
}
|
||||
|
||||
public function decideForEnd(Token $token)
|
||||
{
|
||||
return $token->test('endfor');
|
||||
}
|
||||
|
||||
// the loop variable cannot be used in the condition
|
||||
protected function checkLoopUsageCondition(TokenStream $stream, \Twig_NodeInterface $node)
|
||||
{
|
||||
if ($node instanceof GetAttrExpression && $node->getNode('node') instanceof NameExpression && 'loop' == $node->getNode('node')->getAttribute('name')) {
|
||||
throw new SyntaxError('The "loop" variable cannot be used in a looping condition.', $node->getTemplateLine(), $stream->getSourceContext());
|
||||
}
|
||||
|
||||
foreach ($node as $n) {
|
||||
if (!$n) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->checkLoopUsageCondition($stream, $n);
|
||||
}
|
||||
}
|
||||
|
||||
// check usage of non-defined loop-items
|
||||
// it does not catch all problems (for instance when a for is included into another or when the variable is used in an include)
|
||||
protected function checkLoopUsageBody(TokenStream $stream, \Twig_NodeInterface $node)
|
||||
{
|
||||
if ($node instanceof GetAttrExpression && $node->getNode('node') instanceof NameExpression && 'loop' == $node->getNode('node')->getAttribute('name')) {
|
||||
$attribute = $node->getNode('attribute');
|
||||
if ($attribute instanceof ConstantExpression && \in_array($attribute->getAttribute('value'), ['length', 'revindex0', 'revindex', 'last'])) {
|
||||
throw new SyntaxError(sprintf('The "loop.%s" variable is not defined when looping with a condition.', $attribute->getAttribute('value')), $node->getTemplateLine(), $stream->getSourceContext());
|
||||
}
|
||||
}
|
||||
|
||||
// should check for parent.loop.XXX usage
|
||||
if ($node instanceof ForNode) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($node as $n) {
|
||||
if (!$n) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->checkLoopUsageBody($stream, $n);
|
||||
}
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'for';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig\TokenParser\ForTokenParser', 'Twig_TokenParser_For');
|
@@ -1,66 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Imports macros.
|
||||
*
|
||||
* <pre>
|
||||
* {% from 'forms.html' import forms %}
|
||||
* </pre>
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class Twig_TokenParser_From extends Twig_TokenParser
|
||||
{
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$macro = $this->parser->getExpressionParser()->parseExpression();
|
||||
$stream = $this->parser->getStream();
|
||||
$stream->expect('import');
|
||||
|
||||
$targets = array();
|
||||
do {
|
||||
$name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
|
||||
|
||||
$alias = $name;
|
||||
if ($stream->nextIf('as')) {
|
||||
$alias = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
|
||||
}
|
||||
|
||||
$targets[$name] = $alias;
|
||||
|
||||
if (!$stream->nextIf(Twig_Token::PUNCTUATION_TYPE, ',')) {
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
$node = new Twig_Node_Import($macro, new Twig_Node_Expression_AssignName($this->parser->getVarName(), $token->getLine()), $token->getLine(), $this->getTag());
|
||||
|
||||
foreach ($targets as $name => $alias) {
|
||||
if ($this->parser->isReservedMacroName($name)) {
|
||||
throw new Twig_Error_Syntax(sprintf('"%s" cannot be an imported macro as it is a reserved keyword.', $name), $token->getLine(), $stream->getSourceContext());
|
||||
}
|
||||
|
||||
$this->parser->addImportedSymbol('function', $alias, 'get'.$name, $node->getNode('var'));
|
||||
}
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'from';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_TokenParser_From', 'Twig\TokenParser\FromTokenParser', false);
|
72
system/libs/Twig/TokenParser/FromTokenParser.php
Normal file
72
system/libs/Twig/TokenParser/FromTokenParser.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Twig\TokenParser;
|
||||
|
||||
use Twig\Error\SyntaxError;
|
||||
use Twig\Node\Expression\AssignNameExpression;
|
||||
use Twig\Node\ImportNode;
|
||||
use Twig\Token;
|
||||
|
||||
/**
|
||||
* Imports macros.
|
||||
*
|
||||
* {% from 'forms.html' import forms %}
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class FromTokenParser extends AbstractTokenParser
|
||||
{
|
||||
public function parse(Token $token)
|
||||
{
|
||||
$macro = $this->parser->getExpressionParser()->parseExpression();
|
||||
$stream = $this->parser->getStream();
|
||||
$stream->expect(Token::NAME_TYPE, 'import');
|
||||
|
||||
$targets = [];
|
||||
do {
|
||||
$name = $stream->expect(Token::NAME_TYPE)->getValue();
|
||||
|
||||
$alias = $name;
|
||||
if ($stream->nextIf('as')) {
|
||||
$alias = $stream->expect(Token::NAME_TYPE)->getValue();
|
||||
}
|
||||
|
||||
$targets[$name] = $alias;
|
||||
|
||||
if (!$stream->nextIf(Token::PUNCTUATION_TYPE, ',')) {
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
|
||||
$var = new AssignNameExpression($this->parser->getVarName(), $token->getLine());
|
||||
$node = new ImportNode($macro, $var, $token->getLine(), $this->getTag());
|
||||
|
||||
foreach ($targets as $name => $alias) {
|
||||
if ($this->parser->isReservedMacroName($name)) {
|
||||
throw new SyntaxError(sprintf('"%s" cannot be an imported macro as it is a reserved keyword.', $name), $token->getLine(), $stream->getSourceContext());
|
||||
}
|
||||
|
||||
$this->parser->addImportedSymbol('function', $alias, 'get'.$name, $var);
|
||||
}
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'from';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig\TokenParser\FromTokenParser', 'Twig_TokenParser_From');
|
@@ -1,86 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
* (c) Armin Ronacher
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests a condition.
|
||||
*
|
||||
* <pre>
|
||||
* {% if users %}
|
||||
* <ul>
|
||||
* {% for user in users %}
|
||||
* <li>{{ user.username|e }}</li>
|
||||
* {% endfor %}
|
||||
* </ul>
|
||||
* {% endif %}
|
||||
* </pre>
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class Twig_TokenParser_If extends Twig_TokenParser
|
||||
{
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$lineno = $token->getLine();
|
||||
$expr = $this->parser->getExpressionParser()->parseExpression();
|
||||
$stream = $this->parser->getStream();
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
$body = $this->parser->subparse(array($this, 'decideIfFork'));
|
||||
$tests = array($expr, $body);
|
||||
$else = null;
|
||||
|
||||
$end = false;
|
||||
while (!$end) {
|
||||
switch ($stream->next()->getValue()) {
|
||||
case 'else':
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
$else = $this->parser->subparse(array($this, 'decideIfEnd'));
|
||||
break;
|
||||
|
||||
case 'elseif':
|
||||
$expr = $this->parser->getExpressionParser()->parseExpression();
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
$body = $this->parser->subparse(array($this, 'decideIfFork'));
|
||||
$tests[] = $expr;
|
||||
$tests[] = $body;
|
||||
break;
|
||||
|
||||
case 'endif':
|
||||
$end = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Twig_Error_Syntax(sprintf('Unexpected end of template. Twig was looking for the following tags "else", "elseif", or "endif" to close the "if" block started at line %d).', $lineno), $stream->getCurrent()->getLine(), $stream->getSourceContext());
|
||||
}
|
||||
}
|
||||
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
return new Twig_Node_If(new Twig_Node($tests), $else, $lineno, $this->getTag());
|
||||
}
|
||||
|
||||
public function decideIfFork(Twig_Token $token)
|
||||
{
|
||||
return $token->test(array('elseif', 'else', 'endif'));
|
||||
}
|
||||
|
||||
public function decideIfEnd(Twig_Token $token)
|
||||
{
|
||||
return $token->test(array('endif'));
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'if';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_TokenParser_If', 'Twig\TokenParser\IfTokenParser', false);
|
91
system/libs/Twig/TokenParser/IfTokenParser.php
Normal file
91
system/libs/Twig/TokenParser/IfTokenParser.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
* (c) Armin Ronacher
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Twig\TokenParser;
|
||||
|
||||
use Twig\Error\SyntaxError;
|
||||
use Twig\Node\IfNode;
|
||||
use Twig\Node\Node;
|
||||
use Twig\Token;
|
||||
|
||||
/**
|
||||
* Tests a condition.
|
||||
*
|
||||
* {% if users %}
|
||||
* <ul>
|
||||
* {% for user in users %}
|
||||
* <li>{{ user.username|e }}</li>
|
||||
* {% endfor %}
|
||||
* </ul>
|
||||
* {% endif %}
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class IfTokenParser extends AbstractTokenParser
|
||||
{
|
||||
public function parse(Token $token)
|
||||
{
|
||||
$lineno = $token->getLine();
|
||||
$expr = $this->parser->getExpressionParser()->parseExpression();
|
||||
$stream = $this->parser->getStream();
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
$body = $this->parser->subparse([$this, 'decideIfFork']);
|
||||
$tests = [$expr, $body];
|
||||
$else = null;
|
||||
|
||||
$end = false;
|
||||
while (!$end) {
|
||||
switch ($stream->next()->getValue()) {
|
||||
case 'else':
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
$else = $this->parser->subparse([$this, 'decideIfEnd']);
|
||||
break;
|
||||
|
||||
case 'elseif':
|
||||
$expr = $this->parser->getExpressionParser()->parseExpression();
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
$body = $this->parser->subparse([$this, 'decideIfFork']);
|
||||
$tests[] = $expr;
|
||||
$tests[] = $body;
|
||||
break;
|
||||
|
||||
case 'endif':
|
||||
$end = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new SyntaxError(sprintf('Unexpected end of template. Twig was looking for the following tags "else", "elseif", or "endif" to close the "if" block started at line %d).', $lineno), $stream->getCurrent()->getLine(), $stream->getSourceContext());
|
||||
}
|
||||
}
|
||||
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
|
||||
return new IfNode(new Node($tests), $else, $lineno, $this->getTag());
|
||||
}
|
||||
|
||||
public function decideIfFork(Token $token)
|
||||
{
|
||||
return $token->test(['elseif', 'else', 'endif']);
|
||||
}
|
||||
|
||||
public function decideIfEnd(Token $token)
|
||||
{
|
||||
return $token->test(['endif']);
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'if';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig\TokenParser\IfTokenParser', 'Twig_TokenParser_If');
|
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Imports macros.
|
||||
*
|
||||
* <pre>
|
||||
* {% import 'forms.html' as forms %}
|
||||
* </pre>
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class Twig_TokenParser_Import extends Twig_TokenParser
|
||||
{
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$macro = $this->parser->getExpressionParser()->parseExpression();
|
||||
$this->parser->getStream()->expect('as');
|
||||
$var = new Twig_Node_Expression_AssignName($this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue(), $token->getLine());
|
||||
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
$this->parser->addImportedSymbol('template', $var->getAttribute('name'));
|
||||
|
||||
return new Twig_Node_Import($macro, $var, $token->getLine(), $this->getTag());
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'import';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_TokenParser_Import', 'Twig\TokenParser\ImportTokenParser', false);
|
45
system/libs/Twig/TokenParser/ImportTokenParser.php
Normal file
45
system/libs/Twig/TokenParser/ImportTokenParser.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Twig\TokenParser;
|
||||
|
||||
use Twig\Node\Expression\AssignNameExpression;
|
||||
use Twig\Node\ImportNode;
|
||||
use Twig\Token;
|
||||
|
||||
/**
|
||||
* Imports macros.
|
||||
*
|
||||
* {% import 'forms.html' as forms %}
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class ImportTokenParser extends AbstractTokenParser
|
||||
{
|
||||
public function parse(Token $token)
|
||||
{
|
||||
$macro = $this->parser->getExpressionParser()->parseExpression();
|
||||
$this->parser->getStream()->expect(Token::NAME_TYPE, 'as');
|
||||
$var = new AssignNameExpression($this->parser->getStream()->expect(Token::NAME_TYPE)->getValue(), $token->getLine());
|
||||
$this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
|
||||
|
||||
$this->parser->addImportedSymbol('template', $var->getAttribute('name'));
|
||||
|
||||
return new ImportNode($macro, $var, $token->getLine(), $this->getTag());
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'import';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig\TokenParser\ImportTokenParser', 'Twig_TokenParser_Import');
|
27
system/libs/Twig/TokenParser/Include.php → system/libs/Twig/TokenParser/IncludeTokenParser.php
Executable file → Normal file
27
system/libs/Twig/TokenParser/Include.php → system/libs/Twig/TokenParser/IncludeTokenParser.php
Executable file → Normal file
@@ -10,24 +10,27 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Twig\TokenParser;
|
||||
|
||||
use Twig\Node\IncludeNode;
|
||||
use Twig\Token;
|
||||
|
||||
/**
|
||||
* Includes a template.
|
||||
*
|
||||
* <pre>
|
||||
* {% include 'header.html' %}
|
||||
* Body
|
||||
* {% include 'footer.html' %}
|
||||
* </pre>
|
||||
*/
|
||||
class Twig_TokenParser_Include extends Twig_TokenParser
|
||||
class IncludeTokenParser extends AbstractTokenParser
|
||||
{
|
||||
public function parse(Twig_Token $token)
|
||||
public function parse(Token $token)
|
||||
{
|
||||
$expr = $this->parser->getExpressionParser()->parseExpression();
|
||||
|
||||
list($variables, $only, $ignoreMissing) = $this->parseArguments();
|
||||
|
||||
return new Twig_Node_Include($expr, $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag());
|
||||
return new IncludeNode($expr, $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag());
|
||||
}
|
||||
|
||||
protected function parseArguments()
|
||||
@@ -35,25 +38,25 @@ class Twig_TokenParser_Include extends Twig_TokenParser
|
||||
$stream = $this->parser->getStream();
|
||||
|
||||
$ignoreMissing = false;
|
||||
if ($stream->nextIf(Twig_Token::NAME_TYPE, 'ignore')) {
|
||||
$stream->expect(Twig_Token::NAME_TYPE, 'missing');
|
||||
if ($stream->nextIf(Token::NAME_TYPE, 'ignore')) {
|
||||
$stream->expect(Token::NAME_TYPE, 'missing');
|
||||
|
||||
$ignoreMissing = true;
|
||||
}
|
||||
|
||||
$variables = null;
|
||||
if ($stream->nextIf(Twig_Token::NAME_TYPE, 'with')) {
|
||||
if ($stream->nextIf(Token::NAME_TYPE, 'with')) {
|
||||
$variables = $this->parser->getExpressionParser()->parseExpression();
|
||||
}
|
||||
|
||||
$only = false;
|
||||
if ($stream->nextIf(Twig_Token::NAME_TYPE, 'only')) {
|
||||
if ($stream->nextIf(Token::NAME_TYPE, 'only')) {
|
||||
$only = true;
|
||||
}
|
||||
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
|
||||
return array($variables, $only, $ignoreMissing);
|
||||
return [$variables, $only, $ignoreMissing];
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
@@ -62,4 +65,4 @@ class Twig_TokenParser_Include extends Twig_TokenParser
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_TokenParser_Include', 'Twig\TokenParser\IncludeTokenParser', false);
|
||||
class_alias('Twig\TokenParser\IncludeTokenParser', 'Twig_TokenParser_Include');
|
@@ -1,60 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Defines a macro.
|
||||
*
|
||||
* <pre>
|
||||
* {% macro input(name, value, type, size) %}
|
||||
* <input type="{{ type|default('text') }}" name="{{ name }}" value="{{ value|e }}" size="{{ size|default(20) }}" />
|
||||
* {% endmacro %}
|
||||
* </pre>
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class Twig_TokenParser_Macro extends Twig_TokenParser
|
||||
{
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$lineno = $token->getLine();
|
||||
$stream = $this->parser->getStream();
|
||||
$name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
|
||||
|
||||
$arguments = $this->parser->getExpressionParser()->parseArguments(true, true);
|
||||
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
$this->parser->pushLocalScope();
|
||||
$body = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
|
||||
if ($token = $stream->nextIf(Twig_Token::NAME_TYPE)) {
|
||||
$value = $token->getValue();
|
||||
|
||||
if ($value != $name) {
|
||||
throw new Twig_Error_Syntax(sprintf('Expected endmacro for macro "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext());
|
||||
}
|
||||
}
|
||||
$this->parser->popLocalScope();
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
$this->parser->setMacro($name, new Twig_Node_Macro($name, new Twig_Node_Body(array($body)), $arguments, $lineno, $this->getTag()));
|
||||
}
|
||||
|
||||
public function decideBlockEnd(Twig_Token $token)
|
||||
{
|
||||
return $token->test('endmacro');
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'macro';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_TokenParser_Macro', 'Twig\TokenParser\MacroTokenParser', false);
|
68
system/libs/Twig/TokenParser/MacroTokenParser.php
Normal file
68
system/libs/Twig/TokenParser/MacroTokenParser.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Twig\TokenParser;
|
||||
|
||||
use Twig\Error\SyntaxError;
|
||||
use Twig\Node\BodyNode;
|
||||
use Twig\Node\MacroNode;
|
||||
use Twig\Node\Node;
|
||||
use Twig\Token;
|
||||
|
||||
/**
|
||||
* Defines a macro.
|
||||
*
|
||||
* {% macro input(name, value, type, size) %}
|
||||
* <input type="{{ type|default('text') }}" name="{{ name }}" value="{{ value|e }}" size="{{ size|default(20) }}" />
|
||||
* {% endmacro %}
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class MacroTokenParser extends AbstractTokenParser
|
||||
{
|
||||
public function parse(Token $token)
|
||||
{
|
||||
$lineno = $token->getLine();
|
||||
$stream = $this->parser->getStream();
|
||||
$name = $stream->expect(Token::NAME_TYPE)->getValue();
|
||||
|
||||
$arguments = $this->parser->getExpressionParser()->parseArguments(true, true);
|
||||
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
$this->parser->pushLocalScope();
|
||||
$body = $this->parser->subparse([$this, 'decideBlockEnd'], true);
|
||||
if ($token = $stream->nextIf(Token::NAME_TYPE)) {
|
||||
$value = $token->getValue();
|
||||
|
||||
if ($value != $name) {
|
||||
throw new SyntaxError(sprintf('Expected endmacro for macro "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext());
|
||||
}
|
||||
}
|
||||
$this->parser->popLocalScope();
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
|
||||
$this->parser->setMacro($name, new MacroNode($name, new BodyNode([$body]), $arguments, $lineno, $this->getTag()));
|
||||
|
||||
return new Node();
|
||||
}
|
||||
|
||||
public function decideBlockEnd(Token $token)
|
||||
{
|
||||
return $token->test('endmacro');
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'macro';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig\TokenParser\MacroTokenParser', 'Twig_TokenParser_Macro');
|
@@ -1,61 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Marks a section of a template as untrusted code that must be evaluated in the sandbox mode.
|
||||
*
|
||||
* <pre>
|
||||
* {% sandbox %}
|
||||
* {% include 'user.html' %}
|
||||
* {% endsandbox %}
|
||||
* </pre>
|
||||
*
|
||||
* @see http://www.twig-project.org/doc/api.html#sandbox-extension for details
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class Twig_TokenParser_Sandbox extends Twig_TokenParser
|
||||
{
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$stream = $this->parser->getStream();
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
$body = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
// in a sandbox tag, only include tags are allowed
|
||||
if (!$body instanceof Twig_Node_Include) {
|
||||
foreach ($body as $node) {
|
||||
if ($node instanceof Twig_Node_Text && ctype_space($node->getAttribute('data'))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$node instanceof Twig_Node_Include) {
|
||||
throw new Twig_Error_Syntax('Only "include" tags are allowed within a "sandbox" section.', $node->getTemplateLine(), $stream->getSourceContext());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new Twig_Node_Sandbox($body, $token->getLine(), $this->getTag());
|
||||
}
|
||||
|
||||
public function decideBlockEnd(Twig_Token $token)
|
||||
{
|
||||
return $token->test('endsandbox');
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'sandbox';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_TokenParser_Sandbox', 'Twig\TokenParser\SandboxTokenParser', false);
|
67
system/libs/Twig/TokenParser/SandboxTokenParser.php
Normal file
67
system/libs/Twig/TokenParser/SandboxTokenParser.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Twig\TokenParser;
|
||||
|
||||
use Twig\Error\SyntaxError;
|
||||
use Twig\Node\IncludeNode;
|
||||
use Twig\Node\SandboxNode;
|
||||
use Twig\Node\TextNode;
|
||||
use Twig\Token;
|
||||
|
||||
/**
|
||||
* Marks a section of a template as untrusted code that must be evaluated in the sandbox mode.
|
||||
*
|
||||
* {% sandbox %}
|
||||
* {% include 'user.html' %}
|
||||
* {% endsandbox %}
|
||||
*
|
||||
* @see https://twig.symfony.com/doc/api.html#sandbox-extension for details
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class SandboxTokenParser extends AbstractTokenParser
|
||||
{
|
||||
public function parse(Token $token)
|
||||
{
|
||||
$stream = $this->parser->getStream();
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
$body = $this->parser->subparse([$this, 'decideBlockEnd'], true);
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
|
||||
// in a sandbox tag, only include tags are allowed
|
||||
if (!$body instanceof IncludeNode) {
|
||||
foreach ($body as $node) {
|
||||
if ($node instanceof TextNode && ctype_space($node->getAttribute('data'))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$node instanceof IncludeNode) {
|
||||
throw new SyntaxError('Only "include" tags are allowed within a "sandbox" section.', $node->getTemplateLine(), $stream->getSourceContext());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new SandboxNode($body, $token->getLine(), $this->getTag());
|
||||
}
|
||||
|
||||
public function decideBlockEnd(Token $token)
|
||||
{
|
||||
return $token->test('endsandbox');
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'sandbox';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig\TokenParser\SandboxTokenParser', 'Twig_TokenParser_Sandbox');
|
@@ -1,75 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Defines a variable.
|
||||
*
|
||||
* <pre>
|
||||
* {% set foo = 'foo' %}
|
||||
*
|
||||
* {% set foo = [1, 2] %}
|
||||
*
|
||||
* {% set foo = {'foo': 'bar'} %}
|
||||
*
|
||||
* {% set foo = 'foo' ~ 'bar' %}
|
||||
*
|
||||
* {% set foo, bar = 'foo', 'bar' %}
|
||||
*
|
||||
* {% set foo %}Some content{% endset %}
|
||||
* </pre>
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class Twig_TokenParser_Set extends Twig_TokenParser
|
||||
{
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$lineno = $token->getLine();
|
||||
$stream = $this->parser->getStream();
|
||||
$names = $this->parser->getExpressionParser()->parseAssignmentExpression();
|
||||
|
||||
$capture = false;
|
||||
if ($stream->nextIf(Twig_Token::OPERATOR_TYPE, '=')) {
|
||||
$values = $this->parser->getExpressionParser()->parseMultitargetExpression();
|
||||
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
if (count($names) !== count($values)) {
|
||||
throw new Twig_Error_Syntax('When using set, you must have the same number of variables and assignments.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
|
||||
}
|
||||
} else {
|
||||
$capture = true;
|
||||
|
||||
if (count($names) > 1) {
|
||||
throw new Twig_Error_Syntax('When using set with a block, you cannot have a multi-target.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
|
||||
}
|
||||
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
$values = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
}
|
||||
|
||||
return new Twig_Node_Set($capture, $names, $values, $lineno, $this->getTag());
|
||||
}
|
||||
|
||||
public function decideBlockEnd(Twig_Token $token)
|
||||
{
|
||||
return $token->test('endset');
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'set';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_TokenParser_Set', 'Twig\TokenParser\SetTokenParser', false);
|
74
system/libs/Twig/TokenParser/SetTokenParser.php
Normal file
74
system/libs/Twig/TokenParser/SetTokenParser.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Twig\TokenParser;
|
||||
|
||||
use Twig\Error\SyntaxError;
|
||||
use Twig\Node\SetNode;
|
||||
use Twig\Token;
|
||||
|
||||
/**
|
||||
* Defines a variable.
|
||||
*
|
||||
* {% set foo = 'foo' %}
|
||||
* {% set foo = [1, 2] %}
|
||||
* {% set foo = {'foo': 'bar'} %}
|
||||
* {% set foo = 'foo' ~ 'bar' %}
|
||||
* {% set foo, bar = 'foo', 'bar' %}
|
||||
* {% set foo %}Some content{% endset %}
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class SetTokenParser extends AbstractTokenParser
|
||||
{
|
||||
public function parse(Token $token)
|
||||
{
|
||||
$lineno = $token->getLine();
|
||||
$stream = $this->parser->getStream();
|
||||
$names = $this->parser->getExpressionParser()->parseAssignmentExpression();
|
||||
|
||||
$capture = false;
|
||||
if ($stream->nextIf(Token::OPERATOR_TYPE, '=')) {
|
||||
$values = $this->parser->getExpressionParser()->parseMultitargetExpression();
|
||||
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
|
||||
if (\count($names) !== \count($values)) {
|
||||
throw new SyntaxError('When using set, you must have the same number of variables and assignments.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
|
||||
}
|
||||
} else {
|
||||
$capture = true;
|
||||
|
||||
if (\count($names) > 1) {
|
||||
throw new SyntaxError('When using set with a block, you cannot have a multi-target.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
|
||||
}
|
||||
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
|
||||
$values = $this->parser->subparse([$this, 'decideBlockEnd'], true);
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
}
|
||||
|
||||
return new SetNode($capture, $names, $values, $lineno, $this->getTag());
|
||||
}
|
||||
|
||||
public function decideBlockEnd(Token $token)
|
||||
{
|
||||
return $token->test('endset');
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'set';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig\TokenParser\SetTokenParser', 'Twig_TokenParser_Set');
|
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Remove whitespaces between HTML tags.
|
||||
*
|
||||
* <pre>
|
||||
* {% spaceless %}
|
||||
* <div>
|
||||
* <strong>foo</strong>
|
||||
* </div>
|
||||
* {% endspaceless %}
|
||||
*
|
||||
* {# output will be <div><strong>foo</strong></div> #}
|
||||
* </pre>
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class Twig_TokenParser_Spaceless extends Twig_TokenParser
|
||||
{
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$lineno = $token->getLine();
|
||||
|
||||
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
$body = $this->parser->subparse(array($this, 'decideSpacelessEnd'), true);
|
||||
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
return new Twig_Node_Spaceless($body, $lineno, $this->getTag());
|
||||
}
|
||||
|
||||
public function decideSpacelessEnd(Twig_Token $token)
|
||||
{
|
||||
return $token->test('endspaceless');
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'spaceless';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_TokenParser_Spaceless', 'Twig\TokenParser\SpacelessTokenParser', false);
|
53
system/libs/Twig/TokenParser/SpacelessTokenParser.php
Normal file
53
system/libs/Twig/TokenParser/SpacelessTokenParser.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Twig\TokenParser;
|
||||
|
||||
use Twig\Node\SpacelessNode;
|
||||
use Twig\Token;
|
||||
|
||||
/**
|
||||
* Remove whitespaces between HTML tags.
|
||||
*
|
||||
* {% spaceless %}
|
||||
* <div>
|
||||
* <strong>foo</strong>
|
||||
* </div>
|
||||
* {% endspaceless %}
|
||||
* {# output will be <div><strong>foo</strong></div> #}
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class SpacelessTokenParser extends AbstractTokenParser
|
||||
{
|
||||
public function parse(Token $token)
|
||||
{
|
||||
$lineno = $token->getLine();
|
||||
|
||||
$this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
|
||||
$body = $this->parser->subparse([$this, 'decideSpacelessEnd'], true);
|
||||
$this->parser->getStream()->expect(Token::BLOCK_END_TYPE);
|
||||
|
||||
return new SpacelessNode($body, $lineno, $this->getTag());
|
||||
}
|
||||
|
||||
public function decideSpacelessEnd(Token $token)
|
||||
{
|
||||
return $token->test('endspaceless');
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'spaceless';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig\TokenParser\SpacelessTokenParser', 'Twig_TokenParser_Spaceless');
|
51
system/libs/Twig/TokenParser/TokenParserInterface.php
Normal file
51
system/libs/Twig/TokenParser/TokenParserInterface.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Twig\TokenParser;
|
||||
|
||||
use Twig\Error\SyntaxError;
|
||||
use Twig\Parser;
|
||||
use Twig\Token;
|
||||
|
||||
/**
|
||||
* Interface implemented by token parsers.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
interface TokenParserInterface
|
||||
{
|
||||
/**
|
||||
* Sets the parser associated with this token parser.
|
||||
*/
|
||||
public function setParser(Parser $parser);
|
||||
|
||||
/**
|
||||
* Parses a token and returns a node.
|
||||
*
|
||||
* @return \Twig_NodeInterface
|
||||
*
|
||||
* @throws SyntaxError
|
||||
*/
|
||||
public function parse(Token $token);
|
||||
|
||||
/**
|
||||
* Gets the tag name associated with this token parser.
|
||||
*
|
||||
* @return string The tag name
|
||||
*/
|
||||
public function getTag();
|
||||
}
|
||||
|
||||
class_alias('Twig\TokenParser\TokenParserInterface', 'Twig_TokenParserInterface');
|
||||
|
||||
// Ensure that the aliased name is loaded to keep BC for classes implementing the typehint with the old aliased name.
|
||||
class_exists('Twig\Token');
|
||||
class_exists('Twig\Parser');
|
@@ -1,70 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Imports blocks defined in another template into the current template.
|
||||
*
|
||||
* <pre>
|
||||
* {% extends "base.html" %}
|
||||
*
|
||||
* {% use "blocks.html" %}
|
||||
*
|
||||
* {% block title %}{% endblock %}
|
||||
* {% block content %}{% endblock %}
|
||||
* </pre>
|
||||
*
|
||||
* @see http://www.twig-project.org/doc/templates.html#horizontal-reuse for details.
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class Twig_TokenParser_Use extends Twig_TokenParser
|
||||
{
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$template = $this->parser->getExpressionParser()->parseExpression();
|
||||
$stream = $this->parser->getStream();
|
||||
|
||||
if (!$template instanceof Twig_Node_Expression_Constant) {
|
||||
throw new Twig_Error_Syntax('The template references in a "use" statement must be a string.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
|
||||
}
|
||||
|
||||
$targets = array();
|
||||
if ($stream->nextIf('with')) {
|
||||
do {
|
||||
$name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
|
||||
|
||||
$alias = $name;
|
||||
if ($stream->nextIf('as')) {
|
||||
$alias = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
|
||||
}
|
||||
|
||||
$targets[$name] = new Twig_Node_Expression_Constant($alias, -1);
|
||||
|
||||
if (!$stream->nextIf(Twig_Token::PUNCTUATION_TYPE, ',')) {
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
}
|
||||
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
$this->parser->addTrait(new Twig_Node(array('template' => $template, 'targets' => new Twig_Node($targets))));
|
||||
|
||||
return new Twig_Node();
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'use';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_TokenParser_Use', 'Twig\TokenParser\UseTokenParser', false);
|
75
system/libs/Twig/TokenParser/UseTokenParser.php
Normal file
75
system/libs/Twig/TokenParser/UseTokenParser.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Twig\TokenParser;
|
||||
|
||||
use Twig\Error\SyntaxError;
|
||||
use Twig\Node\Expression\ConstantExpression;
|
||||
use Twig\Node\Node;
|
||||
use Twig\Token;
|
||||
|
||||
/**
|
||||
* Imports blocks defined in another template into the current template.
|
||||
*
|
||||
* {% extends "base.html" %}
|
||||
*
|
||||
* {% use "blocks.html" %}
|
||||
*
|
||||
* {% block title %}{% endblock %}
|
||||
* {% block content %}{% endblock %}
|
||||
*
|
||||
* @see https://twig.symfony.com/doc/templates.html#horizontal-reuse for details.
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class UseTokenParser extends AbstractTokenParser
|
||||
{
|
||||
public function parse(Token $token)
|
||||
{
|
||||
$template = $this->parser->getExpressionParser()->parseExpression();
|
||||
$stream = $this->parser->getStream();
|
||||
|
||||
if (!$template instanceof ConstantExpression) {
|
||||
throw new SyntaxError('The template references in a "use" statement must be a string.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
|
||||
}
|
||||
|
||||
$targets = [];
|
||||
if ($stream->nextIf('with')) {
|
||||
do {
|
||||
$name = $stream->expect(Token::NAME_TYPE)->getValue();
|
||||
|
||||
$alias = $name;
|
||||
if ($stream->nextIf('as')) {
|
||||
$alias = $stream->expect(Token::NAME_TYPE)->getValue();
|
||||
}
|
||||
|
||||
$targets[$name] = new ConstantExpression($alias, -1);
|
||||
|
||||
if (!$stream->nextIf(Token::PUNCTUATION_TYPE, ',')) {
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
}
|
||||
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
|
||||
$this->parser->addTrait(new Node(['template' => $template, 'targets' => new Node($targets)]));
|
||||
|
||||
return new Node();
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'use';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig\TokenParser\UseTokenParser', 'Twig_TokenParser_Use');
|
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creates a nested scope.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class Twig_TokenParser_With extends Twig_TokenParser
|
||||
{
|
||||
public function parse(Twig_Token $token)
|
||||
{
|
||||
$stream = $this->parser->getStream();
|
||||
|
||||
$variables = null;
|
||||
$only = false;
|
||||
if (!$stream->test(Twig_Token::BLOCK_END_TYPE)) {
|
||||
$variables = $this->parser->getExpressionParser()->parseExpression();
|
||||
$only = $stream->nextIf(Twig_Token::NAME_TYPE, 'only');
|
||||
}
|
||||
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
$body = $this->parser->subparse(array($this, 'decideWithEnd'), true);
|
||||
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
return new Twig_Node_With($body, $variables, $only, $token->getLine(), $this->getTag());
|
||||
}
|
||||
|
||||
public function decideWithEnd(Twig_Token $token)
|
||||
{
|
||||
return $token->test('endwith');
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'with';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_TokenParser_With', 'Twig\TokenParser\WithTokenParser', false);
|
57
system/libs/Twig/TokenParser/WithTokenParser.php
Normal file
57
system/libs/Twig/TokenParser/WithTokenParser.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Twig\TokenParser;
|
||||
|
||||
use Twig\Node\WithNode;
|
||||
use Twig\Token;
|
||||
|
||||
/**
|
||||
* Creates a nested scope.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class WithTokenParser extends AbstractTokenParser
|
||||
{
|
||||
public function parse(Token $token)
|
||||
{
|
||||
$stream = $this->parser->getStream();
|
||||
|
||||
$variables = null;
|
||||
$only = false;
|
||||
if (!$stream->test(Token::BLOCK_END_TYPE)) {
|
||||
$variables = $this->parser->getExpressionParser()->parseExpression();
|
||||
$only = $stream->nextIf(Token::NAME_TYPE, 'only');
|
||||
}
|
||||
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
|
||||
$body = $this->parser->subparse([$this, 'decideWithEnd'], true);
|
||||
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
|
||||
return new WithNode($body, $variables, $only, $token->getLine(), $this->getTag());
|
||||
}
|
||||
|
||||
public function decideWithEnd(Token $token)
|
||||
{
|
||||
return $token->test('endwith');
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'with';
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig\TokenParser\WithTokenParser', 'Twig_TokenParser_With');
|
Reference in New Issue
Block a user