Skip to content

Commit

Permalink
Merge pull request #22 from PackageFactory/bugfix/handleArrayAccessIn…
Browse files Browse the repository at this point in the history
…DataStructureValidatorGracefully

BUGFIX: Handle ArrayAccess in DataStructure validator gracefully
  • Loading branch information
mficzel committed Jan 12, 2023
2 parents c42e26a + 22b02f8 commit a94ac42
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 a94ac42

Please sign in to comment.