File tree Expand file tree Collapse file tree 2 files changed +23
-6
lines changed
Expand file tree Collapse file tree 2 files changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -46,14 +46,14 @@ use Symfony\Component\Console\CommandLoader\FactoryCommandLoader;
4646 $ application = new Application ();
4747 $ application ->setCommandLoader (
4848 new FactoryCommandLoader ([
49- Command \Get::getDefaultName () => static fn () => new Command \Get (),
50- Command \ListSoftware::getDefaultName () => static fn () => new Command \ListSoftware (),
51- Command \Show::getDefaultName () => static fn () => new Command \Show (),
52- Command \Init::getDefaultName () => static fn () => new Command \Init (),
53- Command \Build::getDefaultName () => static fn () => new Command \Build (),
49+ Command \Get::getCommandName () => static fn () => new Command \Get (),
50+ Command \ListSoftware::getCommandName () => static fn () => new Command \ListSoftware (),
51+ Command \Show::getCommandName () => static fn () => new Command \Show (),
52+ Command \Init::getCommandName () => static fn () => new Command \Init (),
53+ Command \Build::getCommandName () => static fn () => new Command \Build (),
5454 ]),
5555 );
56- $ application ->setDefaultCommand (Command \Get::getDefaultName (), false );
56+ $ application ->setDefaultCommand (Command \Get::getCommandName (), false );
5757 $ application ->setVersion (Info::version ());
5858 $ application ->setName (Info::NAME );
5959 $ application ->run ();
Original file line number Diff line number Diff line change 77use Internal \DLoad \Bootstrap ;
88use Internal \DLoad \Service \Container ;
99use Internal \DLoad \Service \Logger ;
10+ use Symfony \Component \Console \Attribute \AsCommand ;
1011use Symfony \Component \Console \Command \Command ;
1112use Symfony \Component \Console \Input \InputInterface ;
1213use Symfony \Component \Console \Input \InputOption ;
@@ -43,6 +44,22 @@ abstract class Base extends Command
4344 /** @var Container IoC container with services */
4445 protected Container $ container ;
4546
47+ public static function getCommandName (): ?string
48+ {
49+ if (!\class_exists (AsCommand::class)) {
50+ // Fall back on lower Symfony versions
51+ return self ::getDefaultName ();
52+ }
53+
54+ if ($ attributes = (new \ReflectionClass (static ::class))->getAttributes (AsCommand::class)) {
55+ /** @var AsCommand $attribute */
56+ $ attribute = $ attributes [0 ]->newInstance ();
57+ return $ attribute ->name ;
58+ }
59+
60+ return null ;
61+ }
62+
4663 /**
4764 * Configures command options.
4865 *
You can’t perform that action at this time.
0 commit comments