Hotfix/3650 #3651

merged 2 commits into from Feb 4, 2013

3 participants

Zend Framework member

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


This patch was tested by me and fixed #3650 successfully.

weierophinney added some commits Feb 1, 2013
@weierophinney weierophinney [#3650] Do not re-inject EM instance
- If the controller already composes an EM instance, do not re-inject
  it. This allows factories to inject an EM instance and attach
@weierophinney weierophinney [#3650] Fix failing test
- Override getEventManager() in test asset so that we can test
  injection, as parent was lazy initializing an EM instance.
@ezimuel ezimuel merged commit 93d7089 into zendframework:master Feb 4, 2013

1 check passed

Details default The Travis build passed
@Slamdunk Slamdunk referenced this pull request in zendframework/zend-eventmanager Jun 24, 2015

Refactor #2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment