Created
March 21, 2019 10:05
-
-
Save kanian/79cee42acf3a5da230e2987cb52ecc51 to your computer and use it in GitHub Desktop.
Container Factory Composition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//.. | |
class Container implements ContainerInterface | |
{ | |
//.. | |
public function get($dependency) | |
{ | |
if (!$this->has($dependency)) { | |
throw new DependencyNotRegisteredException($dependency); | |
} | |
$entry = $this->instances[$dependency]; | |
if ($entry instanceof Closure) { // We use closures in order to enable factory composition | |
return $entry($this); | |
} | |
return $this->concretize($entry); | |
} | |
//.. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment