8000 [Console] made the defaults in Application more easily customizable · Kiruban2011/symfony@95ec41b · GitHub
[go: up one dir, main page]

Skip to content

Commit 95ec41b

Browse files
committed
[Console] made the defaults in Application more easily customizable
1 parent b112ef5 commit 95ec41b

File tree

2 files changed

+49
-18
lines changed

2 files changed

+49
-18
lines changed

CHANGELOG-2.1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c
4646

4747
### Console
4848

49+
* made the defaults (helper set, commands, input definition) in Application more easily customizable
4950
* added support for the shell even if readline is not available
5051

5152
### ClassLoader

src/Symfony/Component/Console/Application.php

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,12 @@ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
7171
$this->catchExceptions = true;
7272
$this->autoExit = true;
7373
$this->commands = array();
74-
$this->helperSet = new HelperSet(array(
75-
new FormatterHelper(),
76-
new DialogHelper(),
77-
));
78-
79-
$this->add(new HelpCommand());
80-
$this->add(new ListCommand());
81-
82-
$this->definition = new InputDefinition(array(
83-
new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'),
74+
$this->helperSet = $this->getDefaultHelperSet();
75+
$this->definition = $this->getDefaultInputDefinition();
8476

85-
new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message.'),
86-
new InputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message.'),
87-
new InputOption('--verbose', '-v', InputOption::VALUE_NONE, 'Increase verbosity of messages.'),
88-
new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this program version.'),
89-
new InputOption('--ansi', '', InputOption::VALUE_NONE, 'Force ANSI output.'),
90-
new InputOption('--no-ansi', '', InputOption::VALUE_NONE, 'Disable ANSI output.'),
91-
new InputOption('--no-interaction', '-n', InputOption::VALUE_NONE, 'Do not ask any interactive question.'),
92-
));
77+
foreach ($this->getDefaultCommands() as $command) {
78+
$this->add($command);
79+
}
9380
}
9481

9582
/**
@@ -809,6 +796,49 @@ protected function getCommandName(InputInterface $input)
809796
return $input->getFirstArgument('command');
810797
}
811798

799+
/**
800+
* Gets the default input definition.
801+
*
802+
* @return InputDefinition An InputDefinition instance
803+
*/
804+
protected function getDefaultInputDefinition()
805+
{
806+
return new InputDefinition(array(
807+
new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'),
808+
809+
new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message.'),
810+
new InputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message.'),
811+
new InputOption('--verbose', '-v', InputOption::VALUE_NONE, 'Increase verbosity of messages.'),
812+
new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this program version.'),
813+
new InputOption('--ansi', '', InputOption::VALUE_NONE, 'Force ANSI output.'),
814+
new InputOption('--no-ansi', '', InputOption::VALUE_NONE, 'Disable ANSI output.'),
815+
new InputOption('--no-interaction', '-n', InputOption::VALUE_NONE, 'Do not ask any interactive question.'),
816+
));
817+
}
818+
819+
/**
820+
* Gets the default commands that should always be available.
821+
*
822+
* @return array An array of default Command instances
823+
*/
824+
protected function getDefaultCommands()
825+
{
826+
return array(new HelpCommand(), new ListCommand());
827+
}
828+
829+
/**
830+
* Gets the default helper set with the helpers that should always be available.
831+
*
832+
* @return HelperSet A HelperSet instance
833+
*/
834+
protected function getDefaultHelperSet()
835+
{
836+
return new HelperSet(array(
837+
new FormatterHelper(),
838+
new DialogHelper(),
839+
));
840+
}
841+
812842
/**
813843
* Sorts commands in alphabetical order.
814844
*

0 commit comments

Comments
 (0)
0