symfony/symfony — pull request #11384 by duncan3dc (2014-07-13 10:38:50+00:00)
Title: [Console] added a way to dispatch events on any command

| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets |
| License | MIT
| Doc PR | symfony/symfony-docs#4020

Console events do not run when they are expected to.

The [documentation](http://symfony.com/doc/current/components/console/introduction.html#calling-an-existing-command) recommends the following to execute an existing command
```
$command = $this->getApplication()->find('demo:greet');
$returnCode = $command->run($input, $output);
```

Then the [events section](http://symfony.com/doc/current/components/console/events.html#the-consoleevents-command-event) states the following (emphasis mine)
*Typical Purposes: Doing something before __any__ command is run (like logging which command is going to be executed), or displaying something about the event to be executed.*

However console events are only dispatched by Application::doRunCommand(), which is used for running the main command only. Leaving no way to run an additional command and have the events dispatched.

This commit is my attempt at allowing a command to be run with events with least disruption, but I think it would be better if the events were dispatched from within the Command class. But I guess that would be a 3.0 feature