Skip to content

Commit f3109a6

Browse files
committed
Fix options resolver with array allowed types
1 parent f31f4d3 commit f3109a6

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

OptionsResolver.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ private function verifyTypes($type, $value, array &$invalidTypes)
883883
$invalidValues = array_filter( // Filter out valid values, keeping invalid values in the resulting array
884884
$value,
885885
function ($value) use ($type) {
886-
return (function_exists($isFunction = 'is_'.$type) && !$isFunction($value)) || !$value instanceof $type;
886+
return !self::isValueValidType($type, $value);
887887
}
888888
);
889889

@@ -896,7 +896,7 @@ function ($value) use ($type) {
896896
return false;
897897
}
898898

899-
if ((function_exists($isFunction = 'is_'.$type) && $isFunction($value)) || $value instanceof $type) {
899+
if (self::isValueValidType($type, $value)) {
900900
return true;
901901
}
902902

@@ -1073,4 +1073,9 @@ private function formatValues(array $values)
10731073

10741074
return implode(', ', $values);
10751075
}
1076+
1077+
private static function isValueValidType($type, $value)
1078+
{
1079+
return (function_exists($isFunction = 'is_'.$type) && $isFunction($value)) || $value instanceof $type;
1080+
}
10761081
}

Tests/OptionsResolverTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,15 @@ public function testSetAllowedTypesFailsIfUnknownOption()
486486
$this->resolver->setAllowedTypes('foo', 'string');
487487
}
488488

489+
public function testResolveTypedArray()
490+
{
491+
$this->resolver->setDefined('foo');
492+
$this->resolver->setAllowedTypes('foo', 'string[]');
493+
$options = $this->resolver->resolve(array('foo' => array('bar', 'baz')));
494+
495+
$this->assertSame(array('foo' => array('bar', 'baz')), $options);
496+
}
497+
489498
/**
490499
* @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException
491500
*/

0 commit comments

Comments
 (0)