Last active
March 21, 2019 08:01
-
-
Save kanian/36e96d961eda99c4ba15e6bbd50bb10b to your computer and use it in GitHub Desktop.
Template for PSR-11 Compliant Container
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 | |
namespace Kanian\ContainerX; | |
use Psr\Container\ContainerInterface; | |
/** | |
* A psr-11 compliant container | |
*/ | |
class Container implements ContainerInterface | |
{ | |
public function __construct() | |
{ | |
//bootstrap code here | |
} | |
protected $instances = []; | |
public function get($dependency) | |
{ | |
if (!$this->has($dependency)) { | |
throw new DependencyNotRegisteredException($dependency); //DependencyNotRegisteredException implements NotFoundExceptionInterface | |
} | |
$entry = $this->instances[$dependency]; | |
//other necessary code here | |
//return $this->concreteInstance($entry); | |
} | |
public function has($dependency) | |
{ | |
return isset($this->instances[$dependency]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment