Add type aliases for allowed types in OptionsResolver
This commit is contained in:
parent
193d69c4d1
commit
ae544e5d8f
@ -110,6 +110,12 @@ class OptionsResolver implements Options, OptionsResolverInterface
|
||||
*/
|
||||
private $locked = false;
|
||||
|
||||
private static $typeAliases = array(
|
||||
'boolean' => 'bool',
|
||||
'integer' => 'int',
|
||||
'double' => 'float',
|
||||
);
|
||||
|
||||
/**
|
||||
* Sets the default value of a given option.
|
||||
*
|
||||
@ -844,6 +850,8 @@ class OptionsResolver implements Options, OptionsResolverInterface
|
||||
$valid = false;
|
||||
|
||||
foreach ($this->allowedTypes[$option] as $type) {
|
||||
$type = isset(self::$typeAliases[$type]) ? self::$typeAliases[$type] : $type;
|
||||
|
||||
if (function_exists($isFunction = 'is_'.$type)) {
|
||||
if ($isFunction($value)) {
|
||||
$valid = true;
|
||||
|
@ -78,6 +78,21 @@ class OptionsResolverTest extends \PHPUnit_Framework_TestCase
|
||||
), $this->resolver->resolve(array()));
|
||||
}
|
||||
|
||||
public function testTypeAliasesForAllowedTypes()
|
||||
{
|
||||
$this->resolver->setDefaults(array(
|
||||
'force' => false,
|
||||
));
|
||||
|
||||
$this->resolver->setAllowedTypes(array(
|
||||
'force' => 'boolean',
|
||||
));
|
||||
|
||||
$this->resolver->resolve(array(
|
||||
'force' => true,
|
||||
));
|
||||
}
|
||||
|
||||
public function testResolveLazyDependencyOnOptional()
|
||||
{
|
||||
$this->resolver->setDefaults(array(
|
||||
|
Reference in New Issue
Block a user