diff --git a/UPGRADE-4.4.md b/UPGRADE-4.4.md index 584eb693e2ab5..323bf96c18a70 100644 --- a/UPGRADE-4.4.md +++ b/UPGRADE-4.4.md @@ -6,6 +6,11 @@ Cache * Added argument `$prefix` to `AdapterInterface::clear()` +Console +------- + + * Deprecated finding hidden commands using an abbreviation, use the full name instead + Debug ----- diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index 1039e3a5fe036..e0df969c4abb0 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -31,6 +31,7 @@ Config Console ------- + * Removed support for finding hidden commands using an abbreviation, use the full name instead * Removed the `setCrossingChar()` method in favor of the `setDefaultCrossingChar()` method in `TableStyle`. * Removed the `setHorizontalBorderChar()` method in favor of the `setDefaultCrossingChars()` method in `TableStyle`. * Removed the `getHorizontalBorderChar()` method in favor of the `getBorderChars()` method in `TableStyle`. diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index af1af4b8ec4cc..e66705ab37bc6 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -692,12 +692,14 @@ public function find($name) foreach ($abbrevs as $abbrev) { $maxLen = max(Helper::strlen($abbrev), $maxLen); } - $abbrevs = array_map(function ($cmd) use ($commandList, $usableWidth, $maxLen) { + $abbrevs = array_map(function ($cmd) use ($commandList, $usableWidth, $maxLen, &$commands) { if (!$commandList[$cmd] instanceof Command) { $commandList[$cmd] = $this->commandLoader->get($cmd); } if ($commandList[$cmd]->isHidden()) { + unset($commands[array_search($cmd, $commands)]); + return false; } @@ -705,12 +707,21 @@ public function find($name) return Helper::strlen($abbrev) > $usableWidth ? Helper::substr($abbrev, 0, $usableWidth - 3).'...' : $abbrev; }, array_values($commands)); - $suggestions = $this->getAbbreviationSuggestions(array_filter($abbrevs)); - throw new CommandNotFoundException(sprintf("Command \"%s\" is ambiguous.\nDid you mean one of these?\n%s", $name, $suggestions), array_values($commands)); + if (\count($commands) > 1) { + $suggestions = $this->getAbbreviationSuggestions(array_filter($abbrevs)); + + throw new CommandNotFoundException(sprintf("Command \"%s\" is ambiguous.\nDid you mean one of these?\n%s", $name, $suggestions), array_values($commands)); + } } - return $this->get(reset($commands)); + $command = $this->get(reset($commands)); + + if ($command->isHidden()) { + @trigger_error(sprintf('Command "%s" is hidden, finding it using an abbreviation is deprecated since Symfony 4.4, use its full name instead.', $command->getName()), E_USER_DEPRECATED); + } + + return $command; } /** diff --git a/src/Symfony/Component/Console/CHANGELOG.md b/src/Symfony/Component/Console/CHANGELOG.md index b9e837a8d10c8..d1b8a324c6024 100644 --- a/src/Symfony/Component/Console/CHANGELOG.md +++ b/src/Symfony/Component/Console/CHANGELOG.md @@ -4,6 +4,7 @@ CHANGELOG 4.4.0 ----- + * deprecated finding hidden commands using an abbreviation, use the full name instead * added `Question::setTrimmable` default to true to allow the answer to be trimmed * added method `preventRedrawFasterThan()` and `forceRedrawSlowerThan()` on `ProgressBar` * `Application` implements `ResetInterface` diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index 9b444419b8848..e750975d2d467 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -76,6 +76,7 @@ public static function setUpBeforeClass(): void require_once self::$fixturesPath.'/TestAmbiguousCommandRegistering.php'; require_once self::$fixturesPath.'/TestAmbiguousCommandRegistering2.php'; require_once self::$fixturesPath.'/FooHiddenCommand.php'; + require_once self::$fixturesPath.'/BarHiddenCommand.php'; } protected function normalizeLineBreaks($text) @@ -441,6 +442,16 @@ public function provideAmbiguousAbbreviations() ]; } + public function testFindWithAmbiguousAbbreviationsFindsCommandIfAlternativesAreHidden() + { + $application = new Application(); + + $application->add(new \FooCommand()); + $application->add(new \FooHiddenCommand()); + + $this->assertInstanceOf('FooCommand', $application->find('foo:')); + } + public function testFindCommandEqualNamespace() { $application = new Application(); @@ -708,6 +719,49 @@ public function testFindWithDoubleColonInNameThrowsException() $application->find('foo::bar'); } + public function testFindHiddenWithExactName() + { + $application = new Application(); + $application->add(new \FooHiddenCommand()); + + $this->assertInstanceOf('FooHiddenCommand', $application->find('foo:hidden')); + $this->assertInstanceOf('FooHiddenCommand', $application->find('afoohidden')); + } + + /** + * @group legacy + * @expectedDeprecation Command "%s:hidden" is hidden, finding it using an abbreviation is deprecated since Symfony 4.4, use its full name instead. + * @dataProvider provideAbbreviationsForHiddenCommands + */ + public function testFindHiddenWithAbbreviatedName($name) + { + $application = new Application(); + + $application->add(new \FooHiddenCommand()); + $application->add(new \BarHiddenCommand()); + + $application->find($name); + } + + public function provideAbbreviationsForHiddenCommands() + { + return [ + ['foo:hidde'], + ['afoohidd'], + ['bar:hidde'], + ]; + } + + public function testFindAmbiguousCommandsIfAllAlternativesAreHidden() + { + $application = new Application(); + + $application->add(new \FooCommand()); + $application->add(new \FooHiddenCommand()); + + $this->assertInstanceOf('FooCommand', $application->find('foo:')); + } + public function testSetCatchExceptions() { $application = new Application(); diff --git a/src/Symfony/Component/Console/Tests/Fixtures/BarHiddenCommand.php b/src/Symfony/Component/Console/Tests/Fixtures/BarHiddenCommand.php new file mode 100644 index 0000000000000..d500f8731f7d9 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/BarHiddenCommand.php @@ -0,0 +1,21 @@ +setName('bar:hidden') + ->setAliases(['abarhidden']) + ->setHidden(true) + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + } +} pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy