10000 [OptionsResolver] Added OptionsResolverInterface · symfony/symfony@dc2fa9d · GitHub
[go: up one dir, main page]

Skip to content

Commit dc2fa9d

Browse files
committed
[OptionsResolver] Added OptionsResolverInterface
1 parent 2cd99e8 commit dc2fa9d

File tree

2 files changed

+223
-144
lines changed

2 files changed

+223
-144
lines changed

src/Symfony/Component/OptionsResolver/OptionsResolver.php

Lines changed: 15 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* @author Bernhard Schussek <bschussek@gmail.com>
2222
* @author Tobias Schultze <http://tobion.de>
2323
*/
24-
class OptionsResolver
24+
class OptionsResolver implements OptionsResolverInterface
2525
{
2626
/**
2727
* The default option values.
@@ -68,27 +68,7 @@ public function __construct()
6868
}
6969

7070
/**
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}
9272
*/
9373
public function setDefaults(array $defaultValues)
9474
{
@@ -102,17 +82,7 @@ public function setDefaults(array $defaultValues)
10282
}
10383

10484
/**
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}
11686
*/
11787
public function replaceDefaults(array $defaultValues)
11888
{
@@ -126,20 +96,7 @@ public function replaceDefaults(array $defaultValues)
12696
}
12797

12898
/**
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}
143100
*/
144101
public function setOptional(array $optionNames)
145102
{
@@ -155,16 +112,7 @@ public function setOptional(array $optionNames)
155112
}
156113

157114
/**
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}
168116
*/
169117
public function setRequired(array $optionNames)
170118
{
@@ -184,17 +132,7 @@ public function setRequired(array $optionNames)
184132
}
185133

186134
/**
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}
198136
*/
199137
public function setAllowedValues(array $allowedValues)
200138
{
@@ -206,18 +144,7 @@ public function setAllowedValues(array $allowedValues)
206144
}
207145

208146
/**
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}
221148
*/
222149
public function addAllowedValues(array $allowedValues)
223150
{
@@ -229,63 +156,31 @@ public function addAllowedValues(array $allowedValues)
229156
}
230157

231158
/**
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}
241160
*/
242161
public function setAllowedTypes(array $allowedTypes)
243162
{
244-
$this->validateOptionNames(array_keys($allowedTypes));
163+
$this->validateOptionsExistence($allowedTypes);
245164

246165
$this->allowedTypes = array_replace($this->allowedTypes, $allowedTypes);
247166

248167
return $this;
249168
}
250169

251170
/**
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}
263172
*/
264173
public function addAllowedTypes(array $allowedTypes)
265174
{
266-
$this->validateOptionNames(array_keys($allowedTypes));
175+
$this->validateOptionsExistence($allowedTypes);
267176

268177
$this->allowedTypes = array_merge_recursive($this->allowedTypes, $allowedTypes);
269178

270179
return $this;
271180
}
272181

273182
/**
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}
289184
*/
290185
public function setFilters(array $filters)
291186
{
@@ -297,47 +192,23 @@ public function setFilters(array $filters)
297192
}
298193

299194
/**
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}
307196
*/
308197
public function isKnown($option)
309198
{
310199
return isset($this->knownOptions[$option]);
311200
}
312201

313202
/**
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}
322204
*/
323205
public function isRequired($option)
324206
{
325207
return isset($this->requiredOptions[$option]);
326208
}
327209

328210
/**
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}
341212
*/
342213
public function resolve(array $options)
343214
{

0 commit comments

Comments
 (0)
0