Skip to content

Commit e8c7385

Browse files
committed
Merge branch 'hotfix/serviceconfig-merge-order' of https://github.com/EvanDotPro/zf2 into hotfix/modulemanager-service-config-order
2 parents 52bbc07 + c9959a7 commit e8c7385

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

library/Zend/ModuleManager/Listener/ServiceListener.php

+6-12
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,19 @@ public function addServiceManager($serviceManager, $key, $moduleInterface, $meth
7979
(string) $serviceManager
8080
));
8181
}
82+
8283
$this->serviceManagers[$smKey] = array(
8384
'service_manager' => $serviceManager,
8485
'config_key' => $key,
8586
'module_class_interface' => $moduleInterface,
8687
'module_class_method' => $method,
8788
'configuration' => array(),
8889
);
90+
91+
if ($key === 'service_manager' && $this->defaultServiceConfig) {
92+
$this->serviceManagers[$smKey]['configuration']['default_config'] = $this->defaultServiceConfig;
93+
}
94+
8995
return $this;
9096
}
9197

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

177-
if ($this->defaultServiceConfig) {
178-
$defaultConfig = array('service_manager' => $this->defaultServiceConfig);
179-
}
180-
181183
foreach ($this->serviceManagers as $key => $sm) {
182-
183-
if (isset($defaultConfig[$sm['config_key']])
184-
&& is_array($defaultConfig[$sm['config_key']])
185-
&& !empty($defaultConfig[$sm['config_key']])
186-
) {
187-
$this->serviceManagers[$key]['configuration']['default_config'] = $defaultConfig[$sm['config_key']];
188-
}
189-
190184
if (isset($config[$sm['config_key']])
191185
&& is_array($config[$sm['config_key']])
192186
&& !empty($config[$sm['config_key']])

tests/Zend/ModuleManager/Listener/ServiceListenerTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ public function testModuleReturningTraversableConfiguresServiceManager()
123123
$this->assertServiceManagerIsConfigured();
124124
}
125125

126+
public function testModuleServiceConfigOverridesGlobalConfig()
127+
{
128+
$this->listener = new ServiceListener($this->services, array('aliases' => array('foo' => 'bar')));
129+
$this->listener->addServiceManager($this->services, 'service_manager', 'Zend\ModuleManager\Feature\ServiceProviderInterface', 'getServiceConfig');
130+
$config = array('aliases' => array('foo' => 'baz'));
131+
$module = new TestAsset\ServiceProviderModule($config);
132+
$this->event->setModule($module);
133+
$this->listener->onLoadModule($this->event);
134+
$this->listener->onLoadModulesPost($this->event);
135+
$this->assertAttributeEquals($config['aliases'], 'aliases', $this->services, "aliases assertion failed - module config did not override main config");
136+
}
137+
126138
public function testModuleReturningServiceConfigConfiguresServiceManager()
127139
{
128140
$config = $this->getServiceConfig();

0 commit comments

Comments
 (0)