Closed
Description
For many projects or even Symfony components, the full functionality of the OptionsResolver is overkill. Nevertheless, the com 6A77 ponent contains code that is very useful, but not easily accessible.
I suggest to make the validate*
methods in the OptionsResolver class accessible through a simple low-level API such as:
use Symfony\Component\OptionsResolver\Options;
// throws MissingOptionsException if the option(s) is (are) missing
Options::require($options, 'toTz');
// throws InvalidOptionsException if any of the options have an invalid type
Options::validateTypes($options, array(
'fromTz' => 'string',
'toTz' => 'string',
'dateFormat' => 'string',
'timeFormat' => 'string',
'calendar' => array('null', 'integer'),
));
// throws InvalidOptionsException if any of the options contain an invalid value
Options::validateValues($options, array(
'calendar' => array(
\IntlDateFormatter::GREGORIAN,
\IntlDateFormatter::TRADITIONAL,
),
));
// throws InvalidOptionsException if any of the given options is not known
$options = Options::resolve($options, array(
'fromTz' => null,
'toTz' => null,
'dateFormat' => \IntlDateFormatter::MEDIUM,
'timeFormat' => \IntlDateFormatter::SHORT,
'calendar' => \IntlDateFormatter::GREGORIAN,
));
Opinions?