Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
80.00% |
4 / 5 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
Container | |
80.00% |
4 / 5 |
|
66.67% |
2 / 3 |
4.13 | |
0.00% |
0 / 1 |
get | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 | |||
has | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
set | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
5 | **/ |
6 | |
7 | declare(strict_types=1); |
8 | |
9 | namespace BO\Slim; |
10 | |
11 | use Psr\Container\ContainerInterface; |
12 | use Psr\Container\NotFoundExceptionInterface; |
13 | use BO\Slim\Exception\UnknownIdentifierException; |
14 | |
15 | /** |
16 | * PSR compatible container implementation, compatible with the ArrayAccess usage in zms |
17 | */ |
18 | class Container extends \ArrayObject implements ContainerInterface |
19 | { |
20 | /** |
21 | * @param string $identifier |
22 | * @return mixed |
23 | * |
24 | * @throws NotFoundExceptionInterface |
25 | */ |
26 | public function get(string $identifier) |
27 | { |
28 | if (!$this->has($identifier)) { |
29 | throw new UnknownIdentifierException('The container has no value identified by ' . $identifier); |
30 | } |
31 | |
32 | return $this->offsetGet($identifier); |
33 | } |
34 | |
35 | /** |
36 | * @param string $identifier The value identifier |
37 | * |
38 | * @return bool |
39 | */ |
40 | public function has(string $identifier): bool |
41 | { |
42 | return $this->offsetExists($identifier); |
43 | } |
44 | |
45 | /** |
46 | * @param string $identifier |
47 | * @param mixed $value |
48 | */ |
49 | public function set(string $identifier, $value): void |
50 | { |
51 | $this->offsetSet($identifier, $value); |
52 | } |
53 | } |