Skip to content

Commit 5d5a3f1

Browse files
henrikbjornfabpot
authored andcommitted
Add type aliases for allowed types in OptionsResolver
1 parent 55cad3a commit 5d5a3f1

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

OptionsResolver.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ class OptionsResolver implements Options, OptionsResolverInterface
110110
*/
111111
private $locked = false;
112112

113+
private static $typeAliases = array(
114+
'boolean' => 'bool',
115+
'integer' => 'int',
116+
'double' => 'float',
117+
);
118+
113119
/**
114120
* Sets the default value of a given option.
115121
*
@@ -844,6 +850,8 @@ public function offsetGet($option)
844850
$valid = false;
845851

846852
foreach ($this->allowedTypes[$option] as $type) {
853+
$type = isset(self::$typeAliases[$type]) ? self::$typeAliases[$type] : $type;
854+
847855
if (function_exists($isFunction = 'is_'.$type)) {
848856
if ($isFunction($value)) {
849857
$valid = true;

Tests/OptionsResolverTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,21 @@ public function testResolveLazy()
7878
), $this->resolver->resolve(array()));
7979
}
8080

81+
public function testTypeAliasesForAllowedTypes()
82+
{
83+
$this->resolver->setDefaults(array(
84+
'force' => false,
85+
));
86+
87+
$this->resolver->setAllowedTypes(array(
88+
'force' => 'boolean',
89+
));
90+
91+
$this->resolver->resolve(array(
92+
'force' => true,
93+
));
94+
}
95+
8196
public function testResolveLazyDependencyOnOptional()
8297
{
8398
$this->resolver->setDefaults(array(

0 commit comments

Comments
 (0)