19 declare(strict_types=1);
    55         foreach ($components as $component) {
    56             foreach ($component->getInDependencies() as 
$d) {
    57                 switch (
$d->getType()) {
    65                         $this->
resolveUse($component, $disambiguation, 
$d, $components);
    71         $cycles = iterator_to_array($this->
findCycles(...$components));
    72         if (!empty($cycles)) {
    73             throw new \LogicException(
    74                 "Detected Cycles in Dependency Tree: " .
    79                             fn($v) => 
"{$v[0]->getComponentName()} ({$v[1]})",
    95         foreach ($others as $other) {
    96             if ($other->offsetExists(
"PROVIDE: " . $in->
getName())) {
    97                 if (!is_null($candidate)) {
    98                     throw new \LogicException(
    99                         "Dependency {$in->getName()} is provided (at least) twice."   103                 $candidate = $other[
"PROVIDE: " . $in->
getName()][0];
   107         if (is_null($candidate)) {
   108             throw new \LogicException(
"Could not resolve dependency for {$component->getComponentName()}: " . (
string) $in);
   116         foreach ($others as $other) {
   117             if ($other->offsetExists(
"CONTRIBUTE: " . $in->
getName())) {
   119                 foreach ($other[
"CONTRIBUTE: " . $in->
getName()] as $o) {
   130         foreach ($others as $other) {
   131             if ($other->offsetExists(
"IMPLEMENT: " . $in->
getName())) {
   133                 $candidates[] = $other[
"IMPLEMENT: " . $in->
getName()];
   137         $candidates = array_merge(...$candidates);
   139         if (empty($candidates)) {
   140             throw new \LogicException(
   141                 "Could not resolve dependency for {$component->getComponentName()}: " . (
string) $in
   145         if (count($candidates) === 1) {
   150         $preferred_class = $this->
disambiguate($component, $disambiguation, $in);
   151         if (is_null($preferred_class)) {
   152             throw new \LogicException(
   153                 "Dependency {$in->getName()} is provided (at least) twice, " .
   154                 "no disambiguation for {$component->getComponentName()}."   157         foreach ($candidates as $candidate) {
   158             if ($candidate->aux[
"class"] === $preferred_class) {
   163         throw new \LogicException(
   164             "Dependency $preferred_class for service {$in->getName()} " .
   165             "for {$component->getComponentName()} could not be located."   171         $service_name = (string) $in->
getName();
   173             if (isset($disambiguation[
$c]) && isset($disambiguation[$c][$service_name])) {
   174                 return $disambiguation[
$c][$service_name];
   185         foreach ($components as $component) {
   186             foreach ($component->getInDependencies() as $in) {
   196         if (!empty($visited) && $visited[0][0] === $component && $visited[0][1] == $in) {
   201         array_push($visited, [$component, $in]);
   203             $other = 
$out->getComponent();
   204             array_push($visited, [$component, 
$out]);
   205             foreach (
$out->getDependencies() as $next) {
 
findCyclesWith(array $visited, OfComponent $component, In $in)
 
findCycles(OfComponent ... $components)
 
resolveSeek(In $in, array &$others)
 
resolveUse(OfComponent $component, array &$disambiguation, In $in, array &$others)
 
resolvePull(OfComponent $component, In $in, array &$others)
 
A dependency where the component needs something from the world. 
 
disambiguate(OfComponent $component, array &$disambiguation, In $in)
 
addResolution(Out $other)
 
resolveDependencies(array $disambiguation, OfComponent ... $components)
Resolves dependencies of all components.