symfony/symfony — pull request #7466 by fabpot (2013-03-24 10:41:58+00:00)
Title: Console dispatcher

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

refs #1884, #1929

This is an alternative implementation for adding events to console applications.

This implementation has the following features:

* Available for anyone using the Console component and it is not tied to
FrameworkBundle (this is important as one thing we are trying to solve is
email sending from a command, and frameworks like Silex using the Console
component needs a solution too);

* Non-intrusive as the current code has not been changed (except for renaming
an internal variable that was wrongly named -- so that's not strictly needed
for this PR)

* The new DispatchableApplication class also works without a dispatcher,
falling back to the regular behavior. That makes easy to create applications
that can benefit from a dispatcher when available, but can still work
otherwise.

* Besides the *before* and *after* events, there is also an *exception* event
that is dispatched whenever an exception is thrown.

* Each event is quite powerful and can manipulate the input, the output, but
also the command to be executed.