@@ 228-243 (lines=16) @@ | ||
225 | * |
|
226 | * @return mixed Entry. |
|
227 | */ |
|
228 | public function get($abstract) |
|
229 | { |
|
230 | if (! isset($this->collection[$abstract])) { |
|
231 | throw new Exceptions\NotFoundException("Element '$abstract' not found"); |
|
232 | } |
|
233 | ||
234 | if ($this->collection[$abstract] instanceof Closure) { |
|
235 | try { |
|
236 | return $this->collection[$abstract]($this); |
|
237 | } catch (Exception $e) { |
|
238 | throw new Exceptions\ContainerException($e->getMessage()); |
|
239 | } |
|
240 | } |
|
241 | ||
242 | return $this->collection[$abstract]; |
|
243 | } |
|
244 | ||
245 | /** |
|
246 | * Returns true if the container can return an entry for the given identifier. |
|
@@ 426-439 (lines=14) @@ | ||
423 | * @return \Codeburner\Container\Container |
|
424 | */ |
|
425 | ||
426 | public function share(string $abstract) : self |
|
427 | { |
|
428 | if (! isset($this->collection[$abstract])) { |
|
429 | throw new Exceptions\NotFoundException; |
|
430 | } |
|
431 | ||
432 | if (! $this->collection[$abstract] instanceof Closure) { |
|
433 | throw new Exceptions\ContainerException("'$abstract' must be a resolvable element"); |
|
434 | } |
|
435 | ||
436 | $this->collection[$abstract] = $this->collection[$abstract]($this); |
|
437 | ||
438 | return $this; |
|
439 | } |
|
440 | ||
441 | } |
|
442 |