8000 Fix options resolver with array allowed types · symfony/symfony@1e46b19 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1e46b19

Browse files
committed
Fix options resolver with array allowed types
1 parent aa5f7ea commit 1e46b19

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/Symfony/Component/OptionsResolver/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
);
88988 8000 9

@@ -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
}

src/Symfony/Component/OptionsResolver/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(['foo' => ['bar', 'baz']]);
494+
495+
$this->assertSame(['foo' => ['bar', 'baz']], $options);
496+
}
497+
489498
/**
490499
* @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException
491500
*/

0 commit comments

Comments
 (0)
0