Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit33cacad

Browse files
committed
bug#38024 [Console] Fix undefined index for inconsistent command name definition (chalasr)
This PR was merged into the 3.4 branch.Discussion----------[Console] Fix undefined index for inconsistent command name definition| Q | A| ------------- | ---| Branch? | 3.4| Bug fix? | yes| New feature? | no| Deprecations? | no| Tickets |Fixes#38015| License | MIT| Doc PR | -The issue happens when the command name is set via construct/setName() and is routed via a command loader under a different name, which causes `Application::get(): Command` to return null (return type violation) with a notice. This makes it throws a proper CommandNotFoundException as expected.Commits-------d59140e Fix undefined index for inconsistent command name definition
2 parentsf4f7683 +d59140e commit33cacad

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

‎src/Symfony/Component/Console/Application.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,11 @@ public function get($name)
490490
thrownewCommandNotFoundException(sprintf('The command "%s" does not exist.',$name));
491491
}
492492

493+
// When the command has a different name than the one used at the command loader level
494+
if (!isset($this->commands[$name])) {
495+
thrownewCommandNotFoundException(sprintf('The "%s" command cannot be found because it is registered under multiple names. Make sure you don\'t set a different name via constructor or "setName()".',$name));
496+
}
497+
493498
$command =$this->commands[$name];
494499

495500
if ($this->wantHelps) {

‎src/Symfony/Component/Console/Tests/ApplicationTest.php‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,6 +1715,20 @@ public function testErrorIsRethrownIfNotHandledByConsoleErrorEventWithCatchingEn
17151715
$this->assertSame('Something went wrong.',$e->getMessage());
17161716
}
17171717
}
1718+
1719+
publicfunctiontestCommandNameMismatchWithCommandLoaderKeyThrows()
1720+
{
1721+
$this->expectException(CommandNotFoundException::class);
1722+
$this->expectExceptionMessage('The "test" command cannot be found because it is registered under multiple names. Make sure you don\'t set a different name via constructor or "setName()".');
1723+
1724+
$app =newApplication();
1725+
$loader =newFactoryCommandLoader([
1726+
'test' =>staticfunction () {returnnewCommand('test-command'); },
1727+
]);
1728+
1729+
$app->setCommandLoader($loader);
1730+
$app->get('test');
1731+
}
17181732
}
17191733

17201734
class CustomApplicationextends Application

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp