comparison vendor/symfony/validator/Constraints/CollectionValidator.php @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents c75dbcec494b
children 12f9dff5fda9
comparison
equal deleted inserted replaced
3:307d7a7fd348 4:a9cd425dd02b
31 31
32 if (null === $value) { 32 if (null === $value) {
33 return; 33 return;
34 } 34 }
35 35
36 if (!is_array($value) && !($value instanceof \Traversable && $value instanceof \ArrayAccess)) { 36 if (!\is_array($value) && !($value instanceof \Traversable && $value instanceof \ArrayAccess)) {
37 throw new UnexpectedTypeException($value, 'array or Traversable and ArrayAccess'); 37 throw new UnexpectedTypeException($value, 'array or Traversable and ArrayAccess');
38 } 38 }
39 39
40 // We need to keep the initialized context when CollectionValidator 40 // We need to keep the initialized context when CollectionValidator
41 // calls itself recursively (Collection constraints can be nested). 41 // calls itself recursively (Collection constraints can be nested).
48 // to validate() instead. 48 // to validate() instead.
49 $context = $this->context; 49 $context = $this->context;
50 50
51 foreach ($constraint->fields as $field => $fieldConstraint) { 51 foreach ($constraint->fields as $field => $fieldConstraint) {
52 // bug fix issue #2779 52 // bug fix issue #2779
53 $existsInArray = is_array($value) && array_key_exists($field, $value); 53 $existsInArray = \is_array($value) && array_key_exists($field, $value);
54 $existsInArrayAccess = $value instanceof \ArrayAccess && $value->offsetExists($field); 54 $existsInArrayAccess = $value instanceof \ArrayAccess && $value->offsetExists($field);
55 55
56 if ($existsInArray || $existsInArrayAccess) { 56 if ($existsInArray || $existsInArrayAccess) {
57 if (count($fieldConstraint->constraints) > 0) { 57 if (\count($fieldConstraint->constraints) > 0) {
58 $context->getValidator() 58 $context->getValidator()
59 ->inContext($context) 59 ->inContext($context)
60 ->atPath('['.$field.']') 60 ->atPath('['.$field.']')
61 ->validate($value[$field], $fieldConstraint->constraints); 61 ->validate($value[$field], $fieldConstraint->constraints);
62 } 62 }