diff --git a/CHANGELOG-2.1.md b/CHANGELOG-2.1.md index 68ad3f39cf..8e3673a353 100644 --- a/CHANGELOG-2.1.md +++ b/CHANGELOG-2.1.md @@ -46,6 +46,7 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c ### Console + * made the defaults (helper set, commands, input definition) in Application more easily customizable * added support for the shell even if readline is not available ### ClassLoader diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 4a935aa070..e828c2ad6f 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -71,25 +71,12 @@ class Application $this->catchExceptions = true; $this->autoExit = true; $this->commands = array(); - $this->helperSet = new HelperSet(array( - new FormatterHelper(), - new DialogHelper(), - )); + $this->helperSet = $this->getDefaultHelperSet(); + $this->definition = $this->getDefaultInputDefinition(); - $this->add(new HelpCommand()); - $this->add(new ListCommand()); - - $this->definition = new InputDefinition(array( - new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'), - - new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message.'), - new InputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message.'), - new InputOption('--verbose', '-v', InputOption::VALUE_NONE, 'Increase verbosity of messages.'), - new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this program version.'), - new InputOption('--ansi', '', InputOption::VALUE_NONE, 'Force ANSI output.'), - new InputOption('--no-ansi', '', InputOption::VALUE_NONE, 'Disable ANSI output.'), - new InputOption('--no-interaction', '-n', InputOption::VALUE_NONE, 'Do not ask any interactive question.'), - )); + foreach ($this->getDefaultCommands() as $command) { + $this->add($command); + } } /** @@ -809,6 +796,49 @@ class Application return $input->getFirstArgument('command'); } + /** + * Gets the default input definition. + * + * @return InputDefinition An InputDefinition instance + */ + protected function getDefaultInputDefinition() + { + return new InputDefinition(array( + new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'), + + new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message.'), + new InputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message.'), + new InputOption('--verbose', '-v', InputOption::VALUE_NONE, 'Increase verbosity of messages.'), + new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this program version.'), + new InputOption('--ansi', '', InputOption::VALUE_NONE, 'Force ANSI output.'), + new InputOption('--no-ansi', '', InputOption::VALUE_NONE, 'Disable ANSI output.'), + new InputOption('--no-interaction', '-n', InputOption::VALUE_NONE, 'Do not ask any interactive question.'), + )); + } + + /** + * Gets the default commands that should always be available. + * + * @return array An array of default Command instances + */ + protected function getDefaultCommands() + { + return array(new HelpCommand(), new ListCommand()); + } + + /** + * Gets the default helper set with the helpers that should always be available. + * + * @return HelperSet A HelperSet instance + */ + protected function getDefaultHelperSet() + { + return new HelperSet(array( + new FormatterHelper(), + new DialogHelper(), + )); + } + /** * Sorts commands in alphabetical order. *