zendframework/zf2 — pull request #5637 by devosc (2013-12-22 03:58:33+00:00)
Title: [ZF3] [WIP] Event Manager and MVC Events

*Objectives*
* One main EM, similar to the other *Managers*; Other EM instances can be created by providing their own factory.
* Moved functionality of the EM into a PriorityQueueListener class
* Events invoke the listener via their __invoke method. This allows them to decide how to handle the response of a listener, e.g set a specific event property, i.e. setRouteMatch(). The return value of the event's invoke method will indicate whether to stop propagating the event.
* Event listeners can be assigned to events via the application configuration file

See https://github.com/devosc/zf2/tree/Events/library/Zend/Framework/EventManager

*Mvc Events*
By utilizing event and listener invoke methods each of the Mvc Events (and Listeners) are separate objects and their dependencies and results are a lot easier to determine and work with.

*Controllers as Listeners*
In this PR, controllers are attached to the EM for the controller.dispatch event, meaning one controller per action.

*Configuration*
```
'event_manager' => [
'listeners' => [
'mvc.bootstrap' => [
'Listener\Bootstrap',
],
'mvc.route' => [
'Listener\Route',
'Listener\Route\Module',
],
'mvc.dispatch' => [
'Listener\Dispatch',
],
'mvc.dispatch.error' => [
'Listener\View\Exception',
'Listener\View\Model',
'Listener\Route\NotFound'
],
'mvc.controller.dispatch' => [
'Listener\View\Model',
'Listener\View\Template',
],
'mvc.render' => [
'Listener\Render',
],
'mvc.render.error' => [
'Listener\View\Exception',
'Listener\View\Model'
],
'mvc.response' => [
'Listener\Response\Http',
'Listener\Response\Php',
'Listener\Response\Console',
'Listener\Response\Stream',
],
'mvc.application' => [
'Listener\Mvc\Bootstrap',
'Listener\Mvc\Route',
'Listener\Mvc\Dispatch',
'Listener\Mvc\Render',
'Listener\Mvc\Response'
],
'view.renderer' => [
//'Listener\View\Render\Json',
'Listener\View\Renderer'
],
'view.response' => [
//'Listener\View\Render\Json',
'Listener\View\Renderer'
]
],
],
```
```
class Application
{
public function run()
{
$sm = $this->getServiceManager();
$em = $this->getEventManager();

$event = new MvcEvent;

$event->setEventTarget($this)
->setServiceManager($sm)
->setEventManager($em);

$em->trigger($event);
}
}
```