edmondscommerce /
doctrine-static-meta
| 1 | <?php declare(strict_types=1); |
||||
| 2 | |||||
| 3 | namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Traits\Geo; |
||||
| 4 | |||||
| 5 | use Doctrine\ORM\Events; |
||||
| 6 | use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder; |
||||
| 7 | use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Interfaces\Geo\HasAddressEmbeddableInterface; |
||||
| 8 | use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Interfaces\Objects\Geo\AddressEmbeddableInterface; |
||||
| 9 | use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Geo\AddressEmbeddable; |
||||
| 10 | |||||
| 11 | trait HasAddressEmbeddableTrait |
||||
| 12 | { |
||||
| 13 | /** |
||||
| 14 | * @var AddressEmbeddableInterface |
||||
| 15 | */ |
||||
| 16 | private $addressEmbeddable; |
||||
| 17 | |||||
| 18 | /** |
||||
| 19 | * @param ClassMetadataBuilder $builder |
||||
| 20 | */ |
||||
| 21 | protected static function metaForAddress(ClassMetadataBuilder $builder): void |
||||
| 22 | { |
||||
| 23 | $builder->addLifecycleEvent( |
||||
| 24 | 'postLoadSetOwningEntityOnAddressEmbeddable', |
||||
| 25 | Events::postLoad |
||||
| 26 | ); |
||||
| 27 | $builder->createEmbedded( |
||||
| 28 | HasAddressEmbeddableInterface::PROP_ADDRESS_EMBEDDABLE, |
||||
| 29 | AddressEmbeddable::class |
||||
| 30 | ) |
||||
| 31 | ->setColumnPrefix( |
||||
| 32 | HasAddressEmbeddableInterface::COLUMN_PREFIX_ADDRESS |
||||
| 33 | ) |
||||
| 34 | ->build(); |
||||
| 35 | } |
||||
| 36 | |||||
| 37 | /** |
||||
| 38 | * @return AddressEmbeddableInterface |
||||
| 39 | */ |
||||
| 40 | public function getAddressEmbeddable(): AddressEmbeddableInterface |
||||
| 41 | { |
||||
| 42 | return $this->addressEmbeddable; |
||||
| 43 | } |
||||
| 44 | |||||
| 45 | public function postLoadSetOwningEntityOnAddressEmbeddable(): void |
||||
| 46 | { |
||||
| 47 | $this->addressEmbeddable->setOwningEntity($this); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 48 | } |
||||
| 49 | |||||
| 50 | /** |
||||
| 51 | * Called at construction time |
||||
| 52 | */ |
||||
| 53 | private function initAddressEmbeddable(): void |
||||
| 54 | { |
||||
| 55 | $this->setAddressEmbeddable(new AddressEmbeddable(), false); |
||||
| 56 | } |
||||
| 57 | |||||
| 58 | /** |
||||
| 59 | * @param AddressEmbeddableInterface $address |
||||
| 60 | * |
||||
| 61 | * @param bool $notify |
||||
| 62 | * |
||||
| 63 | * @return $this |
||||
| 64 | * @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
||||
| 65 | */ |
||||
| 66 | private function setAddressEmbeddable( |
||||
| 67 | AddressEmbeddableInterface $address, |
||||
| 68 | bool $notify = true |
||||
| 69 | ): self { |
||||
| 70 | $this->addressEmbeddable = $address; |
||||
| 71 | $this->addressEmbeddable->setOwningEntity($this); |
||||
|
0 ignored issues
–
show
$this of type EdmondsCommerce\Doctrine...sAddressEmbeddableTrait is incompatible with the type EdmondsCommerce\Doctrine...TrackingPolicyInterface expected by parameter $entity of EdmondsCommerce\Doctrine...face::setOwningEntity().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 72 | if (true === $notify) { |
||||
| 73 | $this->notifyEmbeddablePrefixedProperties( |
||||
| 74 | HasAddressEmbeddableInterface::PROP_ADDRESS_EMBEDDABLE |
||||
| 75 | ); |
||||
| 76 | } |
||||
| 77 | |||||
| 78 | return $this; |
||||
| 79 | } |
||||
| 80 | } |
||||
| 81 |