1 | <?php |
||
16 | class ExecutionContext implements \ArrayAccess |
||
17 | { |
||
18 | /** |
||
19 | * Data items |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | private $items; |
||
24 | |||
25 | /** |
||
26 | * Nested contexts |
||
27 | * |
||
28 | * @var ExecutionContext[] |
||
29 | */ |
||
30 | private $namespaces; |
||
31 | |||
32 | /** |
||
33 | * ExecutionContext constructor. |
||
34 | * |
||
35 | * @param array $items Initial data for context |
||
36 | */ |
||
37 | 269 | public function __construct(array $items = []) |
|
42 | |||
43 | /** |
||
44 | * Return nested isolated execution context |
||
45 | * |
||
46 | * @param string $namespace Namespace name |
||
47 | * |
||
48 | * @return ExecutionContext |
||
49 | */ |
||
50 | 8 | public function inNamespace($namespace) |
|
58 | |||
59 | /** |
||
60 | * Clears data inside the context |
||
61 | * |
||
62 | * @return void |
||
63 | */ |
||
64 | 1 | public function clear() |
|
68 | |||
69 | /** |
||
70 | * Set a value |
||
71 | * |
||
72 | * @param string|int $key Key |
||
73 | * @param mixed $value A value |
||
74 | * |
||
75 | * @return void |
||
76 | */ |
||
77 | 9 | public function set($key, $value) |
|
81 | |||
82 | /** |
||
83 | * Return a value stored under the key |
||
84 | * |
||
85 | * @param string|int $key A key |
||
86 | * @param mixed $default Default value to return if key does not exist |
||
87 | * |
||
88 | * @return mixed |
||
89 | */ |
||
90 | 4 | public function get($key, $default = null) |
|
94 | |||
95 | /** |
||
96 | * Return true if context has value for a given key |
||
97 | * |
||
98 | * @param string|int $key A key |
||
99 | * |
||
100 | * @return bool |
||
101 | */ |
||
102 | 5 | public function has($key) |
|
106 | |||
107 | /** |
||
108 | * Removes a value under given key |
||
109 | * |
||
110 | * @param string|int $key A key |
||
111 | * |
||
112 | * @return void |
||
113 | */ |
||
114 | 1 | public function remove($key) |
|
118 | |||
119 | /** |
||
120 | * @inheritDoc |
||
121 | */ |
||
122 | 5 | public function offsetExists($offset) |
|
126 | |||
127 | /** |
||
128 | * @inheritDoc |
||
129 | */ |
||
130 | 1 | public function offsetGet($offset) |
|
134 | |||
135 | /** |
||
136 | * @inheritDoc |
||
137 | */ |
||
138 | 9 | public function offsetSet($offset, $value) |
|
142 | |||
143 | /** |
||
144 | * @inheritDoc |
||
145 | */ |
||
146 | 1 | public function offsetUnset($offset) |
|
150 | } |
||
151 |