From 4af6e81da69dfbb38e0532d0c9589ef0aa35ad16 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Sun, 14 Dec 2025 18:08:27 +0100 Subject: [PATCH 1/2] Stop using deprecated Command::getDefaultName() --- bin/dload | 12 ++++++------ src/Command/Base.php | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) mode change 100644 => 100755 bin/dload diff --git a/bin/dload b/bin/dload old mode 100644 new mode 100755 index 9eca91d..053b8e8 --- a/bin/dload +++ b/bin/dload @@ -46,14 +46,14 @@ use Symfony\Component\Console\CommandLoader\FactoryCommandLoader; $application = new Application(); $application->setCommandLoader( new FactoryCommandLoader([ - Command\Get::getDefaultName() => static fn() => new Command\Get(), - Command\ListSoftware::getDefaultName() => static fn() => new Command\ListSoftware(), - Command\Show::getDefaultName() => static fn() => new Command\Show(), - Command\Init::getDefaultName() => static fn() => new Command\Init(), - Command\Build::getDefaultName() => static fn() => new Command\Build(), + Command\Get::getCommandName() => static fn() => new Command\Get(), + Command\ListSoftware::getCommandName() => static fn() => new Command\ListSoftware(), + Command\Show::getCommandName() => static fn() => new Command\Show(), + Command\Init::getCommandName() => static fn() => new Command\Init(), + Command\Build::getCommandName() => static fn() => new Command\Build(), ]), ); - $application->setDefaultCommand(Command\Get::getDefaultName(), false); + $application->setDefaultCommand(Command\Get::getCommandName(), false); $application->setVersion(Info::version()); $application->setName(Info::NAME); $application->run(); diff --git a/src/Command/Base.php b/src/Command/Base.php index 564c4cc..ebbf3a0 100644 --- a/src/Command/Base.php +++ b/src/Command/Base.php @@ -7,6 +7,7 @@ use Internal\DLoad\Bootstrap; use Internal\DLoad\Service\Container; use Internal\DLoad\Service\Logger; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -54,6 +55,22 @@ public function configure(): void $this->addOption('config', null, InputOption::VALUE_OPTIONAL, 'Path to the configuration file'); } + public static function getCommandName(): ?string + { + if (!class_exists(AsCommand::class)) { + // Fall back on lower Symfony versions + return self::getDefaultName(); + } + + if ($attributes = (new \ReflectionClass(static::class))->getAttributes(AsCommand::class)) { + /** @var AsCommand $attribute */ + $attribute = $attributes[0]->newInstance(); + return $attribute->name; + } + + return null; + } + /** * Initializes the command execution environment. * From 5de315e0923a0308139da127250145de1db92291 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Sun, 14 Dec 2025 22:57:24 +0400 Subject: [PATCH 2/2] cs: Fix code style --- src/Command/Base.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Command/Base.php b/src/Command/Base.php index ebbf3a0..86411b4 100644 --- a/src/Command/Base.php +++ b/src/Command/Base.php @@ -44,20 +44,9 @@ abstract class Base extends Command /** @var Container IoC container with services */ protected Container $container; - /** - * Configures command options. - * - * Adds option for specifying configuration file location. - */ - public function configure(): void - { - parent::configure(); - $this->addOption('config', null, InputOption::VALUE_OPTIONAL, 'Path to the configuration file'); - } - public static function getCommandName(): ?string { - if (!class_exists(AsCommand::class)) { + if (!\class_exists(AsCommand::class)) { // Fall back on lower Symfony versions return self::getDefaultName(); } @@ -71,6 +60,17 @@ public static function getCommandName(): ?string return null; } + /** + * Configures command options. + * + * Adds option for specifying configuration file location. + */ + public function configure(): void + { + parent::configure(); + $this->addOption('config', null, InputOption::VALUE_OPTIONAL, 'Path to the configuration file'); + } + /** * Initializes the command execution environment. *