1 | <?php |
||
19 | class ParamBag implements ArrayAccess, IteratorAggregate |
||
20 | { |
||
21 | /** |
||
22 | * @var array |
||
23 | */ |
||
24 | protected $params = []; |
||
25 | |||
26 | /** |
||
27 | * @param array $params |
||
28 | */ |
||
29 | public function __construct(array $params) |
||
33 | |||
34 | /** |
||
35 | * Get parameter values out of the bag. |
||
36 | * |
||
37 | * @param string $key |
||
38 | * |
||
39 | * @return mixed |
||
40 | */ |
||
41 | public function get($key) |
||
45 | |||
46 | /** |
||
47 | * Get parameter values out of the bag via the property access magic method. |
||
48 | * |
||
49 | * @param string $key |
||
50 | * |
||
51 | * @return mixed |
||
52 | */ |
||
53 | public function __get($key) |
||
57 | |||
58 | /** |
||
59 | * Check if a param exists in the bag via an isset() check on the property. |
||
60 | * |
||
61 | * @param string $key |
||
62 | * |
||
63 | * @return bool |
||
64 | */ |
||
65 | public function __isset($key) |
||
69 | |||
70 | /** |
||
71 | * Disallow changing the value of params in the data bag via property access. |
||
72 | * |
||
73 | * @param string $key |
||
74 | * @param mixed $value |
||
75 | * |
||
76 | * @throws \LogicException |
||
77 | * |
||
78 | * @return void |
||
79 | */ |
||
80 | public function __set($key, $value) |
||
84 | |||
85 | /** |
||
86 | * Disallow unsetting params in the data bag via property access. |
||
87 | * |
||
88 | * @param string $key |
||
89 | * |
||
90 | * @throws \LogicException |
||
91 | * |
||
92 | * @return void |
||
93 | */ |
||
94 | public function __unset($key) |
||
98 | |||
99 | /** |
||
100 | * Check if a param exists in the bag via an isset() and array access. |
||
101 | * |
||
102 | * @param string $key |
||
103 | * |
||
104 | * @return bool |
||
105 | */ |
||
106 | public function offsetExists($key) |
||
110 | |||
111 | /** |
||
112 | * Get parameter values out of the bag via array access. |
||
113 | * |
||
114 | * @param string $key |
||
115 | * |
||
116 | * @return mixed |
||
117 | */ |
||
118 | public function offsetGet($key) |
||
122 | |||
123 | /** |
||
124 | * Disallow changing the value of params in the data bag via array access. |
||
125 | * |
||
126 | * @param string $key |
||
127 | * @param mixed $value |
||
128 | * |
||
129 | * @throws \LogicException |
||
130 | * |
||
131 | * @return void |
||
132 | */ |
||
133 | public function offsetSet($key, $value) |
||
137 | |||
138 | /** |
||
139 | * Disallow unsetting params in the data bag via array access. |
||
140 | * |
||
141 | * @param string $key |
||
142 | * |
||
143 | * @throws \LogicException |
||
144 | * |
||
145 | * @return void |
||
146 | */ |
||
147 | public function offsetUnset($key) |
||
151 | |||
152 | /** |
||
153 | * IteratorAggregate for iterating over the object like an array. |
||
154 | * |
||
155 | * @return \ArrayIterator |
||
156 | */ |
||
157 | public function getIterator() |
||
161 | } |
||
162 |