diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AttributeAutoconfigurationPass.php b/src/Symfony/Component/DependencyInjection/Compiler/AttributeAutoconfigurationPass.php index 645214bd467f0..c57b78d3f58e7 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/AttributeAutoconfigurationPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/AttributeAutoconfigurationPass.php @@ -120,7 +120,7 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed if ($this->methodAttributeConfigurators || $this->parameterAttributeConfigurators) { foreach ($classReflector->getMethods(\ReflectionMethod::IS_PUBLIC) as $methodReflector) { - if ($methodReflector->isStatic() || $methodReflector->isConstructor() || $methodReflector->isDestructor()) { + if ($methodReflector->isConstructor() || $methodReflector->isDestructor()) { continue; } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php index e7fcac4623f84..c9364395f71de 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php @@ -47,6 +47,7 @@ use Symfony\Component\DependencyInjection\Tests\Fixtures\LocatorConsumerWithDefaultIndexMethodAndWithDefaultPriorityMethod; use Symfony\Component\DependencyInjection\Tests\Fixtures\LocatorConsumerWithDefaultPriorityMethod; use Symfony\Component\DependencyInjection\Tests\Fixtures\LocatorConsumerWithoutIndex; +use Symfony\Component\DependencyInjection\Tests\Fixtures\StaticMethodTag; use Symfony\Component\DependencyInjection\Tests\Fixtures\TaggedConsumerWithExclude; use Symfony\Component\DependencyInjection\Tests\Fixtures\TaggedService1; use Symfony\Component\DependencyInjection\Tests\Fixtures\TaggedService2; @@ -1025,6 +1026,28 @@ static function (ChildDefinition $definition) { self::assertTrue($service->hasBeenConfigured); } + public function testAttributeAutoconfigurationOnStaticMethod() + { + $container = new ContainerBuilder(); + $container->registerAttributeForAutoconfiguration( + CustomMethodAttribute::class, + static function (ChildDefinition $d, CustomMethodAttribute $a, \ReflectionMethod $_r) { + $d->addTag('custom_tag', ['attribute' => $a->someAttribute]); + } + ); + + $container->register('service', StaticMethodTag::class) + ->setPublic(true) + ->setAutoconfigured(true); + + $container->compile(); + + $definition = $container->getDefinition('service'); + self::assertEquals([['attribute' => 'static']], $definition->getTag('custom_tag')); + + $container->get('service'); + } + public function testTaggedIteratorAndLocatorWithExclude() { $container = new ContainerBuilder(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/StaticMethodTag.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/StaticMethodTag.php new file mode 100644 index 0000000000000..d5362d849cf38 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/StaticMethodTag.php @@ -0,0 +1,22 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\DependencyInjection\Tests\Fixtures; + +use Symfony\Component\DependencyInjection\Tests\Fixtures\Attribute\CustomMethodAttribute; + +final class StaticMethodTag +{ + #[CustomMethodAttribute('static')] + public static function method(): void + { + } +}