1 | <?php |
||
14 | final class Container implements ContainerInterface |
||
15 | { |
||
16 | private $instances = []; |
||
17 | private $items = []; |
||
18 | |||
19 | /** |
||
20 | * Finds an entry of the container by its identifier and returns it. |
||
21 | * |
||
22 | * @param string $id Identifier of the entry to look for. |
||
23 | * |
||
24 | * @throws NotFoundException No entry was found for **this** identifier. |
||
25 | * |
||
26 | * @return mixed Entry. |
||
27 | */ |
||
28 | 3 | public function get($id) |
|
40 | |||
41 | /** |
||
42 | * Check if the container can return an entry for the given identifier. |
||
43 | * |
||
44 | * `has($id)` returning true does not mean that `get($id)` will not throw an exception. |
||
45 | * It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`. |
||
46 | * |
||
47 | * @param string $id Identifier of the entry to look for. |
||
48 | * |
||
49 | * @return bool Returns true if the container can return an entry for the given identifier. |
||
50 | * Returns false otherwise. |
||
51 | */ |
||
52 | 2 | public function has($id) |
|
56 | |||
57 | /** |
||
58 | * Set entry into the container. |
||
59 | * |
||
60 | * @param string $id Identifier of the entry to look for. |
||
61 | * @param mixed $entry Entry which should be returned |
||
62 | * |
||
63 | * @return self Instance of the self for the fluent interface. |
||
64 | */ |
||
65 | 3 | public function set($id, $entry) : Container |
|
73 | |||
74 | // ------------ PRIVATE METHODS |
||
75 | |||
76 | /** |
||
77 | * Create instance of the class |
||
78 | * |
||
79 | * @param string $id Identifier of the entry to look for. |
||
80 | * |
||
81 | * @return mixed Instance of the entry |
||
82 | */ |
||
83 | 2 | private function createInstance(string $id) |
|
89 | |||
90 | /** |
||
91 | * Check if the container can return an entry for the given identifier. |
||
92 | * |
||
93 | * `has($id)` returning true does not mean that `get($id)` will not throw an exception. |
||
94 | * It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`. |
||
95 | * |
||
96 | * @param string $id Identifier of the entry to look for. |
||
97 | * |
||
98 | * @return bool Returns true if the container can return an entry for the given identifier. |
||
99 | * Returns false otherwise. |
||
100 | */ |
||
101 | 5 | private function hasEntry(string $id) : bool |
|
105 | } |
||
106 |