|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Doctrine\ORM\Mapping\Driver\Annotation\Binder; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\ORM\Annotation; |
|
8
|
|
|
use Doctrine\ORM\Mapping; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class ComponentMetadataBinder |
|
12
|
|
|
* |
|
13
|
|
|
* @package Doctrine\ORM\Mapping\Driver\Annotation\Binder |
|
14
|
|
|
* @since 3.0 |
|
15
|
|
|
* |
|
16
|
|
|
* @author Guilherme Blanco <[email protected]> |
|
17
|
|
|
*/ |
|
18
|
|
|
class EntityClassMetadataBinder |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var Mapping\ClassMetadataBuildingContext |
|
22
|
|
|
*/ |
|
23
|
|
|
private $metadataBuildingContext; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var \ReflectionClass |
|
27
|
|
|
*/ |
|
28
|
|
|
private $reflectionClass; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* [dreaming] One day we would eliminate this and only do: $reflectionClass->getAnnotations() |
|
32
|
|
|
* |
|
33
|
|
|
* @var array<string, object> |
|
34
|
|
|
*/ |
|
35
|
|
|
private $classAnnotations; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @todo guilhermeblanco This should disappear once we instantiation happens in the Driver |
|
39
|
|
|
* |
|
40
|
|
|
* @var Mapping\ClassMetadata |
|
41
|
|
|
*/ |
|
42
|
|
|
private $classMetadata; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* ComponentMetadataBinder constructor. |
|
46
|
|
|
* |
|
47
|
|
|
* @param \ReflectionClass $reflectionClass |
|
48
|
|
|
* @param array<string, object> $classAnnotations |
|
49
|
|
|
* @param Mapping\ClassMetadata $classMetadata |
|
50
|
|
|
* @param Mapping\ClassMetadataBuildingContext $metadataBuildingContext |
|
51
|
|
|
*/ |
|
52
|
|
View Code Duplication |
public function __construct( |
|
53
|
|
|
\ReflectionClass $reflectionClass, |
|
54
|
|
|
array $classAnnotations, |
|
55
|
|
|
Mapping\ClassMetadata $classMetadata, |
|
56
|
|
|
Mapping\ClassMetadataBuildingContext $metadataBuildingContext |
|
57
|
|
|
) |
|
58
|
|
|
{ |
|
59
|
|
|
$this->reflectionClass = $reflectionClass; |
|
60
|
|
|
$this->classAnnotations = $classAnnotations; |
|
61
|
|
|
$this->classMetadata = $classMetadata; |
|
62
|
|
|
$this->metadataBuildingContext = $metadataBuildingContext; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @return Mapping\ClassMetadata |
|
67
|
|
|
*/ |
|
68
|
|
|
public function bind() : Mapping\ClassMetadata |
|
69
|
|
|
{ |
|
70
|
|
|
$classMetadata = $this->classMetadata; |
|
71
|
|
|
|
|
72
|
|
|
$this->processEntityAnnotation($classMetadata, $this->classAnnotations[Annotation\Entity::class]); |
|
73
|
|
|
|
|
74
|
|
|
return $classMetadata; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param Mapping\ClassMetadata $classMetadata |
|
79
|
|
|
* @param Annotation\Entity $entityAnnotation |
|
80
|
|
|
* |
|
81
|
|
|
* @return void |
|
82
|
|
|
*/ |
|
83
|
|
|
private function processEntityAnnotation( |
|
84
|
|
|
Mapping\ClassMetadata $classMetadata, |
|
85
|
|
|
Annotation\Entity $entityAnnotation |
|
86
|
|
|
) : void |
|
87
|
|
|
{ |
|
88
|
|
|
if ($entityAnnotation->repositoryClass !== null) { |
|
89
|
|
|
$repositoryClassName = $classMetadata->fullyQualifiedClassName($entityAnnotation->repositoryClass); |
|
90
|
|
|
|
|
91
|
|
|
$classMetadata->setCustomRepositoryClassName($repositoryClassName); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
if ($entityAnnotation->readOnly) { |
|
95
|
|
|
$classMetadata->asReadOnly(); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
$classMetadata->isMappedSuperclass = false; |
|
99
|
|
|
$classMetadata->isEmbeddedClass = false; |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|