zendframework/zf2 — pull request #944 by weierophinney (2012-03-19 22:00:04+00:00)
Title: Feature/eventmanager di usability

Shared Collections support for EventManager

This is a solution for usage of the StaticEventManager. Basically, it
will instead expect the following:

- Classes composing an EventManager will implement EventManagerAware,
and thus opt-in to setter injection of an EM instance
- EM instances will _not_ be shared between classes
- The EM implements the SharedEventManagerAware interface, indicating it
opts-in to setter injection of a SharedEventManager (note: not static)
- A single "SharedEventManager" will be shared between all instances of
EventManager

This commit does the following:

- Renames StaticEventCollection to SharedEventCollection
- Creates SharedEventManager, which implements all the functionality of
StaticEventManager except the singleton aspects.
- StaticEventManager now extends SharedEventManager, and simply
implements a singleton pattern.
- Introduced EventManagerAware and SharedEventManagerAware interfaces;
EventManager implements the latter.
- Adds configuration to the Bootstrap in setupLocator() to mark the EventManager
as an unshared instance.

One issue is known, however:
- Zend\Module\Listener\LocatorRegistration currently fails, as it assumes a StaticEventManager instance. As such, it cannot connect to the bootstrap event. I'm not sure what the solution for this will be -- I assume we'll need to instantiate a SharedEventManager and pass it into the Module\Manager, Mvc\Bootstrap, and potentially Mvc\Application. This will require documentation, and coordination with the skeleton application. Another alternative is to have this listener instead attach directly to the Bootstrap, and loop through the module manager. Ideas are welcome.