zendframework/zf2 — pull request #3651 by weierophinney (2013-02-01 21:13:27+00:00)
Title: Hotfix/3650

The `ControllerManager` was injecting an `EventManager` instance, even if one was available. This meant that if you attached an EM instance inside a factory, it would be overwritten -- losing any listeners attached to it.

This PR does the following:

- If an EM instance is not present, it will do as it did previously, and inject the EM instance from the parent service manager.
- If an EM instance *is* present, it will inject that instance with the shared EM instance form the parent service manager, but otherwise *not* inject a new EM instance. This feature is present because the default `AbstractController` implementation lazy-instantiates an EM instance in `getEventManager()`; since this will mean no EM instance is injected, we need to inject the `SharedEventManager` to ensure the lazy instance can tie into application listeners.

This is completely BC, as previously, a new EM instance was _always_ injected by the `ControllerManager`; there was no opportunity to opt-out if your controller was `EventManagerAware`.

Fixes #3650