1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\ORM\Mapping; |
6
|
|
|
|
7
|
|
|
use Doctrine\ORM\Reflection\ReflectionService; |
8
|
|
|
use ReflectionClass; |
9
|
|
|
use ReflectionException; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* A <tt>ComponentMetadata</tt> instance holds object-relational property mapping. |
13
|
|
|
*/ |
14
|
|
|
abstract class ComponentMetadata |
15
|
|
|
{ |
16
|
|
|
/** @var string */ |
17
|
|
|
protected $className; |
18
|
|
|
|
19
|
|
|
/** @var ComponentMetadata|null */ |
20
|
|
|
protected $parent; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The ReflectionClass instance of the component class. |
24
|
|
|
* |
25
|
|
|
* @var ReflectionClass|null |
26
|
|
|
*/ |
27
|
|
|
protected $reflectionClass; |
28
|
|
|
|
29
|
|
|
/** @var CacheMetadata|null */ |
30
|
|
|
protected $cache; |
31
|
|
|
|
32
|
|
|
/** @var Property[] */ |
33
|
|
|
protected $properties = []; |
34
|
|
|
|
35
|
|
|
public function __construct(string $className) |
36
|
449 |
|
{ |
37
|
|
|
$this->className = $className; |
38
|
449 |
|
} |
39
|
449 |
|
|
40
|
|
|
public function getClassName() : string |
41
|
2016 |
|
{ |
42
|
|
|
return $this->className; |
43
|
2016 |
|
} |
44
|
|
|
|
45
|
|
|
public function setParent(ComponentMetadata $parent) : void |
46
|
98 |
|
{ |
47
|
|
|
$this->parent = $parent; |
48
|
98 |
|
} |
49
|
98 |
|
|
50
|
|
|
public function getParent() : ?ComponentMetadata |
51
|
1217 |
|
{ |
52
|
|
|
return $this->parent; |
53
|
1217 |
|
} |
54
|
|
|
|
55
|
|
|
public function wakeupReflection(ReflectionService $reflectionService) : void |
56
|
1954 |
|
{ |
57
|
|
|
// Restore ReflectionClass and properties |
58
|
|
|
$this->reflectionClass = $reflectionService->getClass($this->className); |
59
|
1954 |
|
|
60
|
|
|
if (! $this->reflectionClass) { |
61
|
1954 |
|
return; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$this->className = $this->reflectionClass->getName(); |
65
|
1954 |
|
|
66
|
|
|
foreach ($this->properties as $property) { |
67
|
1954 |
|
/** @var Property $property */ |
68
|
|
|
$property->wakeupReflection($reflectionService); |
69
|
1951 |
|
} |
70
|
|
|
} |
71
|
1954 |
|
|
72
|
|
|
public function getReflectionClass() : ?ReflectionClass |
73
|
540 |
|
{ |
74
|
|
|
return $this->reflectionClass; |
75
|
540 |
|
} |
76
|
|
|
|
77
|
|
|
public function setCache(?CacheMetadata $cache = null) : void |
78
|
25 |
|
{ |
79
|
|
|
$this->cache = $cache; |
80
|
25 |
|
} |
81
|
25 |
|
|
82
|
|
|
public function getCache() : ?CacheMetadata |
83
|
181 |
|
{ |
84
|
|
|
return $this->cache; |
85
|
181 |
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return iterable|Property[] |
89
|
|
|
*/ |
90
|
|
|
public function getPropertiesIterator() : iterable |
91
|
1485 |
|
{ |
92
|
|
|
foreach ($this->properties as $name => $property) { |
93
|
1485 |
|
yield $name => $property; |
|
|
|
|
94
|
1484 |
|
} |
95
|
|
|
} |
96
|
1484 |
|
|
97
|
|
|
/** |
98
|
|
|
* @throws ReflectionException |
99
|
|
|
* @throws MappingException |
100
|
|
|
*/ |
101
|
|
|
public function addProperty(Property $property) : void |
102
|
416 |
|
{ |
103
|
|
|
$className = $this->getClassName(); |
104
|
416 |
|
$propertyName = $property->getName(); |
105
|
416 |
|
|
106
|
|
|
if ($this->hasProperty($propertyName)) { |
107
|
416 |
|
throw MappingException::duplicateProperty($className, $this->getProperty($propertyName)); |
|
|
|
|
108
|
2 |
|
} |
109
|
|
|
|
110
|
|
|
$property->setDeclaringClass($this); |
111
|
416 |
|
|
112
|
|
|
$this->properties[$propertyName] = $property; |
113
|
416 |
|
} |
114
|
416 |
|
|
115
|
|
|
public function hasProperty(string $propertyName) : bool |
116
|
416 |
|
{ |
117
|
|
|
return isset($this->properties[$propertyName]); |
118
|
416 |
|
} |
119
|
|
|
|
120
|
|
|
public function getProperty(string $propertyName) : ?Property |
121
|
1808 |
|
{ |
122
|
|
|
return $this->properties[$propertyName] ?? null; |
123
|
1808 |
|
} |
124
|
|
|
} |
125
|
|
|
|