From ee3e298c5d59f6eaedb3a0c6126f6d7f392b4d28 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 20 Jan 2010 15:58:25 +0100 Subject: [PATCH] [Console] added a ways to add common behaviors to commands extending a common command --- .../Components/Console/Command/Command.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Symfony/Components/Console/Command/Command.php b/src/Symfony/Components/Console/Command/Command.php index 013b239cbf..30ccec9c47 100644 --- a/src/Symfony/Components/Console/Command/Command.php +++ b/src/Symfony/Components/Console/Command/Command.php @@ -104,6 +104,25 @@ class Command { } + /** + * Initializes the command just after the input has been validated. + * + * This is mainly useful when a lot of commands extends one main command + * where some things need to be initialized based on the input arguments and options. + * + * @param InputInterface $input An InputInterface instance + * @param OutputInterface $output An OutputInterface instance + */ + protected function initialize(InputInterface $input, OutputInterface $output) + { + } + + /** + * Runs the command. + * + * @param InputInterface $input An InputInterface instance + * @param OutputInterface $output An OutputInterface instance + */ public function run(InputInterface $input, OutputInterface $output) { // add the application arguments and options @@ -122,6 +141,8 @@ class Command } } + $this->initialize($input, $output); + if ($input->isInteractive()) { $this->interact($input, $output);