Skip to content

Commit

Permalink
#565 Compile recursively all references found during compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
mnapoli committed Jan 9, 2018
1 parent 251ecae commit 7f8f2e2
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Compiler.php
Expand Up @@ -55,6 +55,11 @@ class Compiler
*/
private $autowiringEnabled;

/**
* @var string[]
*/
private $foundReferences = [];

/**
* Compile the container.
*
Expand Down Expand Up @@ -93,6 +98,21 @@ public function compile(
$this->compileDefinition($entryName, $definition);
}

foreach ($this->foundReferences as $entryName) {
$definition = $definitionSource->getDefinition($entryName);
if (!$definition) {
// We do not throw a `NotFound` exception here because the dependency
// could be defined at runtime
continue;
}
// Check that the definition can be compiled
$errorMessage = $this->isCompilable($definition);
if ($errorMessage !== true) {
continue;
}
$this->compileDefinition($entryName, $definition);
}

$this->containerClass = $className;
$this->containerParentClass = $parentClassName;

Expand Down Expand Up @@ -128,6 +148,7 @@ private function compileDefinition(string $entryName, Definition $definition) :
case $definition instanceof Reference:
$targetEntryName = $definition->getTargetEntryName();
$code = 'return $this->delegateContainer->get(' . $this->compileValue($targetEntryName) . ');';
$this->foundReferences[$targetEntryName] = $targetEntryName;
break;
case $definition instanceof StringDefinition:
$entryName = $this->compileValue($definition->getName());
Expand Down

0 comments on commit 7f8f2e2

Please sign in to comment.