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