use Symfony\Component\OptionsResolver\OptionsResolver; $options = ['ids' => '1,2,3']; $resolver = new OptionsResolver(); $resolver->setDefined('ids'); $resolver->setNormalizer('ids', function ($options, $ids) { return explode(',', $ids); }); $validated = $resolver->resolve($options); var_dump($validated['ids']);
use Symfony\Component\OptionsResolver\OptionsResolver; $options = [ 'secret_key' => 'abcdef123', 'auth_header' => 'Bearer abcdef123', ]; $resolver = new OptionsResolver(); $resolver->setDefined('auth_header'); $resolver->setNormalizer('auth_header', function ($options, $authHeader) { $secretKey = $options['secret_key']; return str_replace('abcdef123', $secretKey, $authHeader); }); $validated = $resolver->resolve($options); var_dump($validated['auth_header']);In the above example, we define an option 'auth_header' with a default value. We also define another option 'secret_key' with a value that is used to modify the 'auth_header' value. We set a normalizer function for 'auth_header' that replaces the default secret key with the actual value of the 'secret_key' option. When we call the `resolve` method on the resolver, it validates and normalizes the options, and we get an array with the 'auth_header' key and its value replaced with the actual secret key value. The symfony.component.optionsresolver package library is part of the Symfony framework, which is a set of reusable PHP components.