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 FullNameEmbeddable |
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
|
|
|
/** |
46
|
|
|
* @param mixed $fullNameEmbeddable |
47
|
|
|
* |
48
|
|
|
* @param bool $notify |
49
|
|
|
* |
50
|
|
|
* @return $this |
51
|
|
|
* @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
52
|
|
|
*/ |
53
|
1 |
|
public function setFullNameEmbeddable($fullNameEmbeddable, bool $notify = true): self |
54
|
|
|
{ |
55
|
1 |
|
$this->fullNameEmbeddable = $fullNameEmbeddable; |
56
|
1 |
|
$this->fullNameEmbeddable->setOwningEntity($this); |
57
|
1 |
|
if (true === $notify) { |
58
|
1 |
|
$this->notifyEmbeddablePrefixedProperties( |
|
|
|
|
59
|
1 |
|
HasFullNameEmbeddableInterface::PROP_FULL_NAME_EMBEDDABLE |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
1 |
|
return $this; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function postLoadSetOwningEntityOnFullNameEmbeddable(): void |
67
|
|
|
{ |
68
|
|
|
$this->fullNameEmbeddable->setOwningEntity($this); |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Called at construction time |
73
|
|
|
*/ |
74
|
1 |
|
private function initFullNameEmbeddable(): void |
75
|
|
|
{ |
76
|
1 |
|
$this->setFullNameEmbeddable(new FullNameEmbeddable(), false); |
77
|
1 |
|
} |
78
|
|
|
} |
79
|
|
|
|