[BugFix][Validator] Fix for PHP incosistent behaviour of ArrayAccess
Bug fix: yes Feature addition: no Backwards compatibility break: no Symfony2 tests pass: yes Fixes the following tickets: #2779 Todo: - Because PHP function `array_key_exists` is buggy, it works great with native PHP `ArrayObject` instances, but hand written implementations of `ArrayAccess` and `Traversable` objects will fail to work with `CollectionValidator`
This commit is contained in:
parent
74961c8d22
commit
253eebad88
@ -52,7 +52,11 @@ class CollectionValidator extends ConstraintValidator
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($constraint->fields as $field => $constraints) {
|
foreach ($constraint->fields as $field => $constraints) {
|
||||||
if (array_key_exists($field, $value)) {
|
if (
|
||||||
|
// bug fix issue #2779
|
||||||
|
(is_array($value) && array_key_exists($field, $value)) ||
|
||||||
|
($value instanceof \ArrayAccess && $value->offsetExists($field))
|
||||||
|
) {
|
||||||
// cannot simply cast to array, because then the object is converted to an
|
// cannot simply cast to array, because then the object is converted to an
|
||||||
// array instead of wrapped inside
|
// array instead of wrapped inside
|
||||||
$constraints = is_array($constraints) ? $constraints : array($constraints);
|
$constraints = is_array($constraints) ? $constraints : array($constraints);
|
||||||
|
Reference in New Issue
Block a user