1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\ORM\Mapping; |
6
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Platforms\AbstractPlatform; |
8
|
|
|
use Doctrine\ORM\Reflection\ReflectionService; |
9
|
|
|
use Doctrine\ORM\Sequencing\Executor\ValueGenerationExecutor; |
10
|
|
|
use ReflectionProperty; |
11
|
|
|
|
12
|
|
|
class EmbeddedMetadata implements Property |
13
|
|
|
{ |
14
|
|
|
/** @var ClassMetadata */ |
15
|
|
|
private $declaringClass; |
16
|
|
|
|
17
|
|
|
/** @var ReflectionProperty */ |
18
|
|
|
private $reflection; |
19
|
|
|
|
20
|
|
|
/** @var string */ |
21
|
|
|
private $name; |
22
|
|
|
|
23
|
|
|
/** @var bool */ |
24
|
|
|
protected $primaryKey = false; |
25
|
|
|
|
26
|
|
|
/** @var string */ |
27
|
|
|
private $targetEntity; |
28
|
|
|
|
29
|
|
|
/** @var string */ |
30
|
|
|
private $sourceEntity; |
31
|
|
|
|
32
|
|
|
/** @var string|null */ |
33
|
|
|
private $columnPrefix; |
34
|
|
|
|
35
|
|
|
public function __construct(string $name) |
36
|
|
|
{ |
37
|
|
|
$this->name = $name; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
*/ |
43
|
|
|
public function getDeclaringClass() : ComponentMetadata |
44
|
|
|
{ |
45
|
|
|
return $this->declaringClass; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function setDeclaringClass(ComponentMetadata $declaringClass) : void |
49
|
|
|
{ |
50
|
|
|
$this->declaringClass = $declaringClass; |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
*/ |
56
|
|
|
public function getName() : string |
57
|
|
|
{ |
58
|
|
|
return $this->name; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritdoc} |
63
|
|
|
*/ |
64
|
|
|
public function setName($name) : void |
65
|
|
|
{ |
66
|
|
|
$this->name = $name; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function setPrimaryKey(bool $isPrimaryKey) : void |
70
|
|
|
{ |
71
|
|
|
$this->primaryKey = $isPrimaryKey; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function isPrimaryKey() : bool |
75
|
|
|
{ |
76
|
|
|
return $this->primaryKey; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function getTargetEntity() : string |
80
|
|
|
{ |
81
|
|
|
return $this->targetEntity; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function setTargetEntity(string $targetEntity) : void |
85
|
|
|
{ |
86
|
|
|
$this->targetEntity = $targetEntity; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function getSourceEntity() : string |
90
|
|
|
{ |
91
|
|
|
return $this->sourceEntity; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function setSourceEntity(string $sourceEntity) : void |
95
|
|
|
{ |
96
|
|
|
$this->sourceEntity = $sourceEntity; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function getColumnPrefix() : ?string |
100
|
|
|
{ |
101
|
|
|
return $this->columnPrefix; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function setColumnPrefix(string $columnPrefix) : void |
105
|
|
|
{ |
106
|
|
|
$this->columnPrefix = $columnPrefix; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* {@inheritdoc} |
111
|
|
|
*/ |
112
|
|
|
public function setValue($object, $value) : void |
113
|
|
|
{ |
114
|
|
|
$this->reflection->setValue($object, $value); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* {@inheritdoc} |
119
|
|
|
*/ |
120
|
|
|
public function getValue($object) |
121
|
|
|
{ |
122
|
|
|
return $this->reflection->getValue($object); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* {@inheritdoc} |
127
|
|
|
*/ |
128
|
|
|
public function setReflectionProperty(ReflectionProperty $reflectionProperty) : void |
129
|
|
|
{ |
130
|
|
|
$this->reflection = $reflectionProperty; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* {@inheritdoc} |
135
|
|
|
*/ |
136
|
|
|
public function wakeupReflection(ReflectionService $reflectionService) : void |
137
|
|
|
{ |
138
|
|
|
$this->setReflectionProperty( |
139
|
|
|
$reflectionService->getAccessibleProperty($this->declaringClass->getClassName(), $this->name) |
|
|
|
|
140
|
|
|
); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function getValueGenerationExecutor(AbstractPlatform $platform) : ?ValueGenerationExecutor |
144
|
|
|
{ |
145
|
|
|
return $this->isPrimaryKey() |
146
|
|
|
? new EmbeddedValueGeneratorExecutor() |
|
|
|
|
147
|
|
|
: null; |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.