Remove deprecated/obsolete features

This commit is contained in:
Fabien Potencier
2024-10-22 12:20:57 +02:00
parent 3c51c13a95
commit 99a85a7b5e
5 changed files with 2 additions and 87 deletions
-21
View File
@@ -1259,27 +1259,6 @@ final class CoreExtension extends AbstractExtension
return mb_strtoupper(mb_substr($string ?? '', 0, 1, $charset), $charset).mb_strtolower(mb_substr($string ?? '', 1, null, $charset), $charset);
}
/**
* @internal
*
* to be removed in 4.0
*/
public static function callMacro(Template $template, string $method, array $args, int $lineno, array $context, Source $source)
{
if (!method_exists($template, $method)) {
$parent = $template;
while ($parent = $parent->getParent($context)) {
if (method_exists($parent, $method)) {
return $parent->$method(...$args);
}
}
throw new RuntimeError(\sprintf('Macro "%s" is not defined in template "%s".', substr($method, \strlen('macro_')), $template->getTemplateName()), $lineno, $source);
}
return $template->$method(...$args);
}
/**
* @template TSequence
*
@@ -1,54 +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.
*/
namespace Twig\Node\Expression;
use Twig\Compiler;
class MethodCallExpression extends AbstractExpression
{
public function __construct(AbstractExpression $node, string $method, ArrayExpression $arguments, int $lineno)
{
trigger_deprecation('twig/twig', '3.15', 'The "%s" class is deprecated, use "%s" instead.', __CLASS__, MacroReferenceExpression::class);
parent::__construct(['node' => $node, 'arguments' => $arguments], ['method' => $method, 'safe' => false, 'is_defined_test' => false], $lineno);
if ($node instanceof NameExpression) {
$node->setAttribute('always_defined', true);
}
}
public function compile(Compiler $compiler): void
{
if ($this->getAttribute('is_defined_test')) {
$compiler
->raw('method_exists($macros[')
->repr($this->getNode('node')->getAttribute('name'))
->raw('], ')
->repr($this->getAttribute('method'))
->raw(')')
;
return;
}
$compiler
->raw('CoreExtension::callMacro($macros[')
->repr($this->getNode('node')->getAttribute('name'))
->raw('], ')
->repr($this->getAttribute('method'))
->raw(', ')
->subcompile($this->getNode('arguments'))
->raw(', ')
->repr($this->getTemplateLine())
->raw(', $context, $this->getSourceContext())');
}
}
-3
View File
@@ -21,7 +21,6 @@ use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Expression\FunctionExpression;
use Twig\Node\Expression\GetAttrExpression;
use Twig\Node\Expression\MacroReferenceExpression;
use Twig\Node\Expression\MethodCallExpression;
use Twig\Node\Expression\NameExpression;
use Twig\Node\Expression\TestExpression;
use Twig\Node\Node;
@@ -55,8 +54,6 @@ class DefinedTest extends TestExpression
$node->setAttribute('is_defined_test', true);
} elseif ($node instanceof ConstantExpression || $node instanceof ArrayExpression) {
$node = new ConstantExpression(true, $node->getTemplateLine());
} elseif ($node instanceof MethodCallExpression) {
$node->setAttribute('is_defined_test', true);
} else {
throw new SyntaxError('The "defined" test only works with simple variables.', $lineno);
}
+1 -2
View File
@@ -19,7 +19,6 @@ use Twig\Node\Expression\FilterExpression;
use Twig\Node\Expression\FunctionExpression;
use Twig\Node\Expression\GetAttrExpression;
use Twig\Node\Expression\MacroReferenceExpression;
use Twig\Node\Expression\MethodCallExpression;
use Twig\Node\Expression\NameExpression;
use Twig\Node\Expression\ParentExpression;
use Twig\Node\Node;
@@ -113,7 +112,7 @@ final class SafeAnalysisNodeVisitor implements NodeVisitorInterface
} else {
$this->setSafe($node, []);
}
} elseif ($node instanceof MethodCallExpression || $node instanceof MacroReferenceExpression) {
} elseif ($node instanceof MacroReferenceExpression) {
// all macro calls are safe
$this->setSafe($node, ['all']);
} elseif ($node instanceof GetAttrExpression && $node->getNode('node') instanceof NameExpression) {
+1 -7
View File
@@ -273,14 +273,8 @@ class Parser
$this->embeddedTemplates[] = $template;
}
public function addImportedSymbol(string $type, string $alias, ?string $name = null, AbstractExpression|string|null $internalRef = null): void
public function addImportedSymbol(string $type, string $alias, ?string $name = null, string|null $internalRef = null): void
{
if ($internalRef instanceof AbstractExpression) {
trigger_deprecation('twig/twig', '3.15', 'Passing a non-string internal reference name to "%s" is deprecated ("%s" given).', __METHOD__, $internalRef::class);
$internalRef = $internalRef->getAttribute('name');
}
$this->importedSymbols[0][$type][$alias] = ['name' => $name, 'node' => $internalRef];
}