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