symfony/symfony — pull request #11716 by webmozart (2014-08-20 10:42:07+00:00)
Title: [OptionsResolver] Added a light-weight, low-level API for basic option resolving

| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #11705
| License | MIT
| Doc PR | TODO

See the attached README for details on the usage of the simple API.

I'm not entirely happy with the method names. `required()` is an adjective since the verb `require()` is a reserved PHP keyword. Please suggest alternatives here if you have any.

The most important motivation for this change is DX and speed. The basic features of the component should be easily usable in a wide variety of use cases without impacting performance.

For DX reasons, I added the static methods to the `Options` class, which makes the code concise and easy to read and understand:

```php
use Symfony\Component\OptionsResolver\Options;

$options = Options::required($options, 'format');

$options = Options::validateTypes($options, array(
'format' => array('string', 'int'),
'calendar' => 'int',
));

$options = Options::validateValues($options, array(
'calendar' => array(
\IntlDateFormatter::GREGORIAN,
\IntlDateFormatter::TRADITIONAL,
),
));

$options = Options::resolve($options, array(
'format' => null,
'calendar' => \IntlDateFormatter::GREGORIAN,
));
```