1 | <?php |
||
9 | abstract class SuperGlobal implements GlobalInterface |
||
10 | { |
||
11 | /** |
||
12 | * @var Container |
||
13 | */ |
||
14 | protected $container; |
||
15 | |||
16 | /** |
||
17 | * @var Security |
||
18 | */ |
||
19 | protected $security; |
||
20 | |||
21 | 32 | public function __construct(Container $container, Security $security) |
|
26 | |||
27 | 4 | public function set(string $key, $value) |
|
28 | { |
||
29 | 4 | $global = $this->getGlobalName(); |
|
30 | 4 | $container = $this->container->get($global); |
|
31 | 4 | $container[$key] = $value; |
|
32 | 4 | $this->container->set($global, $container); |
|
33 | 4 | } |
|
34 | |||
35 | 6 | public function fetch(string $key = null, $default = null) |
|
36 | { |
||
37 | 6 | $global = $this->getGlobalName(); |
|
38 | 6 | if ($key === null) { |
|
39 | 1 | return empty($this->container->get($global)) === true ? null : $this->container->get($global); |
|
40 | } |
||
41 | |||
42 | 5 | return $this->container->has($global) ? $this->container->get($global)[$key] ?? $default : null; |
|
43 | } |
||
44 | |||
45 | 1 | public function remove(string $key) |
|
52 | |||
53 | 32 | private function getGlobalName() : string |
|
57 | |||
58 | 1 | private function processRemoval(string $key) |
|
67 | |||
68 | 32 | protected function registerGlobal($value) |
|
73 | } |
||
74 |