|
21 | 21 | use Zend\ServiceManager\Exception\ServiceNotCreatedException;
|
22 | 22 | use Zend\ServiceManager\Exception\ServiceNotFoundException;
|
23 | 23 |
|
24 |
| -use function \array_merge; |
25 | 24 | use function \array_merge_recursive;
|
26 | 25 | use function \class_exists;
|
27 | 26 | use function \get_class;
|
@@ -133,6 +132,13 @@ class ServiceManager implements ServiceLocatorInterface
|
133 | 132 | */
|
134 | 133 | protected $sharedByDefault = true;
|
135 | 134 |
|
| 135 | + /** |
| 136 | + * Service manager was already configured? |
| 137 | + * |
| 138 | + * @var bool |
| 139 | + */ |
| 140 | + protected $configured = false; |
| 141 | + |
136 | 142 | /**
|
137 | 143 | * Cached abstract factories from string.
|
138 | 144 | *
|
@@ -360,9 +366,8 @@ public function configure(array $config)
|
360 | 366 |
|
361 | 367 | if (isset($config['aliases'])) {
|
362 | 368 | $this->aliases = $config['aliases'] + $this->aliases;
|
363 |
| - } |
364 |
| - |
365 |
| - if (! empty($this->aliases)) { |
| 369 | + $this->mapAliasesToTargets(); |
| 370 | + } elseif (! $this->configured && ! empty($this->aliases)) { |
366 | 371 | $this->mapAliasesToTargets();
|
367 | 372 | }
|
368 | 373 |
|
@@ -391,6 +396,8 @@ public function configure(array $config)
|
391 | 396 | $this->resolveInitializers($config['initializers']);
|
392 | 397 | }
|
393 | 398 |
|
| 399 | + $this->configured = true; |
| 400 | + |
394 | 401 | return $this;
|
395 | 402 | }
|
396 | 403 |
|
@@ -782,7 +789,7 @@ private function createAliasesAndFactoriesForInvokables(array $invokables)
|
782 | 789 | */
|
783 | 790 | private function validateServiceNames(array $config)
|
784 | 791 | {
|
785 |
| - if ($this->allowOverride) { |
| 792 | + if ($this->allowOverride || ! $this->configured) { |
786 | 793 | return;
|
787 | 794 | }
|
788 | 795 |
|
|
0 commit comments