1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\ORM\Mapping\Builder; |
6
|
|
|
|
7
|
|
|
use Doctrine\ORM\Annotation; |
8
|
|
|
use Doctrine\ORM\Mapping; |
9
|
|
|
use function assert; |
10
|
|
|
|
11
|
|
|
class ManyToOneAssociationMetadataBuilder extends ToOneAssociationMetadataBuilder |
12
|
|
|
{ |
13
|
|
|
/** @var Annotation\ManyToOne */ |
14
|
|
|
private $manyToOneAnnotation; |
15
|
|
|
|
16
|
149 |
|
public function withManyToOneAnnotation(Annotation\ManyToOne $manyToOneAnnotation) : ManyToOneAssociationMetadataBuilder |
17
|
|
|
{ |
18
|
149 |
|
$this->manyToOneAnnotation = $manyToOneAnnotation; |
19
|
|
|
|
20
|
149 |
|
return $this; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @internal Association metadata order of definition settings is important. |
25
|
|
|
*/ |
26
|
149 |
|
public function build() : Mapping\ManyToOneAssociationMetadata |
27
|
|
|
{ |
28
|
|
|
// Validate required fields |
29
|
149 |
|
assert($this->componentMetadata !== null); |
30
|
149 |
|
assert($this->manyToOneAnnotation !== null); |
31
|
149 |
|
assert($this->fieldName !== null); |
32
|
|
|
|
33
|
149 |
|
$componentClassName = $this->componentMetadata->getClassName(); |
34
|
149 |
|
$associationMetadata = new Mapping\ManyToOneAssociationMetadata($this->fieldName); |
35
|
|
|
|
36
|
149 |
|
$associationMetadata->setSourceEntity($componentClassName); |
37
|
149 |
|
$associationMetadata->setTargetEntity($this->getTargetEntity($this->manyToOneAnnotation->targetEntity)); |
38
|
149 |
|
$associationMetadata->setCascade($this->getCascade($this->manyToOneAnnotation->cascade)); |
39
|
149 |
|
$associationMetadata->setFetchMode($this->getFetchMode($this->manyToOneAnnotation->fetch)); |
40
|
149 |
|
$associationMetadata->setOwningSide(true); |
41
|
|
|
|
42
|
149 |
|
if (! empty($this->manyToOneAnnotation->inversedBy)) { |
43
|
96 |
|
$associationMetadata->setInversedBy($this->manyToOneAnnotation->inversedBy); |
44
|
|
|
} |
45
|
|
|
|
46
|
149 |
|
$this->buildCache($associationMetadata); |
47
|
149 |
|
$this->buildPrimaryKey($associationMetadata); |
48
|
147 |
|
$this->buildJoinColumns($associationMetadata); |
49
|
|
|
|
50
|
147 |
|
return $associationMetadata; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|