mirror of
https://github.com/slawkens/myaac.git
synced 2025-10-18 03:33:26 +02:00
* updated Twig to the latest version in 1.x series (v1.35.0)
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2010 Fabien Potencier
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -17,6 +17,8 @@
|
||||
* You can configure which optimizations you want to activate via the
|
||||
* optimizer mode.
|
||||
*
|
||||
* @final
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class Twig_NodeVisitor_Optimizer extends Twig_BaseNodeVisitor
|
||||
@@ -34,8 +36,6 @@ class Twig_NodeVisitor_Optimizer extends Twig_BaseNodeVisitor
|
||||
protected $inABody = false;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param int $optimizers The optimizer mode
|
||||
*/
|
||||
public function __construct($optimizers = -1)
|
||||
@@ -47,16 +47,13 @@ class Twig_NodeVisitor_Optimizer extends Twig_BaseNodeVisitor
|
||||
$this->optimizers = $optimizers;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doEnterNode(Twig_Node $node, Twig_Environment $env)
|
||||
{
|
||||
if (self::OPTIMIZE_FOR === (self::OPTIMIZE_FOR & $this->optimizers)) {
|
||||
$this->enterOptimizeFor($node, $env);
|
||||
}
|
||||
|
||||
if (PHP_VERSION_ID < 50400 && self::OPTIMIZE_VAR_ACCESS === (self::OPTIMIZE_VAR_ACCESS & $this->optimizers) && !$env->isStrictVariables() && !$env->hasExtension('sandbox')) {
|
||||
if (PHP_VERSION_ID < 50400 && self::OPTIMIZE_VAR_ACCESS === (self::OPTIMIZE_VAR_ACCESS & $this->optimizers) && !$env->isStrictVariables() && !$env->hasExtension('Twig_Extension_Sandbox')) {
|
||||
if ($this->inABody) {
|
||||
if (!$node instanceof Twig_Node_Expression) {
|
||||
if (get_class($node) !== 'Twig_Node') {
|
||||
@@ -73,9 +70,6 @@ class Twig_NodeVisitor_Optimizer extends Twig_BaseNodeVisitor
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doLeaveNode(Twig_Node $node, Twig_Environment $env)
|
||||
{
|
||||
$expression = $node instanceof Twig_Node_Expression;
|
||||
@@ -90,14 +84,14 @@ class Twig_NodeVisitor_Optimizer extends Twig_BaseNodeVisitor
|
||||
|
||||
$node = $this->optimizePrintNode($node, $env);
|
||||
|
||||
if (self::OPTIMIZE_VAR_ACCESS === (self::OPTIMIZE_VAR_ACCESS & $this->optimizers) && !$env->isStrictVariables() && !$env->hasExtension('sandbox')) {
|
||||
if (self::OPTIMIZE_VAR_ACCESS === (self::OPTIMIZE_VAR_ACCESS & $this->optimizers) && !$env->isStrictVariables() && !$env->hasExtension('Twig_Extension_Sandbox')) {
|
||||
if ($node instanceof Twig_Node_Body) {
|
||||
$this->inABody = false;
|
||||
} elseif ($this->inABody) {
|
||||
if (!$expression && get_class($node) !== 'Twig_Node' && $prependedNodes = array_shift($this->prependedNodes)) {
|
||||
$nodes = array();
|
||||
foreach (array_unique($prependedNodes) as $name) {
|
||||
$nodes[] = new Twig_Node_SetTemp($name, $node->getLine());
|
||||
$nodes[] = new Twig_Node_SetTemp($name, $node->getTemplateLine());
|
||||
}
|
||||
|
||||
$nodes[] = $node;
|
||||
@@ -114,7 +108,7 @@ class Twig_NodeVisitor_Optimizer extends Twig_BaseNodeVisitor
|
||||
if ('Twig_Node_Expression_Name' === get_class($node) && $node->isSimple()) {
|
||||
$this->prependedNodes[0][] = $node->getAttribute('name');
|
||||
|
||||
return new Twig_Node_Expression_TempName($node->getAttribute('name'), $node->getLine());
|
||||
return new Twig_Node_Expression_TempName($node->getAttribute('name'), $node->getTemplateLine());
|
||||
}
|
||||
|
||||
return $node;
|
||||
@@ -127,9 +121,6 @@ class Twig_NodeVisitor_Optimizer extends Twig_BaseNodeVisitor
|
||||
*
|
||||
* * "echo $this->render(Parent)Block()" with "$this->display(Parent)Block()"
|
||||
*
|
||||
* @param Twig_NodeInterface $node A Node
|
||||
* @param Twig_Environment $env The current Twig environment
|
||||
*
|
||||
* @return Twig_NodeInterface
|
||||
*/
|
||||
protected function optimizePrintNode(Twig_NodeInterface $node, Twig_Environment $env)
|
||||
@@ -138,13 +129,14 @@ class Twig_NodeVisitor_Optimizer extends Twig_BaseNodeVisitor
|
||||
return $node;
|
||||
}
|
||||
|
||||
$exprNode = $node->getNode('expr');
|
||||
if (
|
||||
$node->getNode('expr') instanceof Twig_Node_Expression_BlockReference ||
|
||||
$node->getNode('expr') instanceof Twig_Node_Expression_Parent
|
||||
$exprNode instanceof Twig_Node_Expression_BlockReference ||
|
||||
$exprNode instanceof Twig_Node_Expression_Parent
|
||||
) {
|
||||
$node->getNode('expr')->setAttribute('output', true);
|
||||
$exprNode->setAttribute('output', true);
|
||||
|
||||
return $node->getNode('expr');
|
||||
return $exprNode;
|
||||
}
|
||||
|
||||
return $node;
|
||||
@@ -153,9 +145,6 @@ class Twig_NodeVisitor_Optimizer extends Twig_BaseNodeVisitor
|
||||
/**
|
||||
* Removes "raw" filters.
|
||||
*
|
||||
* @param Twig_NodeInterface $node A Node
|
||||
* @param Twig_Environment $env The current Twig environment
|
||||
*
|
||||
* @return Twig_NodeInterface
|
||||
*/
|
||||
protected function optimizeRawFilter(Twig_NodeInterface $node, Twig_Environment $env)
|
||||
@@ -169,9 +158,6 @@ class Twig_NodeVisitor_Optimizer extends Twig_BaseNodeVisitor
|
||||
|
||||
/**
|
||||
* Optimizes "for" tag by removing the "loop" variable creation whenever possible.
|
||||
*
|
||||
* @param Twig_NodeInterface $node A Node
|
||||
* @param Twig_Environment $env The current Twig environment
|
||||
*/
|
||||
protected function enterOptimizeFor(Twig_NodeInterface $node, Twig_Environment $env)
|
||||
{
|
||||
@@ -236,9 +222,6 @@ class Twig_NodeVisitor_Optimizer extends Twig_BaseNodeVisitor
|
||||
|
||||
/**
|
||||
* Optimizes "for" tag by removing the "loop" variable creation whenever possible.
|
||||
*
|
||||
* @param Twig_NodeInterface $node A Node
|
||||
* @param Twig_Environment $env The current Twig environment
|
||||
*/
|
||||
protected function leaveOptimizeFor(Twig_NodeInterface $node, Twig_Environment $env)
|
||||
{
|
||||
@@ -261,11 +244,10 @@ class Twig_NodeVisitor_Optimizer extends Twig_BaseNodeVisitor
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPriority()
|
||||
{
|
||||
return 255;
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_NodeVisitor_Optimizer', 'Twig\NodeVisitor\OptimizerNodeVisitor', false);
|
||||
|
Reference in New Issue
Block a user