mirror of
https://github.com/slawkens/myaac.git
synced 2025-10-17 19:23:27 +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) 2009 Fabien Potencier
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -12,6 +12,8 @@
|
||||
/**
|
||||
* Twig_NodeVisitor_Escaper implements output escaping.
|
||||
*
|
||||
* @final
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class Twig_NodeVisitor_Escaper extends Twig_BaseNodeVisitor
|
||||
@@ -28,16 +30,14 @@ class Twig_NodeVisitor_Escaper extends Twig_BaseNodeVisitor
|
||||
$this->safeAnalysis = new Twig_NodeVisitor_SafeAnalysis();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doEnterNode(Twig_Node $node, Twig_Environment $env)
|
||||
{
|
||||
if ($node instanceof Twig_Node_Module) {
|
||||
if ($env->hasExtension('escaper') && $defaultStrategy = $env->getExtension('escaper')->getDefaultStrategy($node->getAttribute('filename'))) {
|
||||
if ($env->hasExtension('Twig_Extension_Escaper') && $defaultStrategy = $env->getExtension('Twig_Extension_Escaper')->getDefaultStrategy($node->getTemplateName())) {
|
||||
$this->defaultStrategy = $defaultStrategy;
|
||||
}
|
||||
$this->safeVars = array();
|
||||
$this->blocks = array();
|
||||
} elseif ($node instanceof Twig_Node_AutoEscape) {
|
||||
$this->statusStack[] = $node->getAttribute('value');
|
||||
} elseif ($node instanceof Twig_Node_Block) {
|
||||
@@ -49,14 +49,12 @@ class Twig_NodeVisitor_Escaper extends Twig_BaseNodeVisitor
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doLeaveNode(Twig_Node $node, Twig_Environment $env)
|
||||
{
|
||||
if ($node instanceof Twig_Node_Module) {
|
||||
$this->defaultStrategy = false;
|
||||
$this->safeVars = array();
|
||||
$this->blocks = array();
|
||||
} elseif ($node instanceof Twig_Node_Expression_Filter) {
|
||||
return $this->preEscapeFilterNode($node, $env);
|
||||
} elseif ($node instanceof Twig_Node_Print) {
|
||||
@@ -88,7 +86,7 @@ class Twig_NodeVisitor_Escaper extends Twig_BaseNodeVisitor
|
||||
|
||||
return new $class(
|
||||
$this->getEscaperFilter($type, $expression),
|
||||
$node->getLine()
|
||||
$node->getTemplateLine()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -140,18 +138,17 @@ class Twig_NodeVisitor_Escaper extends Twig_BaseNodeVisitor
|
||||
|
||||
protected function getEscaperFilter($type, Twig_NodeInterface $node)
|
||||
{
|
||||
$line = $node->getLine();
|
||||
$line = $node->getTemplateLine();
|
||||
$name = new Twig_Node_Expression_Constant('escape', $line);
|
||||
$args = new Twig_Node(array(new Twig_Node_Expression_Constant((string) $type, $line), new Twig_Node_Expression_Constant(null, $line), new Twig_Node_Expression_Constant(true, $line)));
|
||||
|
||||
return new Twig_Node_Expression_Filter($node, $name, $args, $line);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPriority()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_NodeVisitor_Escaper', 'Twig\NodeVisitor\EscaperNodeVisitor', false);
|
||||
|
@@ -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);
|
||||
|
@@ -9,6 +9,9 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @final
|
||||
*/
|
||||
class Twig_NodeVisitor_SafeAnalysis extends Twig_BaseNodeVisitor
|
||||
{
|
||||
protected $data = array();
|
||||
@@ -57,17 +60,11 @@ class Twig_NodeVisitor_SafeAnalysis extends Twig_BaseNodeVisitor
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doEnterNode(Twig_Node $node, Twig_Environment $env)
|
||||
{
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doLeaveNode(Twig_Node $node, Twig_Environment $env)
|
||||
{
|
||||
if ($node instanceof Twig_Node_Expression_Constant) {
|
||||
@@ -144,11 +141,10 @@ class Twig_NodeVisitor_SafeAnalysis extends Twig_BaseNodeVisitor
|
||||
return array_intersect($a, $b);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPriority()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_NodeVisitor_SafeAnalysis', 'Twig\NodeVisitor\SafeAnalysisNodeVisitor', false);
|
||||
|
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -12,6 +12,8 @@
|
||||
/**
|
||||
* Twig_NodeVisitor_Sandbox implements sandboxing.
|
||||
*
|
||||
* @final
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class Twig_NodeVisitor_Sandbox extends Twig_BaseNodeVisitor
|
||||
@@ -21,9 +23,6 @@ class Twig_NodeVisitor_Sandbox extends Twig_BaseNodeVisitor
|
||||
protected $filters;
|
||||
protected $functions;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doEnterNode(Twig_Node $node, Twig_Environment $env)
|
||||
{
|
||||
if ($node instanceof Twig_Node_Module) {
|
||||
@@ -51,16 +50,13 @@ class Twig_NodeVisitor_Sandbox extends Twig_BaseNodeVisitor
|
||||
|
||||
// wrap print to check __toString() calls
|
||||
if ($node instanceof Twig_Node_Print) {
|
||||
return new Twig_Node_SandboxedPrint($node->getNode('expr'), $node->getLine(), $node->getNodeTag());
|
||||
return new Twig_Node_SandboxedPrint($node->getNode('expr'), $node->getTemplateLine(), $node->getNodeTag());
|
||||
}
|
||||
}
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doLeaveNode(Twig_Node $node, Twig_Environment $env)
|
||||
{
|
||||
if ($node instanceof Twig_Node_Module) {
|
||||
@@ -72,11 +68,10 @@ class Twig_NodeVisitor_Sandbox extends Twig_BaseNodeVisitor
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPriority()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
class_alias('Twig_NodeVisitor_Sandbox', 'Twig\NodeVisitor\SandboxNodeVisitor', false);
|
||||
|
Reference in New Issue
Block a user