From db7644bf30621f80b8f3b31eb6b09857c4f8c5a3 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Thu, 6 Feb 2025 15:31:18 +0100 Subject: [PATCH] try reading the command name from the AsCommand attribute first --- .../DependencyInjection/AddScheduleMessengerPass.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Scheduler/DependencyInjection/AddScheduleMessengerPass.php b/src/Symfony/Component/Scheduler/DependencyInjection/AddScheduleMessengerPass.php index b0cd4dfa279e1..696422e0d28da 100644 --- a/src/Symfony/Component/Scheduler/DependencyInjection/AddScheduleMessengerPass.php +++ b/src/Symfony/Component/Scheduler/DependencyInjection/AddScheduleMessengerPass.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Scheduler\DependencyInjection; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Messenger\RunCommandMessage; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -55,7 +56,9 @@ public function process(ContainerBuilder $container): void $scheduleName = $tagAttributes['schedule'] ?? 'default'; if ($serviceDefinition->hasTag('console.command')) { - $message = new Definition(RunCommandMessage::class, [$serviceDefinition->getClass()::getDefaultName().(empty($tagAttributes['arguments']) ? '' : " {$tagAttributes['arguments']}")]); + /** @var AsCommand|null $attribute */ + $attribute = ($container->getReflectionClass($serviceDefinition->getClass())->getAttributes(AsCommand::class)[0] ?? null)?->newInstance(); + $message = new Definition(RunCommandMessage::class, [$attribute?->name ?? $serviceDefinition->getClass()::getDefaultName().(empty($tagAttributes['arguments']) ? '' : " {$tagAttributes['arguments']}")]); } else { $message = new Definition(ServiceCallMessage::class, [$serviceId, $tagAttributes['method'] ?? '__invoke', (array) ($tagAttributes['arguments'] ?? [])]); }