wip toward lvl9

This commit is contained in:
Fabio Ivona
2021-11-18 01:01:56 +01:00
parent d4a8a3ec37
commit 7bcd3ebaee
8 changed files with 39 additions and 7 deletions

View File

@ -41,11 +41,13 @@ final class Container
*/
public function get(string $id)
{
if (array_key_exists($id, $this->instances)) {
return $this->instances[$id];
if (!array_key_exists($id, $this->instances)) {
$this->instances[$id] = $this->build($id);
}
$this->instances[$id] = $this->build($id);
if (!is_object($this->instances[$id])) {
throw ShouldNotHappen::fromMessage('Cannot resolve a non-object from container');
}
return $this->instances[$id];
}