Skip to content

Commit

Permalink
feature #23887 [Console] Allow commands to provide a default name for…
Browse files Browse the repository at this point in the history
… compile time registration (chalasr, nicolas-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[Console] Allow commands to provide a default name for compile time registration

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #23796
| License       | MIT
| Doc PR        | symfony/symfony-docs#8147

Commits
-------

eda7d42 [Console] Add protected static $defaultName to set the default name of a Command
5d9ae6b [Console] Allow commands to provide a default name for compile time registration
  • Loading branch information
fabpot committed Aug 24, 2017
2 parents 481e31c + eda7d42 commit 67abb80
Show file tree
Hide file tree
Showing 32 changed files with 130 additions and 45 deletions.
3 changes: 2 additions & 1 deletion src/Symfony/Bridge/Twig/Command/DebugCommand.php
Expand Up @@ -26,6 +26,8 @@
*/
class DebugCommand extends Command
{
protected static $defaultName = 'debug:twig';

private $twig;

/**
Expand Down Expand Up @@ -66,7 +68,6 @@ protected function getTwigEnvironment()
protected function configure()
{
$this
->setName('debug:twig')
->setDefinition(array(
new InputArgument('filter', InputArgument::OPTIONAL, 'Show details for all entries matching this filter'),
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (text or json)', 'text'),
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Bridge/Twig/Command/LintCommand.php
Expand Up @@ -31,6 +31,8 @@
*/
class LintCommand extends Command
{
protected static $defaultName = 'lint:twig';

private $twig;

/**
Expand Down Expand Up @@ -71,7 +73,6 @@ protected function getTwigEnvironment()
protected function configure()
{
$this
->setName('lint:twig')
->setDescription('Lints a template and outputs encountered errors')
->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format', 'txt')
->addArgument('filename', InputArgument::IS_ARRAY)
Expand Down
5 changes: 3 additions & 2 deletions src/Symfony/Bridge/Twig/composer.json
Expand Up @@ -33,13 +33,14 @@
"symfony/security": "~2.8|~3.0|~4.0",
"symfony/security-acl": "~2.8|~3.0",
"symfony/stopwatch": "~2.8|~3.0|~4.0",
"symfony/console": "~2.8|~3.0|~4.0",
"symfony/console": "~3.4|~4.0",
"symfony/var-dumper": "~2.8.10|~3.1.4|~3.2|~4.0",
"symfony/expression-language": "~2.8|~3.0|~4.0",
"symfony/web-link": "~3.3|~4.0"
},
"conflict": {
"symfony/form": "<3.2.10|~3.3,<3.3.3"
"symfony/form": "<3.2.10|~3.3,<3.3.3",
"symfony/console": "<3.4"
},
"suggest": {
"symfony/finder": "",
Expand Down
7 changes: 3 additions & 4 deletions src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php
Expand Up @@ -28,15 +28,14 @@
*/
class AboutCommand extends ContainerAwareCommand
{
protected static $defaultName = 'about';

/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('about')
->setDescription('Displays information about the current project')
;
$this->setDescription('Displays information about the current project');
}

/**
Expand Down
Expand Up @@ -35,6 +35,8 @@ class AssetsInstallCommand extends ContainerAwareCommand
const METHOD_ABSOLUTE_SYMLINK = 'absolute symlink';
const METHOD_RELATIVE_SYMLINK = 'relative symlink';

protected static $defaultName = 'assets:install';

private $filesystem;

/**
Expand All @@ -61,7 +63,6 @@ public function __construct($filesystem = null)
protected function configure()
{
$this
->setName('assets:install')
->setDefinition(array(
new InputArgument('target', InputArgument::OPTIONAL, 'The target directory', 'public'),
))
Expand Down
Expand Up @@ -32,6 +32,8 @@
*/
class CacheClearCommand extends ContainerAwareCommand
{
protected static $defaultName = 'cache:clear';

private $cacheClearer;
private $filesystem;
private $warning;
Expand Down Expand Up @@ -62,7 +64,6 @@ public function __construct($cacheClearer = null, Filesystem $filesystem = null)
protected function configure()
{
$this
->setName('cache:clear')
->setDefinition(array(
new InputOption('no-warmup', '', InputOption::VALUE_NONE, 'Do not warm up the cache'),
new InputOption('no-optional-warmers', '', InputOption::VALUE_NONE, 'Skip optional cache warmers (faster)'),
Expand Down
Expand Up @@ -25,6 +25,8 @@
*/
final class CachePoolClearCommand extends ContainerAwareCommand
{
protected static $defaultName = 'cache:pool:clear';

private $poolClearer;

/**
Expand All @@ -51,7 +53,6 @@ public function __construct($poolClearer = null)
protected function configure()
{
$this
->setName('cache:pool:clear')
->setDefinition(array(
new InputArgument('pools', InputArgument::IS_ARRAY | InputArgument::REQUIRED, 'A list of cache pools or cache pool clearers'),
))
Expand Down
Expand Up @@ -24,6 +24,8 @@
*/
final class CachePoolPruneCommand extends Command
{
protected static $defaultName = 'cache:pool:prune';

private $pools;

/**
Expand All @@ -42,7 +44,6 @@ public function __construct($pools)
protected function configure()
{
$this
->setName('cache:pool:prune')
->setDescription('Prune cache pools')
->setHelp(<<<'EOF'
The <info>%command.name%</info> command deletes all expired items from all pruneable pools.
Expand Down
Expand Up @@ -26,6 +26,8 @@
*/
class CacheWarmupCommand extends ContainerAwareCommand
{
protected static $defaultName = 'cache:warmup';

private $cacheWarmer;

/**
Expand All @@ -52,7 +54,6 @@ public function __construct($cacheWarmer = null)
protected function configure()
{
$this
->setName('cache:warmup')
->setDefinition(array(
new InputOption('no-optional-warmers', '', InputOption::VALUE_NONE, 'Skip optional cache warmers (faster)'),
))
Expand Down
Expand Up @@ -28,13 +28,14 @@
*/
class ConfigDebugCommand extends AbstractConfigCommand
{
protected static $defaultName = 'debug:config';

/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('debug:config')
->setDefinition(array(
new InputArgument('name', InputArgument::OPTIONAL, 'The bundle name or the extension alias'),
new InputArgument('path', InputArgument::OPTIONAL, 'The configuration option path'),
Expand Down
Expand Up @@ -30,13 +30,14 @@
*/
class ConfigDumpReferenceCommand extends AbstractConfigCommand
{
protected static $defaultName = 'config:dump-reference';

/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('config:dump-reference')
->setDefinition(array(
new InputArgument('name', InputArgument::OPTIONAL, 'The Bundle name or the extension alias'),
new InputArgument('path', InputArgument::OPTIONAL, 'The configuration option path'),
Expand Down
Expand Up @@ -32,6 +32,8 @@
*/
class ContainerDebugCommand extends ContainerAwareCommand
{
protected static $defaultName = 'debug:container';

/**
* @var ContainerBuilder|null
*/
Expand All @@ -43,7 +45,6 @@ class ContainerDebugCommand extends ContainerAwareCommand
protected function configure()
{
$this
->setName('debug:container')
->setDefinition(array(
new InputArgument('name', InputArgument::OPTIONAL, 'A service name (foo)'),
new InputOption('show-private', null, InputOption::VALUE_NONE, 'Used to show public *and* private services'),
Expand Down
Expand Up @@ -28,6 +28,7 @@
*/
class EventDispatcherDebugCommand extends ContainerAwareCommand
{
protected static $defaultName = 'debug:event-dispatcher';
private $dispatcher;

/**
Expand All @@ -54,7 +55,6 @@ public function __construct($dispatcher = null)
protected function configure()
{
$this
->setName('debug:event-dispatcher')
->setDefinition(array(
new InputArgument('event', InputArgument::OPTIONAL, 'An event name'),
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'),
Expand Down
Expand Up @@ -32,6 +32,7 @@
*/
class RouterDebugCommand extends ContainerAwareCommand
{
protected static $defaultName = 'debug:router';
private $router;

/**
Expand Down Expand Up @@ -79,7 +80,6 @@ public function isEnabled()
protected function configure()
{
$this
->setName('debug:router')
->setDefinition(array(
new InputArgument('name', InputArgument::OPTIONAL, 'A route name'),
new InputOption('show-controllers', null, InputOption::VALUE_NONE, 'Show assigned controllers in overview'),
Expand Down
Expand Up @@ -29,6 +29,8 @@
*/
class RouterMatchCommand extends ContainerAwareCommand
{
protected static $defaultName = 'router:match';

private $router;

/**
Expand Down Expand Up @@ -76,7 +78,6 @@ public function isEnabled()
protected function configure()
{
$this
->setName('router:match')
->setDefinition(array(
new InputArgument('path_info', InputArgument::REQUIRED, 'A path info'),
new InputOption('method', null, InputOption::VALUE_REQUIRED, 'Sets the HTTP method'),
Expand Down
Expand Up @@ -40,6 +40,8 @@ class TranslationDebugCommand extends ContainerAwareCommand
const MESSAGE_UNUSED = 1;
const MESSAGE_EQUALS_FALLBACK = 2;

protected static $defaultName = 'debug:translation';

private $translator;
private $loader;
private $extractor;
Expand Down Expand Up @@ -72,7 +74,6 @@ public function __construct($translator = null, TranslationLoader $loader = null
protected function configure()
{
$this
->setName('debug:translation')
->setDefinition(array(
new InputArgument('locale', InputArgument::REQUIRED, 'The locale'),
new InputArgument('bundle', InputArgument::OPTIONAL, 'The bundle name or directory where to load the messages, defaults to app/Resources folder'),
Expand Down
Expand Up @@ -33,6 +33,8 @@
*/
class TranslationUpdateCommand extends ContainerAwareCommand
{
protected static $defaultName = 'translation:update';

private $writer;
private $loader;
private $extractor;
Expand Down Expand Up @@ -68,7 +70,6 @@ public function __construct($writer = null, TranslationLoader $loader = null, Ex
protected function configure()
{
$this
->setName('translation:update')
->setDefinition(array(
new InputArgument('locale', InputArgument::REQUIRED, 'The locale'),
new InputArgument('bundle', InputArgument::OPTIONAL, 'The bundle name or directory where to load the messages, defaults to app/Resources folder'),
Expand Down
Expand Up @@ -25,6 +25,8 @@
*/
class WorkflowDumpCommand extends ContainerAwareCommand
{
protected static $defaultName = 'workflow:dump';

/**
* {@inheritdoc}
*
Expand All @@ -41,7 +43,6 @@ public function isEnabled()
protected function configure()
{
$this
->setName('workflow:dump')
->setDefinition(array(
new InputArgument('name', InputArgument::REQUIRED, 'A workflow name'),
new InputArgument('marking', InputArgument::IS_ARRAY, 'A marking (a list of places)'),
Expand Down
Expand Up @@ -24,6 +24,8 @@
*/
class XliffLintCommand extends BaseLintCommand
{
protected static $defaultName = 'lint:xliff';

public function __construct($name = null, $directoryIteratorProvider = null, $isReadableProvider = null)
{
if (func_num_args()) {
Expand Down
Expand Up @@ -23,6 +23,8 @@
*/
class YamlLintCommand extends BaseLintCommand
{
protected static $defaultName = 'lint:yaml';

public function __construct($name = null, $directoryIteratorProvider = null, $isReadableProvider = null)
{
if (func_num_args()) {
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Bundle/SecurityBundle/Command/InitAclCommand.php
Expand Up @@ -27,6 +27,8 @@
*/
class InitAclCommand extends ContainerAwareCommand
{
protected static $defaultName = 'init:acl';

private $connection;
private $schema;

Expand Down Expand Up @@ -70,7 +72,6 @@ public function isEnabled()
protected function configure()
{
$this
->setName('init:acl')
->setDescription('Mounts ACL tables in the database')
->setHelp(<<<'EOF'
The <info>%command.name%</info> command mounts ACL tables in the database.
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Bundle/SecurityBundle/Command/SetAclCommand.php
Expand Up @@ -32,6 +32,8 @@
*/
class SetAclCommand extends ContainerAwareCommand
{
protected static $defaultName = 'acl:set';

private $provider;

/**
Expand Down Expand Up @@ -80,7 +82,6 @@ public function isEnabled()
protected function configure()
{
$this
->setName('acl:set')
->setDescription('Sets ACL for objects')
->setHelp(<<<EOF
The <info>%command.name%</info> command sets ACL.
Expand Down
Expand Up @@ -19,7 +19,6 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder;
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
use Symfony\Component\Security\Core\User\User;
Expand All @@ -33,6 +32,8 @@
*/
class UserPasswordEncoderCommand extends ContainerAwareCommand
{
protected static $defaultName = 'security:encode-password';

private $encoderFactory;
private $userClasses;

Expand All @@ -54,7 +55,6 @@ public function __construct(EncoderFactoryInterface $encoderFactory = null, arra
protected function configure()
{
$this
->setName('security:encode-password')
->setDescription('Encodes a password.')
->addArgument('password', InputArgument::OPTIONAL, 'The plain password to encode.')
->addArgument('user-class', InputArgument::OPTIONAL, 'The User entity class path associated with the encoder used to encode the password.')
Expand Down
Expand Up @@ -20,7 +20,6 @@
* file that was distributed with this source code.
*/
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\SecurityBundle\Command\InitAclCommand;
use Symfony\Bundle\SecurityBundle\Command\SetAclCommand;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
Expand Down Expand Up @@ -170,7 +169,6 @@ private function getApplication()
$kernel->boot();

$application = new Application($kernel);
$application->add(new InitAclCommand($kernel->getContainer()->get('security.acl.dbal.connection'), $kernel->getContainer()->get('security.acl.dbal.schema')));

$initAclCommand = $application->find('init:acl');
$initAclCommandTester = new CommandTester($initAclCommand);
Expand Down

0 comments on commit 67abb80

Please sign in to comment.