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

Commit3b995e5

Browse files
author
Robin Chalas
committed
[Console] Fix disabling lazy commands
1 parent8d7f6ed commit3b995e5

File tree

2 files changed

+42
-9
lines changed

2 files changed

+42
-9
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -455,15 +455,12 @@ public function get($name)
455455
{
456456
$this->init();
457457

458-
if (isset($this->commands[$name])) {
459-
$command =$this->commands[$name];
460-
}elseif ($this->commandLoader &&$this->commandLoader->has($name)) {
461-
$command =$this->commandLoader->get($name);
462-
$this->add($command);
463-
}else {
458+
if (!$this->has($name)) {
464459
thrownewCommandNotFoundException(sprintf('The command "%s" does not exist.',$name));
465460
}
466461

462+
$command =$this->commands[$name];
463+
467464
if ($this->wantHelps) {
468465
$this->wantHelps =false;
469466

@@ -487,7 +484,7 @@ public function has($name)
487484
{
488485
$this->init();
489486

490-
returnisset($this->commands[$name]) || ($this->commandLoader &&$this->commandLoader->has($name));
487+
returnisset($this->commands[$name]) || ($this->commandLoader &&$this->commandLoader->has($name) &&$this->add($this->commandLoader->get($name)));
491488
}
492489

493490
/**
@@ -650,7 +647,9 @@ public function all($namespace = null)
650647
$commands =$this->commands;
651648
foreach ($this->commandLoader->getNames()as$name) {
652649
if (!isset($commands[$name])) {
653-
$commands[$name] =$this->get($name);
650+
if ($this->commandLoader->get($name)->isEnabled()) {
651+
$commands[$name] =$this->get($name);
652+
}
654653
}
655654
}
656655

@@ -667,7 +666,9 @@ public function all($namespace = null)
667666
if ($this->commandLoader) {
668667
foreach ($this->commandLoader->getNames()as$name) {
669668
if (!isset($commands[$name]) &&$namespace ===$this->extractNamespace($name,substr_count($namespace,':') +1)) {
670-
$commands[$name] =$this->get($name);
669+
if ($this->commandLoader->get($name)->isEnabled()) {
670+
$commands[$name] =$this->get($name);
671+
}
671672
}
672673
}
673674
}

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,6 +1532,30 @@ public function testRunLazyCommandService()
15321532
$this->assertSame(array('lazy:alias','lazy:alias2'),$command->getAliases());
15331533
}
15341534

1535+
/**
1536+
* @expectedException \Symfony\Component\Console\Exception\CommandNotFoundException
1537+
*/
1538+
publicfunctiontestGetDisabledLazyCommand()
1539+
{
1540+
$application =newApplication();
1541+
$application->setCommandLoader(newFactoryCommandLoader(array('disabled' =>function () {returnnewDisabledCommand(); })));
1542+
$application->get('disabled');
1543+
}
1544+
1545+
publicfunctiontestHasReturnsFalseForDisabledLazyCommand()
1546+
{
1547+
$application =newApplication();
1548+
$application->setCommandLoader(newFactoryCommandLoader(array('disabled' =>function () {returnnewDisabledCommand(); })));
1549+
$this->assertFalse($application->has('disabled'));
1550+
}
1551+
1552+
publicfunctiontestAllExcludesDisabledLazyCommand()
1553+
{
1554+
$application =newApplication();
1555+
$application->setCommandLoader(newFactoryCommandLoader(array('disabled' =>function () {returnnewDisabledCommand(); })));
1556+
$this->assertArrayNotHasKey('disabled',$application->all());
1557+
}
1558+
15351559
protectedfunctiongetDispatcher($skipCommand =false)
15361560
{
15371561
$dispatcher =newEventDispatcher();
@@ -1634,3 +1658,11 @@ public function execute(InputInterface $input, OutputInterface $output)
16341658
$output->writeln('lazy-command called');
16351659
}
16361660
}
1661+
1662+
class DisabledCommandextends Command
1663+
{
1664+
publicfunctionisEnabled()
1665+
{
1666+
returnfalse;
1667+
}
1668+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp