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

Commit 0e6eeb7

Browse files
author
fhein
committed
Added source code documentation to doSetAlias to explain alias
resolution.
1 parent 82d0ee1 commit 0e6eeb7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/ServiceManager.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,6 @@ public function setShared($name, $flag)
520520
*
521521
* @param string[]|Initializer\InitializerInterface[]|callable[] $initializers
522522
*
523-
* @return void
524523
*/
525524
private function resolveInitializer($initializer)
526525
{
@@ -904,15 +903,21 @@ private function validateConfig(array $config)
904903
*/
905904
private function doSetAlias($alias, $target)
906905
{
906+
// $target is either an alias or something else
907+
// if it is an alias, resolve it
907908
$this->aliases[$alias] =
908909
isset($this->aliases[$target]) ? $this->aliases[$target] : $target;
909910

911+
// a self-referencing alias indicates a cycle
910912
if ($alias === $this->aliases[$alias]) {
911913
throw CyclicAliasException::fromCyclicAlias($alias, $this->aliases);
912914
}
913915

916+
// finally we have to check if existing incomplete alias definitions
917+
// exist which can get resolved by the new alias
914918
if (in_array($alias, $this->aliases)) {
915919
$r = array_intersect($this->aliases, [ $alias ]);
920+
// found some, resolve them
916921
foreach ($r as $name => $service) {
917922
$this->aliases[$name] = $target;
918923
}

0 commit comments

Comments
 (0)