mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-27 10:27:26 +00:00
Simplify code
This commit is contained in:
@@ -532,11 +532,7 @@ class ExpressionParser
|
||||
public function getFunctionNode($name, $line)
|
||||
{
|
||||
if (null !== $alias = $this->parser->getImportedSymbol('function', $name)) {
|
||||
$arguments = $this->createArguments($line);
|
||||
$node = new MacroReferenceExpression(new TemplateVariable($alias['node'], $line), $alias['name'], $arguments, $line);
|
||||
$node->setAttribute('safe', true);
|
||||
|
||||
return $node;
|
||||
return new MacroReferenceExpression(new TemplateVariable($alias['node'], $line), $alias['name'], $this->createArguments($line), $line);
|
||||
}
|
||||
|
||||
$args = $this->parseOnlyArguments();
|
||||
@@ -758,7 +754,6 @@ class ExpressionParser
|
||||
|
||||
if ('defined' === $test->getName() && $node instanceof NameExpression && null !== $alias = $this->parser->getImportedSymbol('function', $node->getAttribute('name'))) {
|
||||
$node = new MacroReferenceExpression(new TemplateVariable($alias['node'], $node->getTemplateLine()), $alias['name'], new ArrayExpression([], $node->getTemplateLine()), $node->getTemplateLine());
|
||||
$node->setAttribute('safe', true);
|
||||
}
|
||||
|
||||
$ready = $test instanceof TwigTest;
|
||||
@@ -970,11 +965,7 @@ class ExpressionParser
|
||||
'_self' === $node->getAttribute('name') && $attribute instanceof ConstantExpression
|
||||
)
|
||||
) {
|
||||
$name = $attribute->getAttribute('value');
|
||||
$node = new MacroReferenceExpression(new TemplateVariable($node->getAttribute('name'), $node->getTemplateLine()), 'macro_'.$name, $arguments, $node->getTemplateLine());
|
||||
$node->setAttribute('safe', true);
|
||||
|
||||
return $node;
|
||||
return new MacroReferenceExpression(new TemplateVariable($node->getAttribute('name'), $node->getTemplateLine()), 'macro_'.$attribute->getAttribute('value'), $arguments, $node->getTemplateLine());
|
||||
}
|
||||
|
||||
return new GetAttrExpression($node, $attribute, $arguments, $type, $lineno);
|
||||
|
||||
@@ -1285,6 +1285,8 @@ final class CoreExtension extends AbstractExtension
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* to be removed in 4.0
|
||||
*/
|
||||
public static function callMacro(Template $template, string $method, array $args, int $lineno, array $context, Source $source)
|
||||
{
|
||||
|
||||
@@ -128,11 +128,8 @@ final class SafeAnalysisNodeVisitor implements NodeVisitorInterface
|
||||
$this->setSafe($node, []);
|
||||
}
|
||||
} elseif ($node instanceof MethodCallExpression || $node instanceof MacroReferenceExpression) {
|
||||
if ($node->getAttribute('safe')) {
|
||||
$this->setSafe($node, ['all']);
|
||||
} else {
|
||||
$this->setSafe($node, []);
|
||||
}
|
||||
// all macro calls are safe
|
||||
$this->setSafe($node, ['all']);
|
||||
} elseif ($node instanceof GetAttrExpression && $node->getNode('node') instanceof NameExpression) {
|
||||
$name = $node->getNode('node')->getAttribute('name');
|
||||
if (\in_array($name, $this->safeVars)) {
|
||||
|
||||
@@ -16,13 +16,11 @@ use Twig\Node\BodyNode;
|
||||
use Twig\Node\EmptyNode;
|
||||
use Twig\Node\Expression\ArrayExpression;
|
||||
use Twig\Node\Expression\ConstantExpression;
|
||||
use Twig\Node\Expression\NameExpression;
|
||||
use Twig\Node\Expression\TempNameExpression;
|
||||
use Twig\Node\Expression\Unary\NegUnary;
|
||||
use Twig\Node\Expression\Unary\PosUnary;
|
||||
use Twig\Node\MacroNode;
|
||||
use Twig\Node\Node;
|
||||
use Twig\Node\Nodes;
|
||||
use Twig\Token;
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,7 +19,6 @@ use Twig\Node\Expression\ConstantExpression;
|
||||
use Twig\Node\Expression\NameExpression;
|
||||
use Twig\Node\Expression\TempNameExpression;
|
||||
use Twig\Node\MacroNode;
|
||||
use Twig\Node\Nodes;
|
||||
use Twig\Node\TextNode;
|
||||
use Twig\Test\NodeTestCase;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user