Skip to content

Commit

Permalink
fix: ensure ArrayObject entities can be extracted in all PHP versions
Browse files Browse the repository at this point in the history
Adds checks for `ArrayObject` entities in each implementation of the EntityExtractorHydrator, calling `getArrayCopy()` on the instance when found, instead of `get_object_properties()`

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
  • Loading branch information
weierophinney committed Mar 1, 2021
1 parent c6f44fb commit ac8b67f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Extractor/EntityExtractorHydratorV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Laminas\ApiTools\Hal\Extractor;

use ArrayObject;
use JsonSerializable;
use Laminas\ApiTools\Hal\EntityHydratorManager;
use Laminas\Hydrator\ExtractionInterface;
Expand Down Expand Up @@ -68,6 +69,10 @@ private function extractEntity($entity)
return $entity->jsonSerialize();
}

if ($entity instanceof ArrayObject) {
return $entity->getArrayCopy();
}

return get_object_vars($entity);
}
}
5 changes: 5 additions & 0 deletions src/Extractor/EntityExtractorHydratorV3.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Laminas\ApiTools\Hal\Extractor;

use ArrayObject;
use JsonSerializable;
use Laminas\ApiTools\Hal\EntityHydratorManager;
use Laminas\Hydrator\ExtractionInterface;
Expand Down Expand Up @@ -68,6 +69,10 @@ private function extractEntity(object $entity) : array
return $entity->jsonSerialize();
}

if ($entity instanceof ArrayObject) {
return $entity->getArrayCopy();
}

return get_object_vars($entity);
}
}

0 comments on commit ac8b67f

Please sign in to comment.