Skip to content

Commit

Permalink
Merge branch 'hotfix/serviceconfig-merge-order' of https://github.com…
Browse files Browse the repository at this point in the history
…/EvanDotPro/zf2 into hotfix/modulemanager-service-config-order
  • Loading branch information
weierophinney committed Jul 23, 2012
2 parents 52bbc07 + c9959a7 commit e8c7385
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
18 changes: 6 additions & 12 deletions library/Zend/ModuleManager/Listener/ServiceListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,19 @@ public function addServiceManager($serviceManager, $key, $moduleInterface, $meth
(string) $serviceManager
));
}

$this->serviceManagers[$smKey] = array(
'service_manager' => $serviceManager,
'config_key' => $key,
'module_class_interface' => $moduleInterface,
'module_class_method' => $method,
'configuration' => array(),
);

if ($key === 'service_manager' && $this->defaultServiceConfig) {
$this->serviceManagers[$smKey]['configuration']['default_config'] = $this->defaultServiceConfig;
}

return $this;
}

Expand Down Expand Up @@ -174,19 +180,7 @@ public function onLoadModulesPost(ModuleEvent $e)
$configListener = $e->getConfigListener();
$config = $configListener->getMergedConfig(false);

if ($this->defaultServiceConfig) {
$defaultConfig = array('service_manager' => $this->defaultServiceConfig);
}

foreach ($this->serviceManagers as $key => $sm) {

if (isset($defaultConfig[$sm['config_key']])
&& is_array($defaultConfig[$sm['config_key']])
&& !empty($defaultConfig[$sm['config_key']])
) {
$this->serviceManagers[$key]['configuration']['default_config'] = $defaultConfig[$sm['config_key']];
}

if (isset($config[$sm['config_key']])
&& is_array($config[$sm['config_key']])
&& !empty($config[$sm['config_key']])
Expand Down
12 changes: 12 additions & 0 deletions tests/Zend/ModuleManager/Listener/ServiceListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ public function testModuleReturningTraversableConfiguresServiceManager()
$this->assertServiceManagerIsConfigured();
}

public function testModuleServiceConfigOverridesGlobalConfig()
{
$this->listener = new ServiceListener($this->services, array('aliases' => array('foo' => 'bar')));
$this->listener->addServiceManager($this->services, 'service_manager', 'Zend\ModuleManager\Feature\ServiceProviderInterface', 'getServiceConfig');
$config = array('aliases' => array('foo' => 'baz'));
$module = new TestAsset\ServiceProviderModule($config);
$this->event->setModule($module);
$this->listener->onLoadModule($this->event);
$this->listener->onLoadModulesPost($this->event);
$this->assertAttributeEquals($config['aliases'], 'aliases', $this->services, "aliases assertion failed - module config did not override main config");
}

public function testModuleReturningServiceConfigConfiguresServiceManager()
{
$config = $this->getServiceConfig();
Expand Down

0 comments on commit e8c7385

Please sign in to comment.