Skip to content

Commit a1126e7

Browse files
bug symfony#59711 [Scheduler] try reading the command name from the AsCommand attribute first (xabbuh)
This PR was merged into the 7.3 branch. Discussion ---------- [Scheduler] try reading the command name from the AsCommand attribute first | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | | License | MIT Commits ------- db7644b try reading the command name from the AsCommand attribute first
2 parents 6f4f04b + db7644b commit a1126e7

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/Symfony/Component/Scheduler/DependencyInjection/AddScheduleMessengerPass.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Scheduler\DependencyInjection;
1313

14+
use Symfony\Component\Console\Attribute\AsCommand;
1415
use Symfony\Component\Console\Messenger\RunCommandMessage;
1516
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -55,7 +56,9 @@ public function process(ContainerBuilder $container): void
5556
$scheduleName = $tagAttributes['schedule'] ?? 'default';
5657

5758
if ($serviceDefinition->hasTag('console.command')) {
58-
$message = new Definition(RunCommandMessage::class, [$serviceDefinition->getClass()::getDefaultName().(empty($tagAttributes['arguments']) ? '' : " {$tagAttributes['arguments']}")]);
59+
/** @var AsCommand|null $attribute */
60+
$attribute = ($container->getReflectionClass($serviceDefinition->getClass())->getAttributes(AsCommand::class)[0] ?? null)?->newInstance();
61+
$message = new Definition(RunCommandMessage::class, [$attribute?->name ?? $serviceDefinition->getClass()::getDefaultName().(empty($tagAttributes['arguments']) ? '' : " {$tagAttributes['arguments']}")]);
5962
} else {
6063
$message = new Definition(ServiceCallMessage::class, [$serviceId, $tagAttributes['method'] ?? '__invoke', (array) ($tagAttributes['arguments'] ?? [])]);
6164
}

0 commit comments

Comments
 (0)