Skip to content

Commit

Permalink
Merge be1cfbc into 8ecded4
Browse files Browse the repository at this point in the history
  • Loading branch information
holtkamp committed Oct 30, 2017
2 parents 8ecded4 + be1cfbc commit bf0051d
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/DI/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ class Container implements ContainerInterface, InteropContainerInterface, Factor
*/
private $definitionResolver;

/**
* Map of definitions that are already fetched / looked up.
*
* @var array
*/
private $fetchedDefinitions = [];

/**
* Array of entries being resolved. Used to avoid circular dependencies and infinite loops.
* @var array
Expand Down Expand Up @@ -116,7 +123,7 @@ public function get($name)
return $this->singletonEntries[$name];
}

$definition = $this->definitionSource->getDefinition($name);
$definition = $this->getDefinition($name);
if (! $definition) {
throw new NotFoundException("No entry or class found for '$name'");
}
Expand All @@ -131,6 +138,15 @@ public function get($name)
return $value;
}

private function getDefinition($name)
{
if(!array_key_exists($name, $this->fetchedDefinitions)){
$this->fetchedDefinitions[$name] = $this->definitionSource->getDefinition($name);
}

return $this->fetchedDefinitions[$name];
}

/**
* Build an entry of the container by its name.
*
Expand Down Expand Up @@ -159,7 +175,7 @@ public function make($name, array $parameters = [])
));
}

$definition = $this->definitionSource->getDefinition($name);
$definition = $this->getDefinition($name);
if (! $definition) {
// Try to find the entry in the singleton map
if (array_key_exists($name, $this->singletonEntries)) {
Expand Down Expand Up @@ -193,7 +209,7 @@ public function has($name)
return true;
}

$definition = $this->definitionSource->getDefinition($name);
$definition = $this->getDefinition($name);
if ($definition === null) {
return false;
}
Expand Down

0 comments on commit bf0051d

Please sign in to comment.