edmondscommerce /
doctrine-static-meta
| 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 | protected static function metaForFullNameEmbeddable(ClassMetadataBuilder $builder): void |
||
| 22 | { |
||
| 23 | $builder->addLifecycleEvent( |
||
| 24 | 'postLoadSetOwningEntityOnFullNameEmbeddable', |
||
| 25 | Events::postLoad |
||
| 26 | ); |
||
| 27 | $builder->createEmbedded( |
||
| 28 | HasFullNameEmbeddableInterface::PROP_FULL_NAME_EMBEDDABLE, |
||
| 29 | FullNameEmbeddable::class |
||
| 30 | ) |
||
| 31 | ->setColumnPrefix( |
||
| 32 | HasFullNameEmbeddableInterface::COLUMN_PREFIX_FULL_NAME |
||
| 33 | ) |
||
| 34 | ->build(); |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @return mixed |
||
| 39 | */ |
||
| 40 | public function getFullNameEmbeddable(): FullNameEmbeddableInterface |
||
| 41 | { |
||
| 42 | return $this->fullNameEmbeddable; |
||
| 43 | } |
||
| 44 | |||
| 45 | public function postLoadSetOwningEntityOnFullNameEmbeddable(): void |
||
| 46 | { |
||
| 47 | $this->fullNameEmbeddable->setOwningEntity($this); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Called at construction time |
||
| 52 | */ |
||
| 53 | private function initFullNameEmbeddable(): void |
||
| 54 | { |
||
| 55 | $this->setFullNameEmbeddable(new FullNameEmbeddable(), false); |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @param mixed $fullNameEmbeddable |
||
| 60 | * |
||
| 61 | * @param bool $notify |
||
| 62 | * |
||
| 63 | * @return $this |
||
| 64 | * @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
||
| 65 | */ |
||
| 66 | private function setFullNameEmbeddable($fullNameEmbeddable, bool $notify = true): self |
||
| 67 | { |
||
| 68 | $this->fullNameEmbeddable = $fullNameEmbeddable; |
||
| 69 | $this->fullNameEmbeddable->setOwningEntity($this); |
||
| 70 | if (true === $notify) { |
||
| 71 | $this->notifyEmbeddablePrefixedProperties( |
||
| 72 | HasFullNameEmbeddableInterface::PROP_FULL_NAME_EMBEDDABLE |
||
| 73 | ); |
||
| 74 | } |
||
| 75 | |||
| 76 | return $this; |
||
| 77 | } |
||
| 78 | } |
||
| 79 |