22/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
33 Container.php - Part of the container project.
44
5- © - Jitesoft 2017
5+ © - Jitesoft
66 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
77namespace Jitesoft \Container ;
88
9- use ArrayAccess ;
109use Jitesoft \Exceptions \Psr \Container \ContainerException ;
1110use Jitesoft \Exceptions \Psr \Container \NotFoundException ;
11+ use Psr \Container \ContainerExceptionInterface ;
12+ use Psr \Container \NotFoundExceptionInterface ;
1213
1314/**
1415 * Simple naive implementation of a Dependency container with constructor injection.
@@ -57,7 +58,7 @@ public function clear(): void {
5758 * @param boolean $singleton If the created object is intended to be treated as a single instance on creation.
5859 *
5960 * @return boolean
60- * @throws ContainerException Thrown in case the entry already exist.
61+ * @throws ContainerException|ContainerExceptionInterface Thrown in case the entry already exist.
6162 */
6263 public function set (string $ abstract ,
6364 mixed $ concrete ,
@@ -85,7 +86,8 @@ public function set(string $abstract,
8586 * @param mixed $concrete Concrete value to bind to the abstract value.
8687 * @param boolean $singleton If the created object is intended to be treated as a single instance on creation.
8788 *
88- * @throws NotFoundException Thrown in case the 'abstract' does not exist.
89+ * @throws NotFoundException|NotFoundExceptionInterface Thrown in case the 'abstract' does not exist.
90+ * @throws ContainerException|ContainerExceptionInterface Thrown in case entry could not be set.
8991 *
9092 * @return void
9193 */
@@ -104,13 +106,13 @@ public function rebind(string $abstract,
104106 /**
105107 * Unset a given abstract removing it from the container.
106108 *
107- * @param string $id Identifier of the value to remove entry for.
109+ * @param string|mixed $id Identifier of the value to remove entry for.
108110 *
109- * @throws NotFoundException Thrown if the abstract is not found.
111+ * @throws NotFoundException|NotFoundExceptionInterface Thrown if the abstract is not found.
110112 *
111113 * @return void
112114 */
113- public function unset (string $ id ): void {
115+ public function unset (mixed $ id ): void {
114116 if (!$ this ->has ($ id )) {
115117 throw new NotFoundException (
116118 'Could not remove the given entity because it was not set. '
@@ -125,12 +127,12 @@ public function unset(string $id): void {
125127 *
126128 * @param string|mixed $id Identifier of the entry to look for.
127129 *
128- * @throws NotFoundException No entry was found for **this** identifier.
129- * @throws ContainerException On resolve error.
130+ * @throws NotFoundException|NotFoundExceptionInterface No entry was found for **this** identifier.
131+ * @throws ContainerException|ContainerExceptionInterface On resolve error.
130132 *
131133 * @return mixed Entry.
132134 */
133- public function get ($ id ): mixed {
135+ public function get (mixed $ id ): mixed {
134136 if (array_key_exists ($ id , $ this ->bindings )) {
135137 return $ this ->bindings [$ id ]->resolve (new Injector ($ this ));
136138 }
@@ -154,7 +156,7 @@ public function get($id): mixed {
154156 *
155157 * @return boolean
156158 */
157- public function has ($ id ): bool {
159+ public function has (mixed $ id ): bool {
158160 return array_key_exists ($ id , $ this ->bindings );
159161 }
160162
@@ -163,42 +165,42 @@ public function has($id): bool {
163165 *
164166 * @return boolean
165167 */
166- public function offsetExists ($ offset ): bool {
168+ public function offsetExists (mixed $ offset ): bool {
167169 return $ this ->has ($ offset );
168170 }
169171
170172 /**
171173 * @param string|mixed $offset Offset to fetch.
172174 *
173- * @throws NotFoundException No entry was found for **this** identifier.
174- * @throws ContainerException Error while retrieving the entry.
175+ * @throws NotFoundException|NotFoundExceptionInterface No entry was found for **this** identifier.
176+ * @throws ContainerException|ContainerExceptionInterface Error while retrieving the entry.
175177 *
176178 * @return mixed
177179 */
178- public function offsetGet ($ offset ): mixed {
180+ public function offsetGet (mixed $ offset ): mixed {
179181 return $ this ->get ($ offset );
180182 }
181183
182184 /**
183185 * @param string|mixed $offset Offset to set.
184186 * @param mixed $value Value to set to the offset.
185187 *
186- * @throws ContainerException Thrown if offset does not exist.
188+ * @throws ContainerException|ContainerExceptionInterface Thrown if offset does not exist.
187189 *
188190 * @return void
189191 */
190- public function offsetSet ($ offset , $ value ): void {
192+ public function offsetSet (mixed $ offset , mixed $ value ): void {
191193 $ this ->set ($ offset , $ value );
192194 }
193195
194196 /**
195197 * @param string|mixed $offset Offset to unset
196198 *
197- * @throws NotFoundException Thrown if offset does not exist.
199+ * @throws NotFoundException|NotFoundExceptionInterface Thrown if offset does not exist.
198200 *
199201 * @return void
200202 */
201- public function offsetUnset ($ offset ): void {
203+ public function offsetUnset (mixed $ offset ): void {
202204 $ this ->unset ($ offset );
203205 }
204206
@@ -212,9 +214,10 @@ public function offsetUnset($offset): void {
212214 * @param mixed $concrete Concrete value to bind to the abstract value.
213215 *
214216 * @return boolean
215- * @throws ContainerException Thrown in case the entry already exist.
217+ * @throws ContainerException|ContainerExceptionInterface Thrown in case the entry already exist.
216218 */
217219 public function singleton (string $ abstract , mixed $ concrete ): bool {
218220 return $ this ->set ($ abstract , $ concrete , true );
219221 }
222+
220223}
0 commit comments