From b26a9faacc933f5c56dd1b72cc5e443627317aa4 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Fri, 28 Jul 2017 17:27:49 +0200 Subject: [PATCH 1/5] Add console events --- src/Illuminate/Console/Application.php | 32 +++++++++++++- .../Console/Events/CommandStarting.php | 35 +++++++++++++++ .../Console/Events/CommandTerminating.php | 44 +++++++++++++++++++ 3 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 src/Illuminate/Console/Events/CommandStarting.php create mode 100644 src/Illuminate/Console/Events/CommandTerminating.php diff --git a/src/Illuminate/Console/Application.php b/src/Illuminate/Console/Application.php index 820b16e63e2d..1f852f406652 100755 --- a/src/Illuminate/Console/Application.php +++ b/src/Illuminate/Console/Application.php @@ -9,7 +9,9 @@ use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Process\PhpExecutableFinder; +use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\BufferedOutput; +use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Application as SymfonyApplication; use Symfony\Component\Console\Command\Command as SymfonyCommand; use Illuminate\Contracts\Console\Application as ApplicationContract; @@ -37,6 +39,13 @@ class Application extends SymfonyApplication implements ApplicationContract */ protected static $bootstrappers = []; + /** + * The Event Dispatcher. + * + * @var \Illuminate\Contracts\Events\Dispatcher + */ + protected $events; + /** * Create a new Artisan console application. * @@ -50,14 +59,35 @@ public function __construct(Container $laravel, Dispatcher $events, $version) parent::__construct('Laravel Framework', $version); $this->laravel = $laravel; + $this->events = $events; $this->setAutoExit(false); $this->setCatchExceptions(false); - $events->dispatch(new Events\ArtisanStarting($this)); + $this->events->dispatch(new Events\ArtisanStarting($this)); $this->bootstrap(); } + /** + * {@inheritdoc} + */ + public function run(InputInterface $input = null, OutputInterface $output = null) + { + $commandName = $this->getCommandName($input); + + $this->events->fire( + new Events\CommandStarting($commandName, $input) + ); + + $exitCode = parent::run($input, $output); + + $this->events->fire( + new Events\CommandTerminating($commandName, $input, $exitCode) + ); + + return $exitCode; + } + /** * Determine the proper PHP executable. * diff --git a/src/Illuminate/Console/Events/CommandStarting.php b/src/Illuminate/Console/Events/CommandStarting.php new file mode 100644 index 000000000000..9a17a41e7e6c --- /dev/null +++ b/src/Illuminate/Console/Events/CommandStarting.php @@ -0,0 +1,35 @@ +command = $command; + $this->input = $input; + } +} diff --git a/src/Illuminate/Console/Events/CommandTerminating.php b/src/Illuminate/Console/Events/CommandTerminating.php new file mode 100644 index 000000000000..5ace2ea1472b --- /dev/null +++ b/src/Illuminate/Console/Events/CommandTerminating.php @@ -0,0 +1,44 @@ +command = $command; + $this->input = $input; + $this->exitCode = $exitCode; + } +} From 7ebcdf15429bbc09a6bf409358e972bac4315e05 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Sun, 30 Jul 2017 09:42:50 +0200 Subject: [PATCH 2/5] Rename event. --- src/Illuminate/Console/Application.php | 2 +- .../Events/{CommandTerminating.php => CommandFinished.php} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/Illuminate/Console/Events/{CommandTerminating.php => CommandFinished.php} (96%) diff --git a/src/Illuminate/Console/Application.php b/src/Illuminate/Console/Application.php index 1f852f406652..c518904b7cc0 100755 --- a/src/Illuminate/Console/Application.php +++ b/src/Illuminate/Console/Application.php @@ -82,7 +82,7 @@ public function run(InputInterface $input = null, OutputInterface $output = null $exitCode = parent::run($input, $output); $this->events->fire( - new Events\CommandTerminating($commandName, $input, $exitCode) + new Events\CommandFinished($commandName, $input, $exitCode) ); return $exitCode; diff --git a/src/Illuminate/Console/Events/CommandTerminating.php b/src/Illuminate/Console/Events/CommandFinished.php similarity index 96% rename from src/Illuminate/Console/Events/CommandTerminating.php rename to src/Illuminate/Console/Events/CommandFinished.php index 5ace2ea1472b..16dffa624622 100644 --- a/src/Illuminate/Console/Events/CommandTerminating.php +++ b/src/Illuminate/Console/Events/CommandFinished.php @@ -4,7 +4,7 @@ use Symfony\Component\Console\Input\InputInterface; -class CommandTerminating +class CommandFinished { /** * The command name. From 545c30d9158fd79126b3d336a97f4c7a07739fac Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Mon, 31 Jul 2017 11:17:47 +0200 Subject: [PATCH 3/5] Add command output to the Finished event. --- src/Illuminate/Console/Application.php | 2 +- src/Illuminate/Console/Events/CommandFinished.php | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Console/Application.php b/src/Illuminate/Console/Application.php index c518904b7cc0..a0e26f741e69 100755 --- a/src/Illuminate/Console/Application.php +++ b/src/Illuminate/Console/Application.php @@ -82,7 +82,7 @@ public function run(InputInterface $input = null, OutputInterface $output = null $exitCode = parent::run($input, $output); $this->events->fire( - new Events\CommandFinished($commandName, $input, $exitCode) + new Events\CommandFinished($commandName, $input, $output, $exitCode) ); return $exitCode; diff --git a/src/Illuminate/Console/Events/CommandFinished.php b/src/Illuminate/Console/Events/CommandFinished.php index 16dffa624622..ef2520d58c83 100644 --- a/src/Illuminate/Console/Events/CommandFinished.php +++ b/src/Illuminate/Console/Events/CommandFinished.php @@ -3,6 +3,7 @@ namespace Illuminate\Console\Events; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; class CommandFinished { @@ -27,18 +28,26 @@ class CommandFinished */ public $exitCode; + /** + * The command output. + * + * @var \Symfony\Component\Console\Output\OutputInterface + */ + protected $output; + /** * Create a new event instance. * * @param string $command * @param \Symfony\Component\Console\Input\InputInterface $input + * @param \Symfony\Component\Console\Output\OutputInterface $output * @param int $exitCode - * @return void */ - public function __construct($command, InputInterface $input, $exitCode) + public function __construct($command, InputInterface $input, OutputInterface $output, $exitCode) { $this->command = $command; $this->input = $input; + $this->output = $output; $this->exitCode = $exitCode; } } From 60f13b7ad26b6bddcb3fbe34257e8739e4a9c957 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Mon, 31 Jul 2017 16:14:29 +0200 Subject: [PATCH 4/5] Also add output to CommandStarting. --- src/Illuminate/Console/Application.php | 2 +- .../Console/Events/CommandFinished.php | 14 +++++++------- .../Console/Events/CommandStarting.php | 16 +++++++++++++--- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/Illuminate/Console/Application.php b/src/Illuminate/Console/Application.php index a0e26f741e69..5b8c413ef868 100755 --- a/src/Illuminate/Console/Application.php +++ b/src/Illuminate/Console/Application.php @@ -76,7 +76,7 @@ public function run(InputInterface $input = null, OutputInterface $output = null $commandName = $this->getCommandName($input); $this->events->fire( - new Events\CommandStarting($commandName, $input) + new Events\CommandStarting($commandName, $input, $output) ); $exitCode = parent::run($input, $output); diff --git a/src/Illuminate/Console/Events/CommandFinished.php b/src/Illuminate/Console/Events/CommandFinished.php index ef2520d58c83..bfb090918649 100644 --- a/src/Illuminate/Console/Events/CommandFinished.php +++ b/src/Illuminate/Console/Events/CommandFinished.php @@ -17,23 +17,23 @@ class CommandFinished /** * The console input. * - * @var string + * @var \Symfony\Component\Console\Input\InputInterface */ public $input; /** - * The command exit code. + * The command output. * - * @var int + * @var \Symfony\Component\Console\Output\OutputInterface */ - public $exitCode; + protected $output; /** - * The command output. + * The command exit code. * - * @var \Symfony\Component\Console\Output\OutputInterface + * @var int */ - protected $output; + public $exitCode; /** * Create a new event instance. diff --git a/src/Illuminate/Console/Events/CommandStarting.php b/src/Illuminate/Console/Events/CommandStarting.php index 9a17a41e7e6c..d3fc3d956428 100644 --- a/src/Illuminate/Console/Events/CommandStarting.php +++ b/src/Illuminate/Console/Events/CommandStarting.php @@ -3,6 +3,7 @@ namespace Illuminate\Console\Events; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; class CommandStarting { @@ -16,20 +17,29 @@ class CommandStarting /** * The console input. * - * @var string + * @var \Symfony\Component\Console\Input\InputInterface */ public $input; + /** + * The command output. + * + * @var \Symfony\Component\Console\Output\OutputInterface + */ + protected $output; + /** * Create a new event instance. * * @param string $command * @param \Symfony\Component\Console\Input\InputInterface $input - * @return void + * @param \Symfony\Component\Console\Output\OutputInterface $output + * @param int $exitCode */ - public function __construct($command, InputInterface $input) + public function __construct($command, InputInterface $input, OutputInterface $output) { $this->command = $command; $this->input = $input; + $this->output = $output; } } From 019886fec3994277c907b4adde4fc60dda306309 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Mon, 31 Jul 2017 16:18:20 +0200 Subject: [PATCH 5/5] Update docblocks. --- src/Illuminate/Console/Events/CommandFinished.php | 4 ++-- src/Illuminate/Console/Events/CommandStarting.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Console/Events/CommandFinished.php b/src/Illuminate/Console/Events/CommandFinished.php index bfb090918649..38effb9e06ac 100644 --- a/src/Illuminate/Console/Events/CommandFinished.php +++ b/src/Illuminate/Console/Events/CommandFinished.php @@ -17,14 +17,14 @@ class CommandFinished /** * The console input. * - * @var \Symfony\Component\Console\Input\InputInterface + * @var \Symfony\Component\Console\Input\InputInterface|null */ public $input; /** * The command output. * - * @var \Symfony\Component\Console\Output\OutputInterface + * @var \Symfony\Component\Console\Output\OutputInterface|null */ protected $output; diff --git a/src/Illuminate/Console/Events/CommandStarting.php b/src/Illuminate/Console/Events/CommandStarting.php index d3fc3d956428..e6b590b9a604 100644 --- a/src/Illuminate/Console/Events/CommandStarting.php +++ b/src/Illuminate/Console/Events/CommandStarting.php @@ -17,14 +17,14 @@ class CommandStarting /** * The console input. * - * @var \Symfony\Component\Console\Input\InputInterface + * @var \Symfony\Component\Console\Input\InputInterface|null */ public $input; /** * The command output. * - * @var \Symfony\Component\Console\Output\OutputInterface + * @var \Symfony\Component\Console\Output\OutputInterface|null */ protected $output;