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