1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Traits\Geo; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Events; |
6
|
|
|
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder; |
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Interfaces\Geo\HasAddressEmbeddableInterface; |
8
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Interfaces\Objects\Geo\AddressEmbeddableInterface; |
9
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Geo\AddressEmbeddable; |
10
|
|
|
|
11
|
|
|
trait HasAddressEmbeddableTrait |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var AddressEmbeddableInterface |
15
|
|
|
*/ |
16
|
|
|
private $addressEmbeddable; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @param ClassMetadataBuilder $builder |
20
|
|
|
*/ |
21
|
2 |
|
protected static function metaForAddress(ClassMetadataBuilder $builder): void |
22
|
|
|
{ |
23
|
2 |
|
$builder->addLifecycleEvent( |
24
|
2 |
|
'postLoadSetOwningEntityOnAddressEmbeddable', |
25
|
2 |
|
Events::postLoad |
26
|
|
|
); |
27
|
2 |
|
$builder->createEmbedded( |
28
|
2 |
|
HasAddressEmbeddableInterface::PROP_ADDRESS_EMBEDDABLE, |
29
|
2 |
|
AddressEmbeddable::class |
30
|
|
|
) |
31
|
2 |
|
->setColumnPrefix( |
32
|
2 |
|
HasAddressEmbeddableInterface::COLUMN_PREFIX_ADDRESS |
33
|
|
|
) |
34
|
2 |
|
->build(); |
35
|
2 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return AddressEmbeddableInterface |
39
|
|
|
*/ |
40
|
2 |
|
public function getAddressEmbeddable(): AddressEmbeddableInterface |
41
|
|
|
{ |
42
|
2 |
|
return $this->addressEmbeddable; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param AddressEmbeddableInterface $address |
47
|
|
|
* |
48
|
|
|
* @param bool $notify |
49
|
|
|
* |
50
|
|
|
* @return $this |
51
|
|
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
52
|
|
|
*/ |
53
|
2 |
|
public function setAddressEmbeddable( |
54
|
|
|
AddressEmbeddableInterface $address, |
55
|
|
|
bool $notify = true |
56
|
|
|
): self { |
57
|
2 |
|
$this->addressEmbeddable = $address; |
58
|
2 |
|
$this->addressEmbeddable->setOwningEntity($this); |
|
|
|
|
59
|
2 |
|
if (true === $notify) { |
60
|
1 |
|
$this->notifyEmbeddablePrefixedProperties( |
|
|
|
|
61
|
1 |
|
HasAddressEmbeddableInterface::PROP_ADDRESS_EMBEDDABLE |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
2 |
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function postLoadSetOwningEntityOnAddressEmbeddable(): void |
69
|
|
|
{ |
70
|
|
|
$this->addressEmbeddable->setOwningEntity($this); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Called at construction time |
75
|
|
|
*/ |
76
|
2 |
|
private function initAddressEmbeddable(): void |
77
|
|
|
{ |
78
|
2 |
|
$this->setAddressEmbeddable(new AddressEmbeddable(), false); |
79
|
2 |
|
} |
80
|
|
|
} |
81
|
|
|
|