Skip to content

Commit

Permalink
zendframework#6266 - Optimized and named the `EventManagerAwareInitia…
Browse files Browse the repository at this point in the history
…lizer`
  • Loading branch information
Ocramius committed May 20, 2014
1 parent 8334555 commit d9544fb
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions library/Zend/Mvc/Service/ServiceManagerConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ class ServiceManagerConfig extends Config
*/
public function __construct(array $configuration = array())
{
$this->initializers = array(
'EventManagerAwareInitializer' => function ($instance, ServiceManager $serviceManager) {
if ($instance instanceof EventManagerAwareInterface) {
$eventManager = $instance->getEventManager();

if ($eventManager instanceof EventManagerInterface) {
$eventManager->setSharedManager($serviceManager->get('SharedEventManager'));
} else {
$instance->setEventManager($serviceManager->get('EventManager'));
}
}
},
);

$configuration = array_replace_recursive(array(
'invokables' => $this->invokables,
'factories' => $this->factories,
Expand All @@ -116,19 +130,7 @@ public function __construct(array $configuration = array())
*/
public function configureServiceManager(ServiceManager $serviceManager)
{
parent::configureServiceManager($serviceManager);

$serviceManager->addInitializer(function ($instance) use ($serviceManager) {
if ($instance instanceof EventManagerAwareInterface) {
if ($instance->getEventManager() instanceof EventManagerInterface) {
$instance->getEventManager()->setSharedManager(
$serviceManager->get('SharedEventManager')
);
} else {
$instance->setEventManager($serviceManager->get('EventManager'));
}
}
});
parent::configureServiceManager($serviceManager);

$serviceManager->addInitializer(function ($instance) use ($serviceManager) {
if ($instance instanceof ServiceManagerAwareInterface) {
Expand Down

0 comments on commit d9544fb

Please sign in to comment.