1 | <?php |
||
12 | class DependencyContainer implements ContainerInterface |
||
13 | { |
||
14 | protected $injectors = []; |
||
15 | |||
16 | /** |
||
17 | * Constructor |
||
18 | */ |
||
19 | 10 | public function __construct() |
|
39 | |||
40 | /** |
||
41 | * check if for $interface there is an existing service to inject |
||
42 | * |
||
43 | * @param $interface |
||
44 | * @return bool |
||
45 | */ |
||
46 | 8 | protected function hasServiceFor($interface) |
|
50 | |||
51 | /** |
||
52 | * gets a service instance for $interface - singletoned! |
||
53 | * |
||
54 | * @param string $interface |
||
55 | * @return mixed |
||
56 | */ |
||
57 | 4 | protected function getServiceInstanceFor($interface) |
|
61 | |||
62 | /** |
||
63 | * register an service implementation as a singleton (shared instance) |
||
64 | * |
||
65 | * @param $interface |
||
66 | * @param callable $implementation |
||
67 | * @throws AlreadyRegisteredException |
||
68 | */ |
||
69 | 10 | public function register($interface, callable $implementation) |
|
85 | |||
86 | /** |
||
87 | * register a service implementation as a factory |
||
88 | * |
||
89 | * @param $interface |
||
90 | * @param callable $implementation |
||
91 | * @throws AlreadyRegisteredException |
||
92 | */ |
||
93 | 2 | public function registerFactory($interface, callable $implementation) |
|
101 | |||
102 | /** |
||
103 | * @param string $classname fully qualified classname |
||
104 | * @return object |
||
105 | * @throws NotFoundException |
||
106 | * @throws \ReflectionException |
||
107 | */ |
||
108 | 8 | public function get($classname) |
|
143 | |||
144 | /** |
||
145 | * Returns true if the container can return an entry for the given identifier. |
||
146 | * Returns false otherwise. |
||
147 | * |
||
148 | * `has($id)` returning true does not mean that `get($id)` will not throw an exception. |
||
149 | * It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`. |
||
150 | * |
||
151 | * @param string $id Identifier of the entry to look for. |
||
152 | * |
||
153 | * @return bool |
||
154 | */ |
||
155 | 6 | public function has($id) |
|
166 | |||
167 | /** |
||
168 | * @param \ReflectionParameter $parameter |
||
169 | * @param string $classname |
||
170 | * @return mixed|object |
||
171 | * @throws NotFoundException |
||
172 | * @throws \ReflectionException |
||
173 | */ |
||
174 | 7 | private function handleReflectionParameter(\ReflectionParameter $parameter, $classname) |
|
190 | } |
||
191 |