Skip to content

Commit

Permalink
BUGFIX: Handle ArrayAccess in DataStructure validator gracefully
Browse files Browse the repository at this point in the history
while the data structure validator accepted array acces it threw errors when an object actually used this because array_key_exists does not allow passing arrays.
  • Loading branch information
mficzel committed Jan 12, 2023
1 parent c42e26a commit 22b02f8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
6 changes: 1 addition & 5 deletions Classes/Validators/DataStructureValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ protected function isValid($value)
$result = $this->getResult() ?: new Result();
foreach ($this->options['dataStructure'] as $key => $subValidator) {
if (is_array($value) || ($value instanceof \ArrayAccess)) {
if (array_key_exists($key, $value)) {
$subValue = $value[$key];
} else {
$subValue = null;
}
$subValue = $value[$key] ?? null;
} elseif (ObjectAccess::isPropertyGettable($value, $key)) {
$subValue = ObjectAccess::getPropertyPath($value, $key);
} else {
Expand Down
6 changes: 1 addition & 5 deletions Classes/Validators/ShapeValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ protected function isValid($value)
$result = $this->getResult() ?: new Result();
foreach ($this->options['shape'] as $key => $subValidator) {
if (is_array($value) || ($value instanceof \ArrayAccess)) {
if (array_key_exists($key, $value)) {
$subValue = $value[$key];
} else {
$subValue = null;
}
$subValue = $value[$key] ?? null;
} elseif (ObjectAccess::isPropertyGettable($value, $key)) {
$subValue = ObjectAccess::getPropertyPath($value, $key);
} else {
Expand Down

0 comments on commit 22b02f8

Please sign in to comment.