1212use Doctrine \ODM \MongoDB \Events ;
1313use Doctrine \ODM \MongoDB \Mapping \ClassMetadata ;
1414use Doctrine \ODM \MongoDB \Proxy \InternalProxy ;
15- use Doctrine \ODM \MongoDB \Types \Type ;
1615use Doctrine \ODM \MongoDB \UnitOfWork ;
1716use ProxyManager \Proxy \GhostObjectInterface ;
1817
@@ -165,14 +164,14 @@ private function generateHydratorClass(ClassMetadata $class, string $hydratorCla
165164 if (isset ($ mapping ['alsoLoadFields ' ])) {
166165 foreach ($ mapping ['alsoLoadFields ' ] as $ name ) {
167166 $ code .= sprintf (
168- <<<EOF
167+ <<<'PHP'
169168
170- // AlsoLoad(" $ name ")
171- if (! array_key_exists('%1 \ $s', \ $data) && array_key_exists(' $ name', \ $data)) {
172- \ $data['%1 \ $s'] = \ $data[' $ name'];
169+ // AlsoLoad("%1$s ")
170+ if (! array_key_exists('%1$s', $data) && array_key_exists('$name', $data)) {
171+ $data['%1$s'] = $data['$name'];
173172 }
174173
175- EOF
174+ PHP
176175 ,
177176 $ mapping ['name ' ],
178177 );
@@ -181,48 +180,48 @@ private function generateHydratorClass(ClassMetadata $class, string $hydratorCla
181180
182181 if ($ mapping ['type ' ] === 'date ' ) {
183182 $ code .= sprintf (
184- <<<'EOF '
183+ <<<'PHP '
185184
186185 // Field(type: "date")
187186 if (array_key_exists('%1$s', $data) && ($data['%1$s'] !== null || ($this->class->fieldMappings['%2$s']['nullable'] ?? false))) {
188187 $value = $data['%1$s'];
189- %3$s
188+ $return = Type::getType(' %3$s')->convertToPHPValue($value);
190189 $this->class->propertyAccessors['%2$s']->setValue($document, $return === null ? null : clone $return);
191190 $hydratedData['%2$s'] = $return;
192191 }
193192
194- EOF
193+ PHP
195194 ,
196195 $ mapping ['name ' ],
197196 $ mapping ['fieldName ' ],
198- Type:: getType ( $ mapping ['type ' ])-> closureToPHP () ,
197+ $ mapping ['type ' ],
199198 );
200199 } elseif (! isset ($ mapping ['association ' ])) {
201200 $ code .= sprintf (
202- <<<EOF
203-
204- // Field(type: " { $ mapping [ ' type ' ]} ")
205- if (isset( \ $data['%1 \ $s']) || (! empty( \ $this->class->fieldMappings['%2 \ $s']['nullable']) && array_key_exists('%1 \ $s', \ $data))) {
206- \ $value = \ $data['%1 \ $s'];
207- if ( \ $value !== null) {
208- \ $typeIdentifier = \ $this->class->fieldMappings['%2 \ $s']['type'];
209- %3 \$ s
201+ <<<'PHP'
202+
203+ // Field(type: "%3$s ")
204+ if (isset($data['%1$s']) || (! empty($this->class->fieldMappings['%2$s']['nullable']) && array_key_exists('%1$s', $data))) {
205+ $value = $data['%1$s'];
206+ if ($value !== null) {
207+ $typeIdentifier = $this->class->fieldMappings['%2$s']['type'];
208+ $return = Type::getType('%3$s')->convertToPHPValue($value);
210209 } else {
211- \ $return = null;
210+ $return = null;
212211 }
213- \ $this->class->propertyAccessors['%2 \ $s']->setValue( \ $document, \ $return);
214- \ $hydratedData['%2 \ $s'] = \ $return;
212+ $this->class->propertyAccessors['%2$s']->setValue($document, $return);
213+ $hydratedData['%2$s'] = $return;
215214 }
216215
217- EOF
216+ PHP
218217 ,
219218 $ mapping ['name ' ],
220219 $ mapping ['fieldName ' ],
221- Type:: getType ( $ mapping ['type ' ])-> closureToPHP () ,
220+ $ mapping ['type ' ],
222221 );
223222 } elseif ($ mapping ['association ' ] === ClassMetadata::REFERENCE_ONE && $ mapping ['isOwningSide ' ]) {
224223 $ code .= sprintf (
225- <<<'EOF '
224+ <<<'PHP '
226225
227226 // ReferenceOne
228227 if (isset($data['%1$s']) || (! empty($this->class->fieldMappings['%2$s']['nullable']) && array_key_exists('%1$s', $data))) {
@@ -243,7 +242,7 @@ private function generateHydratorClass(ClassMetadata $class, string $hydratorCla
243242 $hydratedData['%2$s'] = $return;
244243 }
245244
246- EOF
245+ PHP
247246 ,
248247 $ mapping ['name ' ],
249248 $ mapping ['fieldName ' ],
@@ -252,22 +251,22 @@ private function generateHydratorClass(ClassMetadata $class, string $hydratorCla
252251 } elseif ($ mapping ['association ' ] === ClassMetadata::REFERENCE_ONE && $ mapping ['isInverseSide ' ]) {
253252 if (isset ($ mapping ['repositoryMethod ' ]) && $ mapping ['repositoryMethod ' ]) {
254253 $ code .= sprintf (
255- <<<'EOF '
254+ <<<'PHP '
256255
257256 $className = $this->class->fieldMappings['%2$s']['targetDocument'];
258257 $return = $this->dm->getRepository($className)->%3$s($document);
259258 $this->class->propertyAccessors['%2$s']->setValue($document, $return);
260259 $hydratedData['%2$s'] = $return;
261260
262- EOF
261+ PHP
263262 ,
264263 $ mapping ['name ' ],
265264 $ mapping ['fieldName ' ],
266265 $ mapping ['repositoryMethod ' ],
267266 );
268267 } else {
269268 $ code .= sprintf (
270- <<<'EOF '
269+ <<<'PHP '
271270
272271 $mapping = $this->class->fieldMappings['%2$s'];
273272 $className = $mapping['targetDocument'];
@@ -283,15 +282,15 @@ private function generateHydratorClass(ClassMetadata $class, string $hydratorCla
283282 $this->class->propertyAccessors['%2$s']->setValue($document, $return);
284283 $hydratedData['%2$s'] = $return;
285284
286- EOF
285+ PHP
287286 ,
288287 $ mapping ['name ' ],
289288 $ mapping ['fieldName ' ],
290289 );
291290 }
292291 } elseif ($ mapping ['association ' ] === ClassMetadata::REFERENCE_MANY || $ mapping ['association ' ] === ClassMetadata::EMBED_MANY ) {
293292 $ code .= sprintf (
294- <<<'EOF '
293+ <<<'PHP '
295294
296295 // %4$s
297296 $mongoData = $data['%1$s'] ?? null;
@@ -310,7 +309,7 @@ private function generateHydratorClass(ClassMetadata $class, string $hydratorCla
310309 $this->class->propertyAccessors['%2$s']->setValue($document, $return);
311310 $hydratedData['%2$s'] = $return;
312311
313- EOF
312+ PHP
314313 ,
315314 $ mapping ['name ' ],
316315 $ mapping ['fieldName ' ],
@@ -319,7 +318,7 @@ private function generateHydratorClass(ClassMetadata $class, string $hydratorCla
319318 );
320319 } elseif ($ mapping ['association ' ] === ClassMetadata::EMBED_ONE ) {
321320 $ code .= sprintf (
322- <<<'EOF '
321+ <<<'PHP '
323322
324323 // EmbedOne
325324 if (isset($data['%1$s']) || (! empty($this->class->fieldMappings['%2$s']['nullable']) && array_key_exists('%1$s', $data))) {
@@ -349,7 +348,7 @@ private function generateHydratorClass(ClassMetadata $class, string $hydratorCla
349348 $hydratedData['%2$s'] = $return;
350349 }
351350
352- EOF
351+ PHP
353352 ,
354353 $ mapping ['name ' ],
355354 $ mapping ['fieldName ' ],
@@ -360,7 +359,7 @@ private function generateHydratorClass(ClassMetadata $class, string $hydratorCla
360359
361360 $ namespace = $ this ->hydratorNamespace ;
362361 $ code = sprintf (
363- <<<EOF
362+ <<<PHP
364363<?php
365364
366365namespace $ namespace;
@@ -370,6 +369,7 @@ private function generateHydratorClass(ClassMetadata $class, string $hydratorCla
370369use Doctrine\ODM\MongoDB\Hydrator\HydratorInterface;
371370use Doctrine\ODM\MongoDB\Query\Query;
372371use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
372+ use Doctrine\ODM\MongoDB\Types\Type;
373373
374374use function array_key_exists;
375375use function gettype;
@@ -389,7 +389,7 @@ public function hydrate(object \$document, array \$data, array \$hints = []): ar
389389 return \$hydratedData;
390390 }
391391}
392- EOF
392+ PHP
393393 ,
394394 $ code ,
395395 );
0 commit comments