From 9d3dd5b7a6cd4ec849eeaa9807de09b632d7e662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Thu, 30 Nov 2023 09:47:58 +0100 Subject: [PATCH] Update phpdoc --- src/Extension/Attribute/AsTwigFilter.php | 7 +++++++ src/Extension/Attribute/AsTwigFunction.php | 7 +++++++ src/Extension/Attribute/AsTwigTest.php | 7 +++++++ src/Extension/AttributeExtension.php | 6 +++--- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/Extension/Attribute/AsTwigFilter.php b/src/Extension/Attribute/AsTwigFilter.php index 24471323502..9d47aaf674a 100644 --- a/src/Extension/Attribute/AsTwigFilter.php +++ b/src/Extension/Attribute/AsTwigFilter.php @@ -7,6 +7,13 @@ /** * Registers a method as template filter. * + * If the first argument of the method has Twig\Environment type-hint, the filter will receive the current environment. + * If the next argument of the method is named $context and has array type-hint, the filter will receive the current context. + * Additional arguments of the method come from the filter call. + * + * #[AsTwigFilter('foo')] + * function fooFilter(Environment $env, array $context, $string, $arg1 = null, ...) { ... } + * * @see TwigFilter */ #[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] diff --git a/src/Extension/Attribute/AsTwigFunction.php b/src/Extension/Attribute/AsTwigFunction.php index f3fecb559b0..3641f760f55 100644 --- a/src/Extension/Attribute/AsTwigFunction.php +++ b/src/Extension/Attribute/AsTwigFunction.php @@ -7,6 +7,13 @@ /** * Registers a method as template function. * + * If the first argument of the method has Twig\Environment type-hint, the function will receive the current environment. + * If the next argument of the method is named $context and has array type-hint, the function will receive the current context. + * Additional arguments of the method come from the function call. + * + * #[AsTwigFunction('foo')] + * function fooFunction(Environment $env, array $context, $string, $arg1 = null, ...) { ... } + * * @see TwigFunction */ #[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] diff --git a/src/Extension/Attribute/AsTwigTest.php b/src/Extension/Attribute/AsTwigTest.php index ac554efadce..3a6ac806b2b 100644 --- a/src/Extension/Attribute/AsTwigTest.php +++ b/src/Extension/Attribute/AsTwigTest.php @@ -7,6 +7,13 @@ /** * Registers a method as template test. * + * If the first argument of the method has Twig\Environment type-hint, the test will receive the current environment. + * If the next argument of the method is named $context and has array type-hint, the test will receive the current context. + * The last argument of the method is the value to be tested, if any. + * + * #[AsTwigTest('foo')] + * public function fooTest(Environment $env, array $context, $value, $arg1 = null) { ... } + * * @see TwigTest */ #[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] diff --git a/src/Extension/AttributeExtension.php b/src/Extension/AttributeExtension.php index 5bd5cdfa5f0..1464dcaacd4 100644 --- a/src/Extension/AttributeExtension.php +++ b/src/Extension/AttributeExtension.php @@ -98,7 +98,7 @@ private function initFromAttributes() foreach ($method->getAttributes(AsTwigFilter::class) as $attribute) { $attribute = $attribute->newInstance(); - $name = $attribute->name ?? $method->getName(); + $name = $attribute->name; if (isset($filters[$name])) { throw new \LogicException(sprintf('Multiple definitions of the "%s" filter.', $name)); } @@ -127,7 +127,7 @@ private function initFromAttributes() foreach ($method->getAttributes(AsTwigFunction::class) as $attribute) { $attribute = $attribute->newInstance(); - $name = $attribute->name ?? $method->getName(); + $name = $attribute->name; if (isset($functions[$name])) { throw new \LogicException(sprintf('Multiple definitions of the "%s" function.', $name)); } @@ -154,7 +154,7 @@ private function initFromAttributes() foreach ($method->getAttributes(AsTwigTest::class) as $attribute) { $attribute = $attribute->newInstance(); - $name = $attribute->name ?? $method->getName(); + $name = $attribute->name; if (isset($tests[$name])) { throw new \LogicException(sprintf('Multiple definitions of the "%s" test.', $name)); }