8000 feature #20029 Hide commands from ApplicationDescriptor, but allow in… · symfony/symfony@043ccd5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 043ccd5

Browse files
committed
feature #20029 Hide commands from ApplicationDescriptor, but allow invoking (jwdeitch, Jordan Deitch)
This PR was merged into the 3.2-dev branch. Discussion ---------- Hide commands from ApplicationDescriptor, but allow invoking I would like to hide commands from cluttering the descriptors, but still allow their invocation from code or cron. | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | comma-separated list of tickets fixed by the PR, if any | License | MIT | Doc PR | reference to the documentation PR, if any Commits ------- 746dab3 casting setPublic() arg to bool 0a3c290 update 8000 docblocks and added test 6d87837 Update ApplicationDescription.php e969581 update hidden to public 3efa874 Update Command.php dfc1ac8 Update Command.php cd77139 Update Command.php 56a8b93 Update Command.php fb1f30c Update Command.php 1993196 Update Command.php 1add2ad Update Command.php b73f494 Update ApplicationDescription.php 8d0262f Update Command.php b423ab4 Add hidden field
2 parents 5e63ad0 + 746dab3 commit 043ccd5

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

src/Symfony/Component/Console/Command/Command.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Command
3434
private $processTitle;
3535
private $aliases = array();
3636
private $definition;
37+
private $public = true;
3738
private $help;
3839
private $description;
3940
private $ignoreValidationErrors = false;
@@ -446,6 +447,26 @@ public function getName()
446447
return $this->name;
447448
}
448449

450+
/**
451+
* @param bool $public Whether the command should be publicly shown or not.
452+
*
453+
* @return Command The current instance
454+
*/
455+
public function setPublic($public)
456+
{
457+
$this->public = (bool) $public;
458+
459+
return $this;
460+
}
461+
462+
/**
463+
* @return bool Whether the command should be publicly shown or not.
464+
*/
465+
public function isPublic()
466+
{
467+
return $this->public;
468+
}
469+
449470
/**
450471
* Sets the description for the command.
451472
*

src/Symfony/Component/Console/Descriptor/ApplicationDescription.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ private function inspectApplication()
112112

113113
/** @var Command $command */
114114
foreach ($commands as $name => $command) {
115-
if (!$command->getName()) {
115+
if (!$command->getName() || !$command->isPublic()) {
116116
continue;
117117
}
118118

src/Symfony/Component/Console/Tests/Fixtures/DescriptorApplication2.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ public function __construct()
2020
parent::__construct('My Symfony application', 'v1.0');
2121
$this->add(new DescriptorCommand1());
2222
$this->add(new DescriptorCommand2());
23+
$this->add(new DescriptorCommand3());
2324
}
2425
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Console\Tests\Fixtures;
13+
14+
use Symfony\Component\Console\Command\Command;
15+
16+
class DescriptorCommand3 extends Command
17+
{
18+
protected function configure()
19+
{
20+
$this
21+
->setName('descriptor:command3')
22+
->setDescription('command 3 description')
23+
->setHelp('command 3 help')
24+
->setPublic(false)
25+
;
26+
}
27+
}

0 commit comments

Comments
 (0)
0