1 | <?php |
||
11 | class Container implements ContainerInterface |
||
12 | { |
||
13 | |||
14 | private $keyset = []; |
||
15 | private $values = []; |
||
16 | private $services = []; |
||
17 | |||
18 | |||
19 | /** |
||
20 | * @param $id |
||
21 | * @return mixed |
||
22 | * @throws \Exception if there was no value set under specified id |
||
23 | */ |
||
24 | 1 | public function get($id) |
|
32 | |||
33 | 1 | public function set($id, $value) |
|
39 | |||
40 | protected function setAsService($id, $service) |
||
41 | { |
||
42 | if (!is_object($service)) { |
||
43 | throw new \RuntimeException(sprintf('Service %s has to be an object', $id)); |
||
44 | } |
||
45 | |||
46 | $this->services[$id] = $service; |
||
47 | if (isset($this->values[$id])) { |
||
48 | unset($this->values[$id]); |
||
49 | } |
||
50 | $this->keyset[$id] = true; |
||
51 | } |
||
52 | |||
53 | public function remove($id) |
||
54 | { |
||
55 | $this->assertIdentifierSet($id); |
||
56 | if (array_key_exists($id, $this->values)) { |
||
57 | unset($this->values[$id]); |
||
58 | } |
||
59 | if (array_key_exists($id, $this->services)) { |
||
60 | unset($this->services[$id]); |
||
61 | } |
||
62 | } |
||
63 | |||
64 | 1 | public function has($id) |
|
68 | |||
69 | 1 | private function assertIdentifierSet($id) |
|
75 | } |