21
21
* @author Bernhard Schussek <bschussek@gmail.com>
22
22
* @author Tobias Schultze <http://tobion.de>
23
23
*/
24
- class OptionsResolver
24
+ class OptionsResolver implements OptionsResolverInterface
25
25
{
26
26
/**
27
27
* The default option values.
@@ -68,27 +68,7 @@ public function __construct()
68
68
}
69
69
70
70
/**
71
- * Sets default option values.
72
- *
73
- * The options can either be values of any types or closures that
74
- * evaluate the option value lazily. These closures must have one
75
- * of the following signatures:
76
- *
77
- * <code>
78
- * function (Options $options)
79
- * function (Options $options, $value)
80
- * </code>
81
- *
82
- * The second parameter passed to the closure is the previously
83
- * set default value, in case you are overwriting an existing
84
- * default value.
85
- *
86
- * The closures should return the lazily created option value.
87
- *
88
- * @param array $defaultValues A list of option names as keys and default
89
- * values or closures as values.
90
- *
91
- * @return OptionsResolver The resolver instance.
71
+ * {@inheritdoc}
92
72
*/
93
73
public function setDefaults (array $ defaultValues )
94
74
{
@@ -102,17 +82,7 @@ public function setDefaults(array $defaultValues)
102
82
}
103
83
104
84
/**
105
- * Replaces default option values.
106
- *
107
- * Old defaults are erased, which means that closures passed here cannot
108
- * access the previous default value. This may be useful to improve
109
- * performance if the previous default value is calculated by an expensive
110
- * closure.
111
- *
112
- * @param array $defaultValues A list of option names as keys and default
113
- * values or closures as values.
114
- *
115
- * @return OptionsResolver The resolver instance.
85
+ * {@inheritdoc}
116
86
*/
117
87
public function replaceDefaults (array $ defaultValues )
118
88
{
@@ -126,20 +96,7 @@ public function replaceDefaults(array $defaultValues)
126
96
}
127
97
128
98
/**
129
- * Sets optional options.
130
- *
131
- * This method declares a valid option names without setting default values for
132
- * them. If these options are not passed to {@link resolve()} and no default has
133
- * been set for them, they will be missing in the final options array. This can
134
- * be helpful if you want to determine whether an option has been set or not
135
- * because otherwise {@link resolve()} would trigger an exception for unknown
136
- * options.
137
- *
138
- * @param array $optionNames A list of option names.
139
- *
140
- * @return OptionsResolver The resolver instance.
141
- *
142
- * @throws OptionDefinitionException When trying to pass default values.
99
+ * {@inheritdoc}
143
100
*/
144
101
public function setOptional (array $ optionNames )
145
102
{
@@ -155,16 +112,7 @@ public function setOptional(array $optionNames)
155
112
}
156
113
157
114
/**
158
- * Sets required options.
159
- *
160
- * If these options are not passed to resolve() and no default has been set for
161
- * them, an exception will be thrown.
162
- *
163
- * @param array $optionNames A list of option names.
164
- *
165
- * @return OptionsResolver The resolver instance.
166
- *
167
- * @throws OptionDefinitionException When trying to pass default values.
115
+ * {@inheritdoc}
168
116
*/
169
117
public function setRequired (array $ optionNames )
170
118
{
@@ -184,17 +132,7 @@ public function setRequired(array $optionNames)
184
132
}
185
133
186
134
/**
187
- * Sets allowed values for a list of options.
188
- *
189
- * @param array $allowedValues A list of option names as keys and arrays
190
- * with values acceptable for that option as
191
- * values.
192
- *
193
- * @return OptionsResolver The resolver instance.
194
- *
195
- * @throws InvalidOptionsException If an option has not been defined
196
- * (see {@link isKnown()}) for which
197
- * an allowed value is set.
135
+ * {@inheritdoc}
198
136
*/
199
137
public function setAllowedValues (array $ allowedValues )
200
138
{
@@ -206,18 +144,7 @@ public function setAllowedValues(array $allowedValues)
206
144
}
207
145
208
146
/**
209
- * Adds allowed values for a list of options.
210
- *
211
- * The values are merged with the allowed values defined previously.
212
- *
213
- * @param array $allowedValues A list of option names as keys and arrays
214
- * with values acceptable for that option as
215
- * values.
216
- *
217
- * @return OptionsResolver The resolver instance.
218
- *
219
- * @throws InvalidOptionsException If an option has not been defined for
220
- * which an allowed value is set.
147
+ * {@inheritdoc}
221
148
*/
222
149
public function addAllowedValues (array $ allowedValues )
223
150
{
@@ -229,63 +156,31 @@ public function addAllowedValues(array $allowedValues)
229
156
}
230
157
231
158
/**
232
- * Sets allowed types for a list of options.
233
- *
234
- * @param array $allowedTypes A list of option names as keys and type
235
- * names passed as string or array as values.
236
- *
237
- * @return OptionsResolver The resolver instance.
238
- *
239
- * @throws InvalidOptionsException If an option has not been defined for
240
- * which an allowed type is set.
159
+ * {@inheritdoc}
241
160
*/
242
161
public function setAllowedTypes (array $ allowedTypes )
243
162
{
244
- $ this ->validateOptionNames ( array_keys ( $ allowedTypes) );
163
+ $ this ->validateOptionsExistence ( $ allowedTypes );
245
164
246
165
$ this ->allowedTypes = array_replace ($ this ->allowedTypes , $ allowedTypes );
247
166
248
167
return $ this ;
249
168
}
250
169
251
170
/**
252
- * Adds allowed types for a list of options.
253
- *
254
- * The types are merged with the allowed types defined previously.
255
- *
256
- * @param array $allowedTypes A list of option names as keys and type
257
- * names passed as string or array as values.
258
- *
259
- * @return OptionsResolver The resolver instance.
260
- *
261
- * @throws InvalidOptionsException If an option has not been defined for
262
- * which an allowed type is set.
171
+ * {@inheritdoc}
263
172
*/
264
173
public function addAllowedTypes (array $ allowedTypes )
265
174
{
266
- $ this ->validateOptionNames ( array_keys ( $ allowedTypes) );
175
+ $ this ->validateOptionsExistence ( $ allowedTypes );
267
176
268
177
$ this ->allowedTypes = array_merge_recursive ($ this ->allowedTypes , $ allowedTypes );
269
178
270
179
return $ this ;
271
180
}
272
181
273
182
/**
274
- * Sets filters that are applied on resolved options.
275
- *
276
- * The filters should be closures with the following signature:
277
- *
278
- * <code>
279
- * function (Options $options, $value)
280
- * </code>
281
- *
282
- * The second parameter passed to the closure is the value of
283
- * the option.
284
- *
285
- * The closure should return the filtered value.
286
- *
287
- * @param array $filters
288
- * @return OptionsResolver
183
+ * {@inheritdoc}
289
184
*/
290
185
public function setFilters (array $ filters )
291
186
{
@@ -297,47 +192,23 @@ public function setFilters(array $filters)
297
192
}
298
193
299
194
/**
300
- * Returns whether an option is known.
301
- *
302
- * An option is known if it has been passed to either {@link setDefaults()},
303
- * {@link setRequired()} or {@link setOptional()} before.
304
- *
305
- * @param string $option The name of the option.
306
- * @return Boolean Whether the option is known.
195
+ * {@inheritdoc}
307
196
*/
308
197
public function isKnown ($ option )
309
198
{
310
199
return isset ($ this ->knownOptions [$ option ]);
311
200
}
312
201
313
202
/**
314
- * Returns whether an option is required.
315
- *
316
- * An option is required if it has been passed to {@link setRequired()},
317
- * but not to {@link setDefaults()}. That is, the option has been declared
318
- * as required and no default value has been set.
319
- *
320
- * @param string $option The name of the option.
321
- * @return Boolean Whether the option is required.
203
+ * {@inheritdoc}
322
204
*/
323
205
public function isRequired ($ option )
324
206
{
325
207
return isset ($ this ->requiredOptions [$ option ]);
326
208
}
327
209
328
210
/**
329
- * Returns the combination of the default and the passed options.
330
- *
331
- * @param array $options The custom option values.
332
- *
333
- * @return array A list of options and their values.
334
- *
335
- * @throws InvalidOptionsException If any of the passed options has not
336
- * been defined or does not contain an
337
- * allowed value.
338
- * @throws MissingOptionsException If a required option is missing.
339
- * @throws OptionDefinitionException If a cyclic dependency is detected
340
- * between two lazy options.
211
+ * {@inheritdoc}
341
212
*/
342
213
public function resolve (array $ options )
343
214
{
0 commit comments