8000 [Console] added a ways to add common behaviors to commands extending … · Dahipster/symfony@ee3e298 · GitHub
[go: up one dir, main page]

Skip to content

Commit ee3e298

Browse files
committed
[Console] added a ways to add common behaviors to commands extending a common command
1 parent c0ee9fe commit ee3e298

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/Symfony/Components/Console/Command/Command.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,25 @@ protected function interact(InputInterface $input, OutputInterface $output)
104104
{
105105
}
106106

107+
/**
108+
* Initializes the command just after the input has been validated.
109+
*
110+
* This is mainly useful when a lot of commands extends one main command
111+
* where some things need to be initialized based on the input arguments and options.
112+
*
113+
* @param InputInterface $input An InputInterface instance
114+
* @param OutputInterface $output An OutputInterface instance
115+
*/
116+
protected function initialize(InputInterface $input, OutputInterface $output)
117+
{
118+
}
119+
120+
/**
121+
* Runs the command.
122+
*
123+
* @param InputInterface $input An InputInterface instance
124+
* @param OutputInterface $output An OutputInterface instance
125+
*/
107126
public function run(InputInterface $input, OutputInterface $output)
108127
{
109128
// add the application arguments and options
@@ -122,6 +141,8 @@ public function run(InputInterface $input, OutputInterface $output)
122141
}
123142
}
124143

144+
$this->initialize($input, $output);
145+
125146
if ($input->isInteractive())
126147
{
127148
$this->interact($input, $output);

0 commit comments

Comments
 (0)
0