Skip to content

Commit 371532a

Browse files
Merge branch '3.4' into 4.0
* 3.4: [HttpKernel] DebugHandlersListener should always replace the existing exception handler fix the Composer API being used [Security] Notify that symfony/expression-language is not installed if ExpressionLanguage and ExpressionLanguagePrivider are used [Debug] Always decorate existing exception handlers to deal with fatal errors Enableable ArrayNodeDefinition is disabled for empty configuration Fixing a bug where the dump() function depended on bundle ordering [Cache] Fix handling of apcu_fetch() edgy behavior Add nn (Norwegian Nynorsk) translation files, and improve existing file Problem in phar see mergerequest #25579 [Form] Disallow transform dates beyond the year 9999 Avoid button label translation when it's set to false Copied NO language files to the new NB locale. [Serializer] DateTimeNormalizer handling of null and empty values (returning null or empty instead of new object) Fix options resolver with array allowed types [Console] Improve phpdoc on StyleInterface::ask() [TwigBridge][WIP] Pass the form-check-inline in parent
2 parents 30d9240 + f3109a6 commit 371532a

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

@@ -1064,4 +1064,9 @@ private function formatValues(array $values): string
10641064

10651065
return implode(', ', $values);
10661066
}
1067+
1068+
private static function isValueValidType($type, $value)
1069+
{
1070+
return (function_exists($isFunction = 'is_'.$type) && $isFunction($value)) || $value instanceof $type;
1071+
}
10671072
}

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)