Skip to content
This repository was archived by the owner on Feb 6, 2020. It is now read-only.

Commit c8faa39

Browse files
committed
Hotfix #279
1 parent 16817e1 commit c8faa39

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/ServiceManager.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use function spl_object_hash;
3535
use function sprintf;
3636
use function trigger_error;
37+
use Zend\Stdlib\ArrayUtils;
3738

3839
/**
3940
* Service Manager.
@@ -362,7 +363,7 @@ public function configure(array $config)
362363
}
363364

364365
if (isset($config['delegators'])) {
365-
$this->delegators = array_merge_recursive($this->delegators, $config['delegators']);
366+
$this->delegators = ArrayUtils::merge($this->delegators, $config['delegators']);
366367
}
367368

368369
if (isset($config['shared'])) {
@@ -383,7 +384,7 @@ public function configure(array $config)
383384
// If lazy service configuration was provided, reset the lazy services
384385
// delegator factory.
385386
if (isset($config['lazy_services']) && ! empty($config['lazy_services'])) {
386-
$this->lazyServices = array_merge_recursive($this->lazyServices, $config['lazy_services']);
387+
$this->lazyServices = ArrayUtils::merge($this->lazyServices, $config['lazy_services']);
387388
$this->lazyServicesDelegator = null;
388389
}
389390

test/ServiceManagerTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use DateTime;
1111
use PHPUnit\Framework\TestCase;
1212
use Psr\Container\ContainerInterface;
13+
use ReflectionObject;
1314
use stdClass;
1415
use Zend\ServiceManager\Factory\AbstractFactoryInterface;
1516
use Zend\ServiceManager\Factory\FactoryInterface;
@@ -363,4 +364,34 @@ public function testResolvedAliasNoMatchingAbstractFactoryReturnsFalse()
363364

364365
self::assertFalse($serviceManager->has('Alias'));
365366
}
367+
368+
/**
369+
* Hotfix #279
370+
* @see https://github.com/zendframework/zend-servicemanager/issues/279
371+
*/
372+
public function testConfigureMultipleTimes()
373+
{
374+
$config = [
375+
'delegators' => [
376+
'Foo' => 'FooDelegator',
377+
],
378+
'lazy_services' => [
379+
'class_map' => [
380+
'Foo' => 'Foo',
381+
],
382+
]
383+
];
384+
385+
$serviceManager = new ServiceManager($config);
386+
$serviceManager->configure($config);
387+
388+
$ref = new ReflectionObject($serviceManager);
389+
$delegatorsProperty = $ref->getProperty('delegators');
390+
$delegatorsProperty->setAccessible(true);
391+
$lazyServicesProperty = $ref->getProperty('lazyServices');
392+
$lazyServicesProperty->setAccessible(true);
393+
394+
self::assertSame($config['delegators'], $delegatorsProperty->getValue($serviceManager));
395+
self::assertSame($config['lazy_services'], $lazyServicesProperty->getValue($serviceManager));
396+
}
366397
}

0 commit comments

Comments
 (0)