Update Twig. This closes #295

This commit is contained in:
Fredrick Brennan
2018-05-10 18:24:53 +08:00
parent b078ffb1e4
commit 0aa4e3badc
200 changed files with 6150 additions and 2626 deletions

View File

@@ -1,6 +1,18 @@
<?php
class Twig_NodeVisitor_SafeAnalysis implements Twig_NodeVisitorInterface
/*
* 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.
*/
/**
* @final
*/
class Twig_NodeVisitor_SafeAnalysis extends Twig_BaseNodeVisitor
{
protected $data = array();
protected $safeVars = array();
@@ -13,12 +25,20 @@ class Twig_NodeVisitor_SafeAnalysis implements Twig_NodeVisitorInterface
public function getSafe(Twig_NodeInterface $node)
{
$hash = spl_object_hash($node);
if (isset($this->data[$hash])) {
foreach ($this->data[$hash] as $bucket) {
if ($bucket['key'] === $node) {
return $bucket['value'];
}
if (!isset($this->data[$hash])) {
return;
}
foreach ($this->data[$hash] as $bucket) {
if ($bucket['key'] !== $node) {
continue;
}
if (in_array('html_attr', $bucket['value'])) {
$bucket['value'][] = 'html';
}
return $bucket['value'];
}
}
@@ -40,12 +60,12 @@ class Twig_NodeVisitor_SafeAnalysis implements Twig_NodeVisitorInterface
);
}
public function enterNode(Twig_NodeInterface $node, Twig_Environment $env)
protected function doEnterNode(Twig_Node $node, Twig_Environment $env)
{
return $node;
}
public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env)
protected function doLeaveNode(Twig_Node $node, Twig_Environment $env)
{
if ($node instanceof Twig_Node_Expression_Constant) {
// constants are marked safe for all
@@ -89,8 +109,6 @@ class Twig_NodeVisitor_SafeAnalysis implements Twig_NodeVisitorInterface
} else {
$this->setSafe($node, array());
}
} elseif ($node instanceof Twig_Node_Expression_MacroCall) {
$this->setSafe($node, array('all'));
} elseif ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name) {
$name = $node->getNode('node')->getAttribute('name');
// attributes on template instances are safe
@@ -123,11 +141,10 @@ class Twig_NodeVisitor_SafeAnalysis implements Twig_NodeVisitorInterface
return array_intersect($a, $b);
}
/**
* {@inheritdoc}
*/
public function getPriority()
{
return 0;
}
}
class_alias('Twig_NodeVisitor_SafeAnalysis', 'Twig\NodeVisitor\SafeAnalysisNodeVisitor', false);