Skip to content

Commit 8b22008

Browse files
Nyholmroxblnfk
andcommitted
fix: Stop using deprecated Command::getDefaultName() (#90)
Co-authored-by: roxblnfk <roxblnfk@ya.ru>
1 parent 93bb7ad commit 8b22008

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

bin/dload

100644100755
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff 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();

src/Command/Base.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Internal\DLoad\Bootstrap;
88
use Internal\DLoad\Service\Container;
99
use Internal\DLoad\Service\Logger;
10+
use Symfony\Component\Console\Attribute\AsCommand;
1011
use Symfony\Component\Console\Command\Command;
1112
use Symfony\Component\Console\Input\InputInterface;
1213
use 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
*

0 commit comments

Comments
 (0)