Fix MongoHydrator BSON handling
This commit is contained in:
@@ -20,9 +20,7 @@ final class MongoHydrator
|
|||||||
$propName = $field->property->getName();
|
$propName = $field->property->getName();
|
||||||
$value = $doc[$key] ?? null;
|
$value = $doc[$key] ?? null;
|
||||||
|
|
||||||
if ($value instanceof \MongoDB\Model\BSONArray) {
|
$value = $this->normalizeBson($value);
|
||||||
$value = $value->getArrayCopy();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($field->isEmbedded && $value !== null) {
|
if ($field->isEmbedded && $value !== null) {
|
||||||
$value = $this->hydrate($field->embeddedClass, $this->toArray($value));
|
$value = $this->hydrate($field->embeddedClass, $this->toArray($value));
|
||||||
@@ -72,6 +70,19 @@ final class MongoHydrator
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function normalizeBson(mixed $value): mixed
|
||||||
|
{
|
||||||
|
if ($value instanceof \MongoDB\Model\BSONArray) {
|
||||||
|
return array_map($this->normalizeBson(...), $value->getArrayCopy());
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($value instanceof BSONDocument) {
|
||||||
|
return array_map($this->normalizeBson(...), iterator_to_array($value));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
private function toArray(array|BSONDocument $doc): array
|
private function toArray(array|BSONDocument $doc): array
|
||||||
{
|
{
|
||||||
if ($doc instanceof BSONDocument) {
|
if ($doc instanceof BSONDocument) {
|
||||||
|
|||||||
Reference in New Issue
Block a user