diff --git a/src/Attribute/AsTwigFilter.php b/src/Attribute/AsTwigFilter.php index bfa101aaf32..3a9f2abcf52 100644 --- a/src/Attribute/AsTwigFilter.php +++ b/src/Attribute/AsTwigFilter.php @@ -11,6 +11,7 @@ namespace Twig\Attribute; +use Twig\DeprecatedCallableInfo; use Twig\Node\Node; use Twig\TwigFilter; @@ -64,15 +65,7 @@ public function __construct( */ public ?array $preservesSafety = null, - /** - * Set to true if the filter is deprecated. - */ - public bool|string $deprecated = false, - - /** - * The alternative filter name to suggest when the deprecated filter is called. - */ - public ?string $alternative = null, + public ?DeprecatedCallableInfo $deprecationInfo = null, ) { } } diff --git a/src/Attribute/AsTwigFunction.php b/src/Attribute/AsTwigFunction.php index fbbf040b012..bc644df6f81 100644 --- a/src/Attribute/AsTwigFunction.php +++ b/src/Attribute/AsTwigFunction.php @@ -11,6 +11,7 @@ namespace Twig\Attribute; +use Twig\DeprecatedCallableInfo; use Twig\Node\Node; use Twig\TwigFunction; @@ -51,15 +52,7 @@ public function __construct( */ public ?string $isSafeCallback = null, - /** - * Set to true if the function is deprecated. - */ - public bool|string $deprecated = false, - - /** - * The alternative function name to suggest when the deprecated function is called. - */ - public ?string $alternative = null, + public ?DeprecatedCallableInfo $deprecationInfo = null, ) { } } diff --git a/src/Attribute/AsTwigTest.php b/src/Attribute/AsTwigTest.php index 17f91cfd0af..5ee752b6680 100644 --- a/src/Attribute/AsTwigTest.php +++ b/src/Attribute/AsTwigTest.php @@ -11,6 +11,7 @@ namespace Twig\Attribute; +use Twig\DeprecatedCallableInfo; use Twig\TwigTest; /** @@ -36,15 +37,7 @@ public function __construct( */ public string $name, - /** - * Set to true if the function is deprecated. - */ - public bool|string $deprecated = false, - - /** - * The alternative function name to suggest when the deprecated function is called. - */ - public ?string $alternative = null, + public ?DeprecatedCallableInfo $deprecationInfo = null, ) { } } diff --git a/src/Extension/AttributeExtension.php b/src/Extension/AttributeExtension.php index 0ad1ce318ff..6a7bbfa16d2 100644 --- a/src/Extension/AttributeExtension.php +++ b/src/Extension/AttributeExtension.php @@ -110,8 +110,7 @@ private function initFromAttributes() 'is_safe_callback' => $attribute->isSafeCallback, 'pre_escape' => $attribute->preEscape, 'preserves_safety' => $attribute->preservesSafety, - 'deprecated' => $attribute->deprecated, - 'alternative' => $attribute->alternative, + 'deprecation_info' => $attribute->deprecationInfo, ]); } @@ -134,8 +133,7 @@ private function initFromAttributes() 'is_variadic' => $isVariadic, 'is_safe' => $attribute->isSafe, 'is_safe_callback' => $attribute->isSafeCallback, - 'deprecated' => $attribute->deprecated, - 'alternative' => $attribute->alternative, + 'deprecation_info' => $attribute->deprecationInfo, ]); } @@ -150,8 +148,7 @@ private function initFromAttributes() $tests[$name] = new TwigTest($name, [$objectOrClass, $method->getName()], [ 'is_variadic' => $isVariadic, - 'deprecated' => $attribute->deprecated, - 'alternative' => $attribute->alternative, + 'deprecation_info' => $attribute->deprecationInfo, ]); } } diff --git a/tests/Extension/AttributeExtensionTest.php b/tests/Extension/AttributeExtensionTest.php index d5995442e4c..7a5c815ecec 100644 --- a/tests/Extension/AttributeExtensionTest.php +++ b/tests/Extension/AttributeExtensionTest.php @@ -3,6 +3,7 @@ namespace Twig\Tests\Extension; use PHPUnit\Framework\TestCase; +use Twig\DeprecatedCallableInfo; use Twig\Extension\AttributeExtension; use Twig\Tests\Extension\Fixtures\ExtensionWithAttributes; use Twig\TwigFilter; @@ -10,7 +11,8 @@ use Twig\TwigTest; /** - * @requires PHP >= 8.0 + * Nested attributes are not supported in PHP 8.0. + * @requires PHP >= 8.1 */ class AttributeExtensionTest extends TestCase { @@ -40,7 +42,7 @@ public static function provideFilters() yield 'with env and context' => ['with_env_and_context_filter', 'withEnvAndContextFilter', ['needs_environment' => true, 'needs_context' => true]]; yield 'no argument' => ['no_arg_filter', 'noArgFilter', []]; yield 'variadic' => ['variadic_filter', 'variadicFilter', ['is_variadic' => true]]; - yield 'deprecated' => ['deprecated_filter', 'deprecatedFilter', ['deprecated' => true, 'alternative' => 'bar']]; + yield 'deprecated' => ['deprecated_filter', 'deprecatedFilter', ['deprecation_info' => new DeprecatedCallableInfo('foo/bar', '1.2')]]; yield 'pattern' => ['pattern_*_filter', 'patternFilter', []]; } @@ -70,7 +72,7 @@ public static function provideFunctions() yield 'with env and context' => ['with_env_and_context_function', 'withEnvAndContextFunction', ['needs_environment' => true, 'needs_context' => true]]; yield 'no argument' => ['no_arg_function', 'noArgFunction', []]; yield 'variadic' => ['variadic_function', 'variadicFunction', ['is_variadic' => true]]; - yield 'deprecated' => ['deprecated_function', 'deprecatedFunction', ['deprecated' => true, 'alternative' => 'bar']]; + yield 'deprecated' => ['deprecated_function', 'deprecatedFunction', ['deprecation_info' => new DeprecatedCallableInfo('foo/bar', '1.2')]]; } /** @@ -95,7 +97,7 @@ public static function provideTests() { yield 'with name' => ['foo', 'fooTest', []]; yield 'variadic' => ['variadic_test', 'variadicTest', ['is_variadic' => true]]; - yield 'deprecated' => ['deprecated_test', 'deprecatedTest', ['deprecated' => true, 'alternative' => 'bar']]; + yield 'deprecated' => ['deprecated_test', 'deprecatedTest', ['deprecation_info' => new DeprecatedCallableInfo('foo/bar', '1.2')]]; } public function testRuntimeExtension() diff --git a/tests/Extension/Fixtures/ExtensionWithAttributes.php b/tests/Extension/Fixtures/ExtensionWithAttributes.php index c0aade019fb..64a73264107 100644 --- a/tests/Extension/Fixtures/ExtensionWithAttributes.php +++ b/tests/Extension/Fixtures/ExtensionWithAttributes.php @@ -6,6 +6,7 @@ use Twig\Attribute\AsTwigFilter; use Twig\Attribute\AsTwigFunction; use Twig\Attribute\AsTwigTest; +use Twig\DeprecatedCallableInfo; use Twig\Environment; #[AsTwigExtension] @@ -41,7 +42,7 @@ public function variadicFilter(string ...$strings) { } - #[AsTwigFilter('deprecated_filter', deprecated: true, alternative: 'bar')] + #[AsTwigFilter('deprecated_filter', deprecationInfo: new DeprecatedCallableInfo('foo/bar', '1.2'))] public function deprecatedFilter(string $string) { } @@ -81,7 +82,7 @@ public function variadicFunction(string ...$strings) { } - #[AsTwigFunction('deprecated_function', deprecated: true, alternative: 'bar')] + #[AsTwigFunction('deprecated_function', deprecationInfo: new DeprecatedCallableInfo('foo/bar', '1.2'))] public function deprecatedFunction(string $string) { } @@ -96,7 +97,7 @@ public function variadicTest(string ...$strings) { } - #[AsTwigTest('deprecated_test', deprecated: true, alternative: 'bar')] + #[AsTwigTest('deprecated_test', deprecationInfo: new DeprecatedCallableInfo('foo/bar', '1.2'))] public function deprecatedTest(string $string) { }