Total Complexity | 5 |
Total Lines | 50 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
15 | class Container implements ContainerInterface |
||
16 | { |
||
17 | use Constructor; |
||
18 | |||
19 | /** |
||
20 | * @var object[] |
||
21 | */ |
||
22 | private $instances = []; |
||
23 | |||
24 | /** |
||
25 | * @param string $id |
||
26 | * @return bool |
||
27 | */ |
||
28 | public function has($id) : bool |
||
29 | { |
||
30 | return isset($this->instances[$id]); |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * @param string $id |
||
35 | * @return object|mixed |
||
36 | */ |
||
37 | public function get($id) |
||
38 | { |
||
39 | if (isset($this->instances[$id])) { |
||
40 | return $this->instances[$id]; |
||
41 | } |
||
42 | |||
43 | throw new ObjectNotFoundException($id); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @param string $id |
||
48 | * @param object $object |
||
49 | * @return object|mixed |
||
50 | */ |
||
51 | public function set(string $id, $object) |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * @param string $class |
||
59 | * @param mixed ...$args |
||
60 | * @return object|mixed |
||
61 | */ |
||
62 | public function object(string $class, ...$args) |
||
65 | } |
||
66 | } |
||
67 |