1 | <?php |
||
22 | class ParameterHolder implements \ArrayAccess, \IteratorAggregate, \Countable |
||
23 | { |
||
24 | protected $parameters; |
||
25 | |||
26 | /** |
||
27 | * __construct() |
||
28 | * |
||
29 | * @param array $parameters (optional) |
||
30 | */ |
||
31 | public function __construct(array $parameters = []) |
||
35 | |||
36 | /** |
||
37 | * setParameter |
||
38 | * |
||
39 | * Set a parameter. |
||
40 | * |
||
41 | * @param string $name |
||
42 | * @param string|array $value |
||
43 | * @return ParameterHolder $this |
||
44 | */ |
||
45 | public function setParameter($name, $value) |
||
51 | |||
52 | /** |
||
53 | * hasParameter |
||
54 | * |
||
55 | * check if the given parameter exists. |
||
56 | * |
||
57 | * @param string $name |
||
58 | * @return bool |
||
59 | */ |
||
60 | public function hasParameter($name) |
||
64 | |||
65 | /** |
||
66 | * getParameter |
||
67 | * |
||
68 | * Returns the parameter "name" or "default" if not set. |
||
69 | * |
||
70 | * @param string $name |
||
71 | * @param string $default Optional default value if name not set. |
||
72 | * @return string|array Parameter's value or default. |
||
73 | */ |
||
74 | public function getParameter($name, $default = null) |
||
78 | |||
79 | /** |
||
80 | * mustHave() |
||
81 | * |
||
82 | * Throw an exception if a param is not set |
||
83 | * |
||
84 | * @throws FoundationException |
||
85 | * @param string $name the parameter's name |
||
86 | * @return ParameterHolder $this |
||
87 | */ |
||
88 | public function mustHave($name) |
||
96 | |||
97 | /** |
||
98 | * setDefaultValue() |
||
99 | * |
||
100 | * Sets a default value if the param $name is not set |
||
101 | * |
||
102 | * @param string $name the parameter's name |
||
103 | * @param mixed $value the default value |
||
104 | * @return ParameterHolder $this |
||
105 | */ |
||
106 | public function setDefaultValue($name, $value) |
||
114 | |||
115 | /** |
||
116 | * mustBeOneOf() |
||
117 | * |
||
118 | * Check if the given parameter is one of the values passed as argument. If |
||
119 | * not, an exception is thrown. |
||
120 | * |
||
121 | * @throws FoundationException |
||
122 | * @param string $name the parameter's name |
||
123 | * @param array $values |
||
124 | * @return ParameterHolder $this |
||
125 | */ |
||
126 | public function mustBeOneOf($name, array $values) |
||
136 | |||
137 | /** |
||
138 | * unsetParameter() |
||
139 | * |
||
140 | * @param string $name |
||
141 | * @return ParameterHolder $this |
||
142 | */ |
||
143 | public function unsetParameter($name) |
||
149 | |||
150 | /** |
||
151 | * offsetExists() |
||
152 | * |
||
153 | * @see ArrayAccess |
||
154 | */ |
||
155 | public function offsetExists($name) |
||
159 | |||
160 | /** |
||
161 | * offsetGet() |
||
162 | * |
||
163 | * @see ArrayAccess |
||
164 | */ |
||
165 | public function offsetGet($name) |
||
169 | |||
170 | /** |
||
171 | * offsetSet() |
||
172 | * |
||
173 | * @see ArrayAccess |
||
174 | */ |
||
175 | public function offsetSet($name, $value) |
||
179 | |||
180 | /** |
||
181 | * offsetUnset() |
||
182 | * |
||
183 | * @see ArrayAccess |
||
184 | */ |
||
185 | public function offsetUnset($name) |
||
189 | |||
190 | /** |
||
191 | * |
||
192 | * @see \Countable |
||
193 | */ |
||
194 | public function count() |
||
198 | |||
199 | /** |
||
200 | * getIterator() |
||
201 | * |
||
202 | * @see \IteratorAggregate |
||
203 | */ |
||
204 | public function getIterator() |
||
208 | } |
||
209 |