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