Fix MongoHydrator BSON handling

This commit is contained in:
2026-04-12 01:57:12 +03:00
parent d133898383
commit ece0147b3a

View File

@@ -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) {