use Symfony\Component\OptionsResolver\OptionsResolverInterface; $optionsResolver = new OptionsResolverInterface(); $optionsResolver->setDefaults([ 'file_path' => './myfile.txt', ]); $optionsResolver->setNormalizers([ 'file_path' => function (Options $options, $value) { return realpath($value); }, ]); $options = $optionsResolver->resolve([]);
use Symfony\Component\OptionsResolver\OptionsResolverInterface; $optionsResolver = new OptionsResolverInterface(); $optionsResolver->setDefaults([ 'allowed_methods' => 'GET', ]); $optionsResolver->setNormalizers([ 'allowed_methods' => function (Options $options, $value) { if (is_array($value)) { return $value; } else { return explode(',', $value); } }, ]); $options = $optionsResolver->resolve([]);In this example, we set a default value for the `allowed_methods` option to "GET". We then define a normalizer that checks if the value is an array and returns it as is, or converts it to an array by splitting it into an array of values using the comma delimiter. The resolved options will always have an array value for this option. In summary, the OptionsResolverInterface provided by Symfony\Component\OptionsResolver is a useful package library for configuring and validating options in PHP applications. Its setNormalizers method allows for convenient transformation of option values, as shown in the examples above.