steevanb / symfony-options-resolver
Add features to Symfony OptionsResolver component.
Installs: 9 693
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^7.1.
- symfony/options-resolver: ^2.6||^3.0||^4.0
Requires (Dev)
- phpstan/phpstan: ^0.11
- phpunit/phpunit: ^8.3
This package is auto-updated.
Last update: 2024-12-06 23:10:22 UTC
README
symfony-options-resolver
Add features to Symfony OptionsResolver component.
Installation
composer require "steevanb/symfony-options-resolver": "^1.1.0"
Examples
Define an optional option with a default value:
use steevanb\SymfonyOptionsResolver\OptionsResolver; $optionsResolver = new OptionsResolver(); # Configure an optional option $optionsResolver->configureOption('foo', ['string'], 'default', ['default', 'value1', 'value2']); #Â Equivalent to call original OptionsResolver methods: $optionsResolver ->setDefined('foo') ->setAllowedTypes('foo', ['string']) ->setDefault('foo', 'default') ->setAllowedValues('foo', ['default', 'value1', 'value2']);
Define a required option:
use steevanb\SymfonyOptionsResolver\OptionsResolver; $optionsResolver = new OptionsResolver(); # Configure a required option $optionsResolver->configureRequiredOption('foo', ['string'], ['value1', 'value2']); #Â Equivalent to call original OptionsResolver methods: $optionsResolver ->setRequired('foo') ->setAllowedTypes('foo', ['string']) ->setAllowedValues('foo', ['value1', 'value2']);
Allow unknown keys:
use steevanb\SymfonyOptionsResolver\OptionsResolver; # This will not throw an exception because extraKey is not configured (new OptionsResolver()) ->configureRequiredOption('foo', ['string'], ['value1', 'value2']) ->setAllowUnknownKeys(true) ->resolve(['foo' => 'value1', 'extraKey' => 'extraValue']);