@@ 252-277 (lines=26) @@ | ||
249 | $mapping['fieldName'], |
|
250 | Type::getType($mapping['type'])->closureToPHP() |
|
251 | ); |
|
252 | } elseif ($mapping['association'] === ClassMetadata::REFERENCE_ONE && $mapping['isOwningSide']) { |
|
253 | $code .= sprintf(<<<EOF |
|
254 | ||
255 | /** @ReferenceOne */ |
|
256 | if (isset(\$data['%1\$s'])) { |
|
257 | \$reference = \$data['%1\$s']; |
|
258 | if (isset(\$this->class->fieldMappings['%2\$s']['storeAs']) && \$this->class->fieldMappings['%2\$s']['storeAs'] === ClassMetadataInfo::REFERENCE_STORE_AS_ID) { |
|
259 | \$className = \$this->class->fieldMappings['%2\$s']['targetDocument']; |
|
260 | \$mongoId = \$reference; |
|
261 | } else { |
|
262 | \$className = \$this->unitOfWork->getClassNameForAssociation(\$this->class->fieldMappings['%2\$s'], \$reference); |
|
263 | \$mongoId = \$reference['\$id']; |
|
264 | } |
|
265 | \$targetMetadata = \$this->dm->getClassMetadata(\$className); |
|
266 | \$id = \$targetMetadata->getPHPIdentifierValue(\$mongoId); |
|
267 | \$return = \$this->dm->getReference(\$className, \$id); |
|
268 | \$this->class->reflFields['%2\$s']->setValue(\$document, \$return); |
|
269 | \$hydratedData['%2\$s'] = \$return; |
|
270 | } |
|
271 | ||
272 | EOF |
|
273 | , |
|
274 | $mapping['name'], |
|
275 | $mapping['fieldName'] |
|
276 | ); |
|
277 | } elseif ($mapping['association'] === ClassMetadata::REFERENCE_ONE && $mapping['isInverseSide']) { |
|
278 | if (isset($mapping['repositoryMethod']) && $mapping['repositoryMethod']) { |
|
279 | $code .= sprintf(<<<EOF |
|
280 | ||
@@ 315-335 (lines=21) @@ | ||
312 | $mapping['fieldName'] |
|
313 | ); |
|
314 | } |
|
315 | } elseif ($mapping['association'] === ClassMetadata::REFERENCE_MANY || $mapping['association'] === ClassMetadata::EMBED_MANY) { |
|
316 | $code .= sprintf(<<<EOF |
|
317 | ||
318 | /** @Many */ |
|
319 | \$mongoData = isset(\$data['%1\$s']) ? \$data['%1\$s'] : null; |
|
320 | \$return = \$this->dm->getConfiguration()->getPersistentCollectionFactory()->create(\$this->dm, \$this->class->fieldMappings['%2\$s']); |
|
321 | \$return->setHints(\$hints); |
|
322 | \$return->setOwner(\$document, \$this->class->fieldMappings['%2\$s']); |
|
323 | \$return->setInitialized(false); |
|
324 | if (\$mongoData) { |
|
325 | \$return->setMongoData(\$mongoData); |
|
326 | } |
|
327 | \$this->class->reflFields['%2\$s']->setValue(\$document, \$return); |
|
328 | \$hydratedData['%2\$s'] = \$return; |
|
329 | ||
330 | EOF |
|
331 | , |
|
332 | $mapping['name'], |
|
333 | $mapping['fieldName'] |
|
334 | ); |
|
335 | } elseif ($mapping['association'] === ClassMetadata::EMBED_ONE) { |
|
336 | $code .= sprintf(<<<EOF |
|
337 | ||
338 | /** @EmbedOne */ |