Remove the inert FirstClassTwigCallableReady attribute from the built-in nodes

This commit is contained in:
Fabien Potencier
2026-09-25 23:52:28 +02:00
parent bb0dbfc229
commit 69a4e43f0a
9 changed files with 5 additions and 14 deletions
+1
View File
@@ -4,6 +4,7 @@
* Remove support for calling `TemplateWrapper::unwrap()` without an environment argument
* Stop detecting `echo` and `print` in compiled nodes; `yield` is the only supported mode and 3.x deprecates the alternative
* Remove the now inert `#[YieldReady]` attribute from the built-in nodes; the attribute itself is kept so 3.x extensions still load
* Remove the now inert `#[FirstClassTwigCallableReady]` attribute from the built-in nodes; the attribute itself is kept so 3.x extensions still load
* Add an optional `string $template = ''` argument to `IncludeNode::addGetTemplate()`; subclasses overriding this method must declare a compatible parameter
* Remove the obsolete `Twig\Test\NodeTestCase::getTests()` method; override `provideTests()` instead
* Make `Twig\Markup` final
@@ -13,6 +13,10 @@ namespace Twig\Attribute;
/**
* Marks nodes that are ready to accept a TwigCallable instead of its name.
*
* Starting from Twig v4, all nodes must accept a TwigCallable, so this
* attribute doesn't lead to any specific behavior. It still exists to help
* projects move from Twig v3 to v4.
*/
#[\Attribute(\Attribute::TARGET_METHOD)]
final class FirstClassTwigCallableReady
@@ -11,7 +11,6 @@
namespace Twig\Node\Expression\Filter;
use Twig\Attribute\FirstClassTwigCallableReady;
use Twig\Compiler;
use Twig\Node\EmptyNode;
use Twig\Node\Expression\AbstractExpression;
@@ -34,7 +33,6 @@ use Twig\TwigTest;
*/
class DefaultFilter extends FilterExpression
{
#[FirstClassTwigCallableReady]
public function __construct(AbstractExpression $node, TwigFilter $filter, Node $arguments, int $lineno)
{
$name = $filter->getName();
@@ -11,7 +11,6 @@
namespace Twig\Node\Expression\Filter;
use Twig\Attribute\FirstClassTwigCallableReady;
use Twig\Compiler;
use Twig\Node\Expression\AbstractExpression;
use Twig\Node\Expression\FilterExpression;
@@ -25,7 +24,6 @@ use Twig\TwigFilter;
*/
final class EscapeFilter extends FilterExpression
{
#[FirstClassTwigCallableReady]
public function __construct(AbstractExpression $node, TwigFilter $filter, Node $arguments, int $lineno)
{
parent::__construct($node, $filter, $arguments, $lineno);
-2
View File
@@ -11,7 +11,6 @@
namespace Twig\Node\Expression\Filter;
use Twig\Attribute\FirstClassTwigCallableReady;
use Twig\Compiler;
use Twig\Node\EmptyNode;
use Twig\Node\Expression\AbstractExpression;
@@ -24,7 +23,6 @@ use Twig\TwigFilter;
*/
class RawFilter extends FilterExpression
{
#[FirstClassTwigCallableReady]
public function __construct(AbstractExpression $node, ?TwigFilter $filter = null, ?Node $arguments = null, int $lineno = 0)
{
parent::__construct($node, $filter ?: new TwigFilter('raw', null, ['is_safe' => ['all']]), $arguments ?: new EmptyNode(), $lineno ?: $node->getTemplateLine());
-2
View File
@@ -12,14 +12,12 @@
namespace Twig\Node\Expression;
use Twig\Attribute\FirstClassTwigCallableReady;
use Twig\Node\CoercesChildrenToStringInterface;
use Twig\Node\Node;
use Twig\TwigFilter;
class FilterExpression extends CallExpression implements CoercesChildrenToStringInterface
{
#[FirstClassTwigCallableReady]
public function __construct(AbstractExpression $node, TwigFilter $filter, Node $arguments, int $lineno)
{
parent::__construct(['node' => $node, 'arguments' => $arguments], ['name' => $filter->getName(), 'type' => 'filter', 'twig_callable' => $filter], $lineno);
@@ -11,7 +11,6 @@
namespace Twig\Node\Expression;
use Twig\Attribute\FirstClassTwigCallableReady;
use Twig\Compiler;
use Twig\Node\CoercesChildrenToStringInterface;
use Twig\Node\Node;
@@ -21,7 +20,6 @@ class FunctionExpression extends CallExpression implements SupportDefinedTestInt
{
use SupportDefinedTestTrait;
#[FirstClassTwigCallableReady]
public function __construct(TwigFunction $function, Node $arguments, int $lineno)
{
parent::__construct(['arguments' => $arguments], ['name' => $function->getName(), 'type' => 'function', 'twig_callable' => $function], $lineno);
-2
View File
@@ -11,7 +11,6 @@
namespace Twig\Node\Expression\Test;
use Twig\Attribute\FirstClassTwigCallableReady;
use Twig\Compiler;
use Twig\Error\SyntaxError;
use Twig\Node\Expression\AbstractExpression;
@@ -32,7 +31,6 @@ use Twig\TwigTest;
*/
class DefinedTest extends TestExpression
{
#[FirstClassTwigCallableReady]
public function __construct(AbstractExpression $node, TwigTest $name, ?Node $arguments, int $lineno)
{
if (!$node instanceof SupportDefinedTestInterface) {
-2
View File
@@ -11,7 +11,6 @@
namespace Twig\Node\Expression;
use Twig\Attribute\FirstClassTwigCallableReady;
use Twig\Node\CoercesChildrenToStringInterface;
use Twig\Node\EmptyNode;
use Twig\Node\Node;
@@ -19,7 +18,6 @@ use Twig\TwigTest;
class TestExpression extends CallExpression implements ReturnBoolInterface, CoercesChildrenToStringInterface
{
#[FirstClassTwigCallableReady]
public function __construct(AbstractExpression $node, TwigTest $test, ?Node $arguments, int $lineno)
{
parent::__construct(['node' => $node, 'arguments' => $arguments ?: new EmptyNode()], ['name' => $test->getName(), 'type' => 'test', 'twig_callable' => $test], $lineno);