From 35c6c6a4dd320da463d27d511832d20fd145aad4 Mon Sep 17 00:00:00 2001 From: Francesco Levorato Date: Wed, 11 Apr 2012 23:35:46 +0200 Subject: [PATCH 01/15] Addedd events for CLI commands --- .../FrameworkBundle/Console/Application.php | 16 +++++- .../Compiler/RegisterConsoleListenersPass.php | 53 +++++++++++++++++++ .../FrameworkBundle/FrameworkBundle.php | 2 + 3 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/RegisterConsoleListenersPass.php diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php index c091443949975..51a2895009f9f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php @@ -67,15 +67,27 @@ public function doRun(InputInterface $input, OutputInterface $output) { $this->registerCommands(); + + /** + * @var $eventDispatcher \Symfony\Component\EventDispatcher\EventDispatcher + */ + $dispatcher = $this->kernel->getContainer()->get('event_dispatcher'); + + $dispatcher->dispatch('console.init'); + if (true === $input->hasParameterOption(array('--shell', '-s'))) { $shell = new Shell($this); $shell->setProcessIsolation($input->hasParameterOption(array('--process-isolation'))); $shell->run(); - return 0; + $statusCode = 0; + } else { + $statusCode = parent::doRun($input, $output); } - return parent::doRun($input, $output); + $dispatcher->dispatch('console.init'); + + return $statusCode; } protected function registerCommands() diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/RegisterConsoleListenersPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/RegisterConsoleListenersPass.php new file mode 100644 index 0000000000000..8e9a49b5f4c09 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/RegisterConsoleListenersPass.php @@ -0,0 +1,53 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler; + +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; + +/** + * RegisterConsoleListenersPass process tags for console listeners. + * + * @author Francesco Levorato + */ +class RegisterConsoleListenersPass implements CompilerPassInterface +{ + public function process(ContainerBuilder $container) + { + if (!$container->hasDefinition('event_dispatcher')) { + return; + } + + $definition = $container->getDefinition('event_dispatcher'); + + foreach ($container->findTaggedServiceIds('console.event_listener') as $id => $events) { + foreach ($events as $event) { + $priority = isset($event['priority']) ? $event['priority'] : 0; + + if (!isset($event['event'])) { + throw new \InvalidArgumentException(sprintf('Service "%s" must define the "event" attribute on "console.event_listener" tags.', $id)); + } + + if (!isset($event['method'])) { + $event['method'] = 'on'.preg_replace(array( + '/(?<=\b)[a-z]/ie', + '/[^a-z0-9]/i' + ), array('strtoupper("\\0")', ''), $event['event']); + } + + $definition->addMethodCall('addListenerService', array($event['event'], array($id, $event['method']), $priority)); + } + } + + + } +} \ No newline at end of file diff --git a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php index 544f2026baf27..efaaa7cb06ad3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php @@ -15,6 +15,7 @@ use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddValidatorInitializersPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\FormPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TemplatingPass; +use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RegisterConsoleListenersPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RegisterKernelListenersPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RoutingResolverPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass; @@ -53,6 +54,7 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new RoutingResolverPass()); $container->addCompilerPass(new ProfilerPass()); + $container->addCompilerPass(new RegisterConsoleListenersPass(), PassConfig::TYPE_AFTER_REMOVING); $container->addCompilerPass(new RegisterKernelListenersPass(), PassConfig::TYPE_AFTER_REMOVING); $container->addCompilerPass(new TemplatingPass()); $container->addCompilerPass(new AddConstraintValidatorsPass()); From 41949fb24838da0cd5e33b27f6a7ddc5e77464b6 Mon Sep 17 00:00:00 2001 From: Francesco Levorato Date: Thu, 12 Apr 2012 00:11:34 +0200 Subject: [PATCH 02/15] Removed extra comment --- src/Symfony/Bundle/FrameworkBundle/Console/Application.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php index 51a2895009f9f..554c9b8178999 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php @@ -67,10 +67,6 @@ public function doRun(InputInterface $input, OutputInterface $output) { $this->registerCommands(); - - /** - * @var $eventDispatcher \Symfony\Component\EventDispatcher\EventDispatcher - */ $dispatcher = $this->kernel->getContainer()->get('event_dispatcher'); $dispatcher->dispatch('console.init'); From 6d97975ecb3c80e1b61539f90b3e4afedfae16a8 Mon Sep 17 00:00:00 2001 From: Francesco Levorato Date: Thu, 12 Apr 2012 00:20:59 +0200 Subject: [PATCH 03/15] fixed event name and not triggering events for shell --- .../Bundle/FrameworkBundle/Console/Application.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php index 554c9b8178999..68884f47d7835 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php @@ -67,22 +67,22 @@ public function doRun(InputInterface $input, OutputInterface $output) { $this->registerCommands(); - $dispatcher = $this->kernel->getContainer()->get('event_dispatcher'); - - $dispatcher->dispatch('console.init'); if (true === $input->hasParameterOption(array('--shell', '-s'))) { $shell = new Shell($this); $shell->setProcessIsolation($input->hasParameterOption(array('--process-isolation'))); $shell->run(); - $statusCode = 0; - } else { - $statusCode = parent::doRun($input, $output); + return 0; } + $dispatcher = $this->kernel->getContainer()->get('event_dispatcher'); $dispatcher->dispatch('console.init'); + $statusCode = parent::doRun($input, $output); + + $dispatcher->dispatch('console.exit'); + return $statusCode; } From a2ca8f92dbb8b811d24de7841d62a8231f1c31f4 Mon Sep 17 00:00:00 2001 From: Francesco Levorato Date: Thu, 12 Apr 2012 00:31:26 +0200 Subject: [PATCH 04/15] remove extra line --- src/Symfony/Bundle/FrameworkBundle/Console/Application.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php index 68884f47d7835..3499406e32dec 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php @@ -67,7 +67,6 @@ public function doRun(InputInterface $input, OutputInterface $output) { $this->registerCommands(); - if (true === $input->hasParameterOption(array('--shell', '-s'))) { $shell = new Shell($this); $shell->setProcessIsolation($input->hasParameterOption(array('--process-isolation'))); From 9e05e75734d9393bccc21caacf5b45f99e759fb1 Mon Sep 17 00:00:00 2001 From: Francesco Levorato Date: Mon, 16 Apr 2012 22:34:52 +0200 Subject: [PATCH 05/15] renaming variable --- src/Symfony/Bundle/FrameworkBundle/Console/Application.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php index 3499406e32dec..79f294cb932d6 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php @@ -78,11 +78,11 @@ public function doRun(InputInterface $input, OutputInterface $output) $dispatcher = $this->kernel->getContainer()->get('event_dispatcher'); $dispatcher->dispatch('console.init'); - $statusCode = parent::doRun($input, $output); + $exitCode = parent::doRun($input, $output); $dispatcher->dispatch('console.exit'); - return $statusCode; + return $exitCode; } protected function registerCommands() From c15265d240e8ec51013b56dff1997a02af63f679 Mon Sep 17 00:00:00 2001 From: Francesco Levorato Date: Tue, 17 Apr 2012 07:45:56 +0200 Subject: [PATCH 06/15] removing unuesful RegisterConsoleListenersPass --- .../Compiler/RegisterConsoleListenersPass.php | 53 ------------------- .../FrameworkBundle/FrameworkBundle.php | 2 - 2 files changed, 55 deletions(-) delete mode 100644 src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/RegisterConsoleListenersPass.php diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/RegisterConsoleListenersPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/RegisterConsoleListenersPass.php deleted file mode 100644 index 8e9a49b5f4c09..0000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/RegisterConsoleListenersPass.php +++ /dev/null @@ -1,53 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler; - -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; - -/** - * RegisterConsoleListenersPass process tags for console listeners. - * - * @author Francesco Levorato - */ -class RegisterConsoleListenersPass implements CompilerPassInterface -{ - public function process(ContainerBuilder $container) - { - if (!$container->hasDefinition('event_dispatcher')) { - return; - } - - $definition = $container->getDefinition('event_dispatcher'); - - foreach ($container->findTaggedServiceIds('console.event_listener') as $id => $events) { - foreach ($events as $event) { - $priority = isset($event['priority']) ? $event['priority'] : 0; - - if (!isset($event['event'])) { - throw new \InvalidArgumentException(sprintf('Service "%s" must define the "event" attribute on "console.event_listener" tags.', $id)); - } - - if (!isset($event['method'])) { - $event['method'] = 'on'.preg_replace(array( - '/(?<=\b)[a-z]/ie', - '/[^a-z0-9]/i' - ), array('strtoupper("\\0")', ''), $event['event']); - } - - $definition->addMethodCall('addListenerService', array($event['event'], array($id, $event['method']), $priority)); - } - } - - - } -} \ No newline at end of file diff --git a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php index efaaa7cb06ad3..544f2026baf27 100644 --- a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php @@ -15,7 +15,6 @@ use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddValidatorInitializersPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\FormPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TemplatingPass; -use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RegisterConsoleListenersPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RegisterKernelListenersPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RoutingResolverPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass; @@ -54,7 +53,6 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new RoutingResolverPass()); $container->addCompilerPass(new ProfilerPass()); - $container->addCompilerPass(new RegisterConsoleListenersPass(), PassConfig::TYPE_AFTER_REMOVING); $container->addCompilerPass(new RegisterKernelListenersPass(), PassConfig::TYPE_AFTER_REMOVING); $container->addCompilerPass(new TemplatingPass()); $container->addCompilerPass(new AddConstraintValidatorsPass()); From b1de5cad4e82c7f7021f8b8ace455b82986a5895 Mon Sep 17 00:00:00 2001 From: Francesco Levorato Date: Tue, 17 Apr 2012 08:28:38 +0200 Subject: [PATCH 07/15] Events for console commands execution --- .../FrameworkBundle/Console/Application.php | 13 ++- .../FrameworkBundle/Console/ConsoleEvents.php | 46 +++++++++++ .../Console/Event/ConsoleInitEvent.php | 81 +++++++++++++++++++ .../Console/Event/ConsoleTerminateEvent.php | 44 ++++++++++ 4 files changed, 180 insertions(+), 4 deletions(-) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Console/ConsoleEvents.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleInitEvent.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleTerminateEvent.php diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php index 79f294cb932d6..ccf5de8983a73 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php @@ -17,7 +17,9 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\HttpKernel\Kernel; -use Symfony\Component\HttpKernel\Bundle\Bundle; +use Symfony\Bundle\FrameworkBundle\Console\ConsoleEvents; +use Symfony\Bundle\FrameworkBundle\Console\Event\ConsoleInitEvent; +use Symfony\Bundle\FrameworkBundle\Console\Event\ConsoleTerminateEvent; /** * Application. @@ -76,11 +78,14 @@ public function doRun(InputInterface $input, OutputInterface $output) } $dispatcher = $this->kernel->getContainer()->get('event_dispatcher'); - $dispatcher->dispatch('console.init'); - $exitCode = parent::doRun($input, $output); + $initEvent = new ConsoleInitEvent($input, $output); + $dispatcher->dispatch(ConsoleEvents::INIT, $initEvent); - $dispatcher->dispatch('console.exit'); + $exitCode = parent::doRun($initEvent->getInput(), $initEvent->getOutput()); + + $terminateEvent = new ConsoleTerminateEvent($exitCode); + $dispatcher->dispatch(ConsoleEvents::TERMINATE, $terminateEvent); return $exitCode; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/ConsoleEvents.php b/src/Symfony/Bundle/FrameworkBundle/Console/ConsoleEvents.php new file mode 100644 index 0000000000000..9fd7ef59dc9d6 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Console/ConsoleEvents.php @@ -0,0 +1,46 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Console; + +/** + * Contains all events thrown during Console commands execution + * + * @author Francesco Levorato + * + */ +final class ConsoleEvents +{ + /** + * The INIT event allows you to attach listeners before any command is + * executed by the console. It also allows you to modify the input and output + * before they are handled to the command. + * + * The event listener method receives a Symfony\Bundle\FrameworkBundle\Console\Event\ConsoleInitEvent + * instance. + * + * @var string + */ + const INIT = 'console.init'; + + + /** + * The TERMINATE event allows you to attach listeners after a command is + * executed by the console. + * + * The event listener method receives a Symfony\Bundle\FrameworkBundle\Console\Event\ConsoleTerminateEvent + * instance. + * + * @var string + */ + const TERMINATE = 'console.terminate'; + +} \ No newline at end of file diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleInitEvent.php b/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleInitEvent.php new file mode 100644 index 0000000000000..9b3130b4ccdee --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleInitEvent.php @@ -0,0 +1,81 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Console\Event; + +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\HttpKernel\Event\KernelEvent; + +/** + * Allows to edit input and output of a command. + * + * Call setOutput if you need to modify the output object. The propagation of + * this event is stopped as soon as a new output is set. + * + * @author Francesco Levorato + */ +class ConsoleInitEvent extends KernelEvent +{ + + /** + * The input received by the command. + * + * @var Symfony\Component\Console\Input\InputInterface + */ + private $input; + + /** + * The output object used by the command. + * + * @var Symfony\Component\Console\Output\OutputInterface + */ + private $output; + + function __construct(InputInterface $input, OutputInterface $output) + { + $this->input = $input; + $this->output = $output; + } + + /** + * Sets an output object and stops event propagation + * + * @param Symfony\Component\Console\Output\OutputInterface $output + */ + public function setOutput(OutputInterface $output) + { + $this->output = $output; + + $this->stopPropagation(); + } + + /** + * Returns the input object + * + * @return Symfony\Component\Console\Input\InputInterface + */ + public function getInput() + { + return $this->input; + } + + /** + * Returns the output object + * + * @return Symfony\Component\Console\Output\OutputInterface + */ + public function getOutput() + { + return $this->output; + } + +} \ No newline at end of file diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleTerminateEvent.php b/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleTerminateEvent.php new file mode 100644 index 0000000000000..656714baed0f9 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleTerminateEvent.php @@ -0,0 +1,44 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Console\Event; + +/** + * Allows to receive the exit code of a command after its execution. + * + * @author Francesco Levorato + */ +class ConsoleTerminateEvent extends KernelEvent +{ + + /** + * The exit code of the command. + * + * @var integer + */ + private $exitCode; + + function __construct($exitCode) + { + $this->exitCode = $exitCode; + } + + /** + * Returns the exit code. + * + * @return integer + */ + public function getExitCode() + { + return $this->exitCode; + } + +} From c476c9855fdc51db6b4b0109b7e6c61bd3719b2e Mon Sep 17 00:00:00 2001 From: Francesco Levorato Date: Tue, 24 Apr 2012 17:05:00 +0200 Subject: [PATCH 08/15] extending from event and not kernel event --- .../FrameworkBundle/Console/Event/ConsoleInitEvent.php | 5 +++-- .../Console/Event/ConsoleTerminateEvent.php | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleInitEvent.php b/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleInitEvent.php index 9b3130b4ccdee..b7503bc870fbb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleInitEvent.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleInitEvent.php @@ -13,7 +13,8 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\HttpKernel\Event\KernelEvent; +use Symfony\Component\EventDispatcher\Event; + /** * Allows to edit input and output of a command. @@ -23,7 +24,7 @@ * * @author Francesco Levorato */ -class ConsoleInitEvent extends KernelEvent +class ConsoleInitEvent extends Event { /** diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleTerminateEvent.php b/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleTerminateEvent.php index 656714baed0f9..65ae0b1793f6a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleTerminateEvent.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleTerminateEvent.php @@ -11,12 +11,15 @@ namespace Symfony\Bundle\FrameworkBundle\Console\Event; +use Symfony\Component\EventDispatcher\Event; + + /** * Allows to receive the exit code of a command after its execution. * * @author Francesco Levorato */ -class ConsoleTerminateEvent extends KernelEvent +class ConsoleTerminateEvent extends Event { /** @@ -33,7 +36,7 @@ function __construct($exitCode) /** * Returns the exit code. - * + * * @return integer */ public function getExitCode() From b3c3acfebc4cfccbdd2ef37ca1488708837ae4f7 Mon Sep 17 00:00:00 2001 From: Francesco Levorato Date: Tue, 24 Apr 2012 17:05:26 +0200 Subject: [PATCH 09/15] fix public keyword missing --- .../Bundle/FrameworkBundle/Console/Event/ConsoleInitEvent.php | 2 +- .../FrameworkBundle/Console/Event/ConsoleTerminateEvent.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleInitEvent.php b/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleInitEvent.php index b7503bc870fbb..2a8fb783d9626 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleInitEvent.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleInitEvent.php @@ -41,7 +41,7 @@ class ConsoleInitEvent extends Event */ private $output; - function __construct(InputInterface $input, OutputInterface $output) + public function __construct(InputInterface $input, OutputInterface $output) { $this->input = $input; $this->output = $output; diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleTerminateEvent.php b/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleTerminateEvent.php index 65ae0b1793f6a..be81bb15ce417 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleTerminateEvent.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleTerminateEvent.php @@ -29,7 +29,7 @@ class ConsoleTerminateEvent extends Event */ private $exitCode; - function __construct($exitCode) + public function __construct($exitCode) { $this->exitCode = $exitCode; } From 7745d7e2b3fde09715e4f3f4e4a0fde8c9a4ea3d Mon Sep 17 00:00:00 2001 From: Francesco Levorato Date: Sat, 11 Aug 2012 18:53:08 +0200 Subject: [PATCH 10/15] integrating feedback from stof --- .../FrameworkBundle/Console/Application.php | 2 +- .../Console/Event/ConsoleInitEvent.php | 31 ++----------------- 2 files changed, 4 insertions(+), 29 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php index ccf5de8983a73..6ef0de06fe2ff 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php @@ -82,7 +82,7 @@ public function doRun(InputInterface $input, OutputInterface $output) $initEvent = new ConsoleInitEvent($input, $output); $dispatcher->dispatch(ConsoleEvents::INIT, $initEvent); - $exitCode = parent::doRun($initEvent->getInput(), $initEvent->getOutput()); + $exitCode = parent::doRun($input, $output); $terminateEvent = new ConsoleTerminateEvent($exitCode); $dispatcher->dispatch(ConsoleEvents::TERMINATE, $terminateEvent); diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleInitEvent.php b/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleInitEvent.php index 2a8fb783d9626..328bb65d8bc81 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleInitEvent.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleInitEvent.php @@ -17,28 +17,15 @@ /** - * Allows to edit input and output of a command. - * - * Call setOutput if you need to modify the output object. The propagation of - * this event is stopped as soon as a new output is set. + * Allows to inspect input and output of a command. * * @author Francesco Levorato */ class ConsoleInitEvent extends Event { - /** - * The input received by the command. - * - * @var Symfony\Component\Console\Input\InputInterface - */ private $input; - /** - * The output object used by the command. - * - * @var Symfony\Component\Console\Output\OutputInterface - */ private $output; public function __construct(InputInterface $input, OutputInterface $output) @@ -47,22 +34,10 @@ public function __construct(InputInterface $input, OutputInterface $output) $this->output = $output; } - /** - * Sets an output object and stops event propagation - * - * @param Symfony\Component\Console\Output\OutputInterface $output - */ - public function setOutput(OutputInterface $output) - { - $this->output = $output; - - $this->stopPropagation(); - } - /** * Returns the input object * - * @return Symfony\Component\Console\Input\InputInterface + * @return InputInterface */ public function getInput() { @@ -72,7 +47,7 @@ public function getInput() /** * Returns the output object * - * @return Symfony\Component\Console\Output\OutputInterface + * @return OutputInterface */ public function getOutput() { From 55b0ed2ea26ef8f65f3d8167a82e937ef2c8374e Mon Sep 17 00:00:00 2001 From: Francesco Levorato Date: Sat, 11 Aug 2012 19:03:20 +0200 Subject: [PATCH 11/15] renaming ConsoleInitEvent --- .../Bundle/FrameworkBundle/Console/ConsoleEvents.php | 7 +++---- .../Event/{ConsoleInitEvent.php => ConsoleEvent.php} | 5 ++--- .../Console/Event/ConsoleTerminateEvent.php | 5 +---- 3 files changed, 6 insertions(+), 11 deletions(-) rename src/Symfony/Bundle/FrameworkBundle/Console/Event/{ConsoleInitEvent.php => ConsoleEvent.php} (96%) diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/ConsoleEvents.php b/src/Symfony/Bundle/FrameworkBundle/Console/ConsoleEvents.php index 9fd7ef59dc9d6..9751b97109f65 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/ConsoleEvents.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/ConsoleEvents.php @@ -24,23 +24,22 @@ final class ConsoleEvents * executed by the console. It also allows you to modify the input and output * before they are handled to the command. * - * The event listener method receives a Symfony\Bundle\FrameworkBundle\Console\Event\ConsoleInitEvent + * The event listener method receives a \Symfony\Bundle\FrameworkBundle\Console\Event\ConsoleEvent * instance. * * @var string */ const INIT = 'console.init'; - /** * The TERMINATE event allows you to attach listeners after a command is * executed by the console. * - * The event listener method receives a Symfony\Bundle\FrameworkBundle\Console\Event\ConsoleTerminateEvent + * The event listener method receives a \Symfony\Bundle\FrameworkBundle\Console\Event\ConsoleTerminateEvent * instance. * * @var string */ const TERMINATE = 'console.terminate'; -} \ No newline at end of file +} diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleInitEvent.php b/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleEvent.php similarity index 96% rename from src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleInitEvent.php rename to src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleEvent.php index 328bb65d8bc81..d9dd723180332 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleInitEvent.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleEvent.php @@ -15,13 +15,12 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\EventDispatcher\Event; - /** * Allows to inspect input and output of a command. * * @author Francesco Levorato */ -class ConsoleInitEvent extends Event +class ConsoleEvent extends Event { private $input; @@ -54,4 +53,4 @@ public function getOutput() return $this->output; } -} \ No newline at end of file +} diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleTerminateEvent.php b/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleTerminateEvent.php index be81bb15ce417..b5d7b3eddc348 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleTerminateEvent.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleTerminateEvent.php @@ -11,15 +11,12 @@ namespace Symfony\Bundle\FrameworkBundle\Console\Event; -use Symfony\Component\EventDispatcher\Event; - - /** * Allows to receive the exit code of a command after its execution. * * @author Francesco Levorato */ -class ConsoleTerminateEvent extends Event +class ConsoleTerminateEvent extends ConsoleEvent { /** From 08569667e18349d4d92d74879299c74966f222d8 Mon Sep 17 00:00:00 2001 From: Francesco Levorato Date: Sun, 12 Aug 2012 19:38:11 +0200 Subject: [PATCH 12/15] fixed lost use clause --- src/Symfony/Bundle/FrameworkBundle/Console/Application.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php index 6ef0de06fe2ff..9b3184e7dae67 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php @@ -15,6 +15,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\HttpKernel\Kernel; use Symfony\Bundle\FrameworkBundle\Console\ConsoleEvents; From dbb597769a2c1fbcf61aaf9285aac671635f1656 Mon Sep 17 00:00:00 2001 From: Francesco Levorato Date: Sun, 12 Aug 2012 19:38:42 +0200 Subject: [PATCH 13/15] fixed renaming ConsoleInitEvent in ConsoleEvent --- src/Symfony/Bundle/FrameworkBundle/Console/Application.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php index 9b3184e7dae67..9cd71fcbb69c4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php @@ -19,7 +19,7 @@ use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\HttpKernel\Kernel; use Symfony\Bundle\FrameworkBundle\Console\ConsoleEvents; -use Symfony\Bundle\FrameworkBundle\Console\Event\ConsoleInitEvent; +use Symfony\Bundle\FrameworkBundle\Console\Event\ConsoleEvent; use Symfony\Bundle\FrameworkBundle\Console\Event\ConsoleTerminateEvent; /** @@ -80,7 +80,7 @@ public function doRun(InputInterface $input, OutputInterface $output) $dispatcher = $this->kernel->getContainer()->get('event_dispatcher'); - $initEvent = new ConsoleInitEvent($input, $output); + $initEvent = new ConsoleEvent($input, $output); $dispatcher->dispatch(ConsoleEvents::INIT, $initEvent); $exitCode = parent::doRun($input, $output); From bff61be663613b6358cdd704525f30add71227ff Mon Sep 17 00:00:00 2001 From: Francesco Levorato Date: Sun, 12 Aug 2012 19:39:01 +0200 Subject: [PATCH 14/15] fix tests for Console/Application --- .../Tests/Console/ApplicationTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php index 1427453b10650..478723ad8d4eb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php @@ -47,6 +47,19 @@ private function getKernel(array $bundles) ->method('getBundles') ->will($this->returnValue($bundles)) ; + $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $eventDispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); + + $container + ->expects($this->any()) + ->method('get') + ->with($this->equalTo('event_dispatcher')) + ->will($this->returnValue($eventDispatcher)); + $kernel + ->expects($this->any()) + ->method('getContainer') + ->will($this->returnValue($container)) + ; return $kernel; } From 459a4da8f82ed3a70f7484b2350a8b5e4f264890 Mon Sep 17 00:00:00 2001 From: Francesco Levorato Date: Sat, 13 Oct 2012 21:42:28 +0200 Subject: [PATCH 15/15] make ConsoleTerminateEvent receive $input and $output as constructor args --- src/Symfony/Bundle/FrameworkBundle/Console/Application.php | 2 +- .../FrameworkBundle/Console/Event/ConsoleTerminateEvent.php | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php index 9cd71fcbb69c4..e00d018905126 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php @@ -85,7 +85,7 @@ public function doRun(InputInterface $input, OutputInterface $output) $exitCode = parent::doRun($input, $output); - $terminateEvent = new ConsoleTerminateEvent($exitCode); + $terminateEvent = new ConsoleTerminateEvent($input, $output, $exitCode); $dispatcher->dispatch(ConsoleEvents::TERMINATE, $terminateEvent); return $exitCode; diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleTerminateEvent.php b/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleTerminateEvent.php index b5d7b3eddc348..9ebfbb1cf0b47 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleTerminateEvent.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Event/ConsoleTerminateEvent.php @@ -11,6 +11,9 @@ namespace Symfony\Bundle\FrameworkBundle\Console\Event; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + /** * Allows to receive the exit code of a command after its execution. * @@ -26,8 +29,9 @@ class ConsoleTerminateEvent extends ConsoleEvent */ private $exitCode; - public function __construct($exitCode) + public function __construct(InputInterface $input, OutputInterface $output, $exitCode) { + parent::__construct($input, $output); $this->exitCode = $exitCode; }