8000 Suggested fix for issue #15524 · EVODelavega/symfony@ad2e288 · GitHub
[go: up one dir, main page]

Skip to content

Commit ad2e288

Browse files
author
Elias Van Ootegem
committed
Suggested fix for issue symfony#15524
1 parent d76cc03 commit ad2e288

File tree

1 file changed

+41
-14
lines changed

1 file changed

+41
-14
lines changed

src/Symfony/Component/OptionsResolver/OptionsResolver.php

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -866,19 +866,8 @@ public function offsetGet($option)
866866
$valid = false;
867867

868868
foreach ($this->allowedTypes[$option] as $type) {
869-
$type = isset(self::$typeAliases[$type]) ? self::$typeAliases[$type] : $type;
870-
871-
if (function_exists($isFunction = 'is_'.$type)) {
872-
if ($isFunction($value)) {
873-
$valid = true;
874-
break;
875-
}
876-
877-
continue;
878-
}
879-
880-
if ($value instanceof $type) {
881-
$valid = true;
869+
$valid = $this->verifyAllowedType($type, $value);
870+
if ($valid) {
882871
break;
883872
}
884873
}
@@ -890,7 +879,7 @@ public function offsetGet($option)
890879
$option,
891880
$this->formatValue($value),
892881
implode('" or "', $this->allowedTypes[$option]),
893-
$this->formatTypeOf($value)
882+
$this->formatTypeOf($value, $offendingType)
894883
));
895884
}
896885
}
@@ -964,6 +953,44 @@ public function offsetGet($option)
964953
return $value;
965954
}
966955

956+
/**
957+
* Verify value is of the allowed type. Recursive method to support
958+
* typed array notation like ClassName[], or scalar arrays (int[])
959+
*
960+
* @param string $type the required allowedType string
961+
*
962+
* @param mixed $value the value
963+
*
964+
* @return bool Whether or not $value if of the allowed type
965+
*
966+
*/
967+
private function verifyAllowedType($type, $value)
968+
{
969+
$valid = false;
970+
971+
$type = isset(self::$typeAliases[$type]) ? self::$typeAliases[$type] : $type;
972+
973+
if (substr($type, -2) === '[]') {
974+
if (is_array($value)) {
975+
$subType = substr($type, 0, -2);
976+
foreach ($value as $v) {
977+
$valid = $this->validateType($subType, $v);
978+
if (!$valid) {
979+
break;
980+
}
981+
}
982+
}
983+
} else if (function_exists($isFunction = 'is_'.$type)) {
984+
if ($isFunction($value)) {
985+
$valid = true;
986+
}
987+
} else if ($value instanceof $type) {
988+
$valid = true;
989+
}
990+
991+
return $valid;
992+
}
993+
967994
/**
968995
* Returns whether a resolved option with the given name exists.
969996
*

0 commit comments

Comments
 (0)
0