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