1 | <?php |
||
12 | class DependencyContainer implements ContainerInterface |
||
13 | { |
||
14 | protected $injectors = []; |
||
15 | |||
16 | /** |
||
17 | * Constructor |
||
18 | */ |
||
19 | 10 | public function __construct() |
|
31 | |||
32 | /** |
||
33 | * check if for $interface there is an existing service to inject |
||
34 | * |
||
35 | * @param $interface |
||
36 | * @return bool |
||
37 | */ |
||
38 | 8 | protected function hasServiceFor($interface) |
|
42 | |||
43 | /** |
||
44 | * gets a service instance for $interface - singletoned! |
||
45 | * |
||
46 | * @param string $interface |
||
47 | * @return mixed |
||
48 | */ |
||
49 | 4 | protected function getServiceInstanceFor($interface) |
|
53 | |||
54 | /** |
||
55 | * register an service implementation as a singleton (shared instance) |
||
56 | * |
||
57 | * @param $interface |
||
58 | * @param callable $implementation |
||
59 | * @throws AlreadyRegisteredException |
||
60 | */ |
||
61 | 10 | public function register($interface, callable $implementation) |
|
77 | |||
78 | /** |
||
79 | * register a service implementation as a factory |
||
80 | * |
||
81 | * @param $interface |
||
82 | * @param callable $implementation |
||
83 | * @throws AlreadyRegisteredException |
||
84 | */ |
||
85 | 2 | public function registerFactory($interface, callable $implementation) |
|
93 | |||
94 | /** |
||
95 | * @param string $classname fully qualified classname |
||
96 | * @return object |
||
97 | * @throws NotFoundException |
||
98 | * @throws \ReflectionException |
||
99 | */ |
||
100 | 8 | public function get($classname) |
|
147 | |||
148 | /** |
||
149 | * Returns true if the container can return an entry for the given identifier. |
||
150 | * Returns false otherwise. |
||
151 | * |
||
152 | * `has($id)` returning true does not mean that `get($id)` will not throw an exception. |
||
153 | * It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`. |
||
154 | * |
||
155 | * @param string $id Identifier of the entry to look for. |
||
156 | * |
||
157 | * @return bool |
||
158 | */ |
||
159 | 6 | public function has($id) |
|
170 | } |
||
171 |