1 | <?php |
||
22 | class ParameterHolder implements \ArrayAccess, \IteratorAggregate, \Countable |
||
23 | { |
||
24 | protected $parameters; |
||
25 | |||
26 | /** |
||
27 | * __construct() |
||
28 | * |
||
29 | * @access public |
||
30 | * @param array $parameters (optional) |
||
31 | */ |
||
32 | public function __construct(array $parameters = []) |
||
33 | { |
||
34 | $this->parameters = $parameters; |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * setParameter |
||
39 | * |
||
40 | * Set a parameter. |
||
41 | * |
||
42 | * @access public |
||
43 | * @param string $name |
||
44 | * @param string|array $value |
||
45 | * @return ParameterHolder $this |
||
46 | */ |
||
47 | public function setParameter($name, $value) |
||
48 | { |
||
49 | $this->parameters[$name] = $value; |
||
50 | |||
51 | return $this; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * hasParameter |
||
56 | * |
||
57 | * check if the given parameter exists. |
||
58 | * |
||
59 | * @access public |
||
60 | * @param string $name |
||
61 | * @return bool |
||
62 | */ |
||
63 | public function hasParameter($name) |
||
67 | |||
68 | /** |
||
69 | * getParameter |
||
70 | * |
||
71 | * Returns the parameter "name" or "default" if not set. |
||
72 | * |
||
73 | * @access public |
||
74 | * @param string $name |
||
75 | * @param string $default Optional default value if name not set. |
||
76 | * @return string|array Parameter's value or default. |
||
77 | */ |
||
78 | public function getParameter($name, $default = null) |
||
82 | |||
83 | /** |
||
84 | * mustHave() |
||
85 | * |
||
86 | * Throw an exception if a param is not set |
||
87 | * |
||
88 | * @access public |
||
89 | * @throws FoundationException |
||
90 | * @param string $name the parameter's name |
||
91 | * @return ParameterHolder $this |
||
92 | */ |
||
93 | public function mustHave($name) |
||
101 | |||
102 | /** |
||
103 | * setDefaultValue() |
||
104 | * |
||
105 | * Sets a default value if the param $name is not set |
||
106 | * |
||
107 | * @access public |
||
108 | * @param string $name the parameter's name |
||
109 | * @param mixed $value the default value |
||
110 | * @return ParameterHolder $this |
||
111 | */ |
||
112 | public function setDefaultValue($name, $value) |
||
120 | |||
121 | /** |
||
122 | * mustBeOneOf() |
||
123 | * |
||
124 | * Check if the given parameter is one of the values passed as argument. If |
||
125 | * not, an exception is thrown. |
||
126 | * |
||
127 | * @access public |
||
128 | * @throws FoundationException |
||
129 | * @param string $name the parameter's name |
||
130 | * @param array $values |
||
131 | * @return ParameterHolder $this |
||
132 | */ |
||
133 | public function mustBeOneOf($name, array $values) |
||
141 | |||
142 | /** |
||
143 | * unsetParameter() |
||
144 | * |
||
145 | * @access public |
||
146 | * @param string $name |
||
147 | * @return ParameterHolder $this |
||
148 | */ |
||
149 | public function unsetParameter($name) |
||
155 | |||
156 | /** |
||
157 | * offsetExists() |
||
158 | * |
||
159 | * @see ArrayAccess |
||
160 | */ |
||
161 | public function offsetExists($name) |
||
165 | |||
166 | /** |
||
167 | * offsetGet() |
||
168 | * |
||
169 | * @see ArrayAccess |
||
170 | */ |
||
171 | public function offsetGet($name) |
||
175 | |||
176 | /** |
||
177 | * offsetSet() |
||
178 | * |
||
179 | * @see ArrayAccess |
||
180 | */ |
||
181 | public function offsetSet($name, $value) |
||
185 | |||
186 | /** |
||
187 | * offsetUnset() |
||
188 | * |
||
189 | * @see ArrayAccess |
||
190 | */ |
||
191 | public function offsetUnset($name) |
||
195 | |||
196 | /** |
||
197 | * |
||
198 | * @see \Countable |
||
199 | */ |
||
200 | public function count() |
||
204 | |||
205 | /** |
||
206 | * getIterator() |
||
207 | * |
||
208 | * @see \IteratorAggregate |
||
209 | */ |
||
210 | public function getIterator() |
||
214 | } |
||
215 |