1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\ORM\Utility; |
6
|
|
|
|
7
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
8
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata; |
9
|
|
|
use Doctrine\ORM\Mapping\FieldMetadata; |
10
|
|
|
use Doctrine\ORM\Mapping\ToOneAssociationMetadata; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @since 3.0 |
14
|
|
|
* @author Marco Pivetta <[email protected]> |
15
|
|
|
* |
16
|
|
|
* @internal do not use in your own codebase: no BC compliance on this class |
17
|
|
|
*/ |
18
|
|
|
final class NormalizeIdentifier |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Given a flat identifier, this method will produce another flat identifier, but with all |
22
|
|
|
* association fields that are mapped as identifiers replaced by entity references, recursively. |
23
|
|
|
* |
24
|
|
|
* @throws \Doctrine\ORM\ORMException |
25
|
|
|
*/ |
26
|
|
|
public function __invoke( |
27
|
|
|
EntityManagerInterface $entityManager, |
28
|
|
|
ClassMetadata $targetClass, |
29
|
|
|
array $flatIdentifier |
30
|
|
|
) : array { |
31
|
|
|
$normalizedAssociatedId = []; |
32
|
|
|
|
33
|
|
|
foreach ($targetClass->getDeclaredPropertiesIterator() as $name => $declaredProperty) { |
34
|
|
|
if (! \array_key_exists($name, $flatIdentifier)) { |
35
|
|
|
continue; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
if ($declaredProperty instanceof FieldMetadata) { |
39
|
|
|
$normalizedAssociatedId[$name] = $flatIdentifier[$name]; |
40
|
|
|
|
41
|
|
|
continue; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
if ($declaredProperty instanceof ToOneAssociationMetadata) { |
45
|
|
|
$targetIdMetadata = $entityManager->getClassMetadata($declaredProperty->getTargetEntity()); |
46
|
|
|
|
47
|
|
|
// Note: the ORM prevents using an entity with a composite identifier as an identifier association |
48
|
|
|
// therefore, reset($targetIdMetadata->identifier) is always correct |
49
|
|
|
$normalizedAssociatedId[$name] = $entityManager->getReference( |
50
|
|
|
$targetIdMetadata->getClassName(), |
|
|
|
|
51
|
|
|
$this->__invoke( |
52
|
|
|
$entityManager, |
53
|
|
|
$targetIdMetadata, |
|
|
|
|
54
|
|
|
[reset($targetIdMetadata->identifier) => $flatIdentifier[$name]] |
|
|
|
|
55
|
|
|
) |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return $normalizedAssociatedId; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.