diff --git a/src/Symfony/Component/Console/Attribute/AsCommand.php b/src/Symfony/Component/Console/Attribute/AsCommand.php index b337f548f4663..70215c8a65709 100644 --- a/src/Symfony/Component/Console/Attribute/AsCommand.php +++ b/src/Symfony/Component/Console/Attribute/AsCommand.php @@ -21,7 +21,7 @@ public function __construct( public string $name, public ?string $description = null, array $aliases = [], - bool $hidden = false, + public bool $hidden = false, ) { if (!$hidden && !$aliases) { return; diff --git a/src/Symfony/Component/Console/Command/Command.php b/src/Symfony/Component/Console/Command/Command.php index e35ae51ebfa28..ec06c6e720c6b 100644 --- a/src/Symfony/Component/Console/Command/Command.php +++ b/src/Symfony/Component/Console/Command/Command.php @@ -513,7 +513,12 @@ public function setHidden(bool $hidden /*= true*/) */ public function isHidden() { - return $this->hidden; + $isHidden = false; + if (\PHP_VERSION_ID >= 80000 && $attribute = (new \ReflectionClass($this))->getAttributes(AsCommand::class)) { + $isHidden = $attribute[0]->newInstance()->hidden; + } + + return $this->hidden || $isHidden; } /** diff --git a/src/Symfony/Component/Console/Tests/Command/CommandTest.php b/src/Symfony/Component/Console/Tests/Command/CommandTest.php index 68c0366210374..10d29314711e9 100644 --- a/src/Symfony/Component/Console/Tests/Command/CommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/CommandTest.php @@ -414,6 +414,8 @@ public function testCommandAttribute() { $this->assertSame('|foo|f', Php8Command::getDefaultName()); $this->assertSame('desc', Php8Command::getDefaultDescription()); + + $this->assertTrue((new Php8Command())->isHidden()); } }