From 27192ef2ffe9faa600bb38334d0e24e2f2e12d9d Mon Sep 17 00:00:00 2001 From: Mathieu Ducrot Date: Mon, 25 Mar 2024 16:40:45 +0100 Subject: [PATCH] Add common entity trait/interface --- src/Entity/AddressInterface.php | 14 +++++ src/Entity/AddressTrait.php | 76 ++++++++++++++++++++++++++ src/Entity/EmailInterface.php | 10 ++++ src/Entity/EmailTrait.php | 30 ++++++++++ src/Entity/NameableInterface.php | 10 ++++ src/Entity/NameableTrait.php | 26 +++++++++ src/Entity/OrganizationInterface.php | 12 ++++ src/Entity/OrganizationTrait.php | 42 ++++++++++++++ src/Entity/PersonNameableInterface.php | 18 ++++++ src/Entity/PersonNameableTrait.php | 60 ++++++++++++++++++++ src/Entity/PhoneInterface.php | 10 ++++ src/Entity/PhoneTrait.php | 27 +++++++++ src/Entity/SirenInterface.php | 10 ++++ src/Entity/SirenTrait.php | 27 +++++++++ src/Entity/WebsiteInterface.php | 10 ++++ src/Entity/WebsiteTrait.php | 26 +++++++++ 16 files changed, 408 insertions(+) create mode 100644 src/Entity/AddressInterface.php create mode 100644 src/Entity/AddressTrait.php create mode 100644 src/Entity/EmailInterface.php create mode 100644 src/Entity/EmailTrait.php create mode 100644 src/Entity/NameableInterface.php create mode 100644 src/Entity/NameableTrait.php create mode 100644 src/Entity/OrganizationInterface.php create mode 100644 src/Entity/OrganizationTrait.php create mode 100644 src/Entity/PersonNameableInterface.php create mode 100644 src/Entity/PersonNameableTrait.php create mode 100644 src/Entity/PhoneInterface.php create mode 100644 src/Entity/PhoneTrait.php create mode 100644 src/Entity/SirenInterface.php create mode 100644 src/Entity/SirenTrait.php create mode 100644 src/Entity/WebsiteInterface.php create mode 100644 src/Entity/WebsiteTrait.php diff --git a/src/Entity/AddressInterface.php b/src/Entity/AddressInterface.php new file mode 100644 index 0000000..9434c95 --- /dev/null +++ b/src/Entity/AddressInterface.php @@ -0,0 +1,14 @@ +address; + } + + public function setAddress(?string $address): self + { + $this->address = $address; + + return $this; + } + + public function getAdditionalAddress(): ?string + { + return $this->additionalAddress; + } + + public function setAdditionalAddress(?string $additionalAddress): self + { + $this->additionalAddress = $additionalAddress; + + return $this; + } + + public function getPostalCode(): ?string + { + return $this->postalCode; + } + + public function setPostalCode(?string $postalCode): self + { + if (strlen($postalCode) === 4) { + $postalCode = '0' . $postalCode; + } + $this->postalCode = $postalCode; + + return $this; + } + + public function getCity(): ?string + { + return $this->city; + } + + public function setCity(?string $city): self + { + $this->city = $city; + + return $this; + } +} diff --git a/src/Entity/EmailInterface.php b/src/Entity/EmailInterface.php new file mode 100644 index 0000000..4fda2c6 --- /dev/null +++ b/src/Entity/EmailInterface.php @@ -0,0 +1,10 @@ +email; + } + + public function setEmail(?string $email): self + { + $email = strtolower($email); + if ($email === '') { + $email = null; + } + $this->email = $email; + + return $this; + } +} diff --git a/src/Entity/NameableInterface.php b/src/Entity/NameableInterface.php new file mode 100644 index 0000000..a992776 --- /dev/null +++ b/src/Entity/NameableInterface.php @@ -0,0 +1,10 @@ +name; + } + + public function setName(string $name): self + { + $this->name = $name; + + return $this; + } +} diff --git a/src/Entity/OrganizationInterface.php b/src/Entity/OrganizationInterface.php new file mode 100644 index 0000000..eb92f9f --- /dev/null +++ b/src/Entity/OrganizationInterface.php @@ -0,0 +1,12 @@ +id; + } + + public function getOrganizationEmail(): ?string + { + return $this->organizationEmail; + } + + public function setOrganizationEmail(?string $organizationEmail): static + { + $this->organizationEmail = $organizationEmail; + + return $this; + } +} diff --git a/src/Entity/PersonNameableInterface.php b/src/Entity/PersonNameableInterface.php new file mode 100644 index 0000000..c31c11b --- /dev/null +++ b/src/Entity/PersonNameableInterface.php @@ -0,0 +1,18 @@ +getFirstName(), $this->getLastName())); + if ($toReturn === '') { + return null; + } + + return $toReturn; + } + + public function getInitial(): string + { + return sprintf( + '%s%s', + substr(trim($this->getFirstName()), 0, 1), + substr(trim($this->getLastName()), 0, 1) + ); + } + + public function getFirstName(): ?string + { + return $this->firstName; + } + + public function setFirstName(?string $firstName): self + { + $this->firstName = $firstName; + + return $this; + } + + public function getLastName(): ?string + { + return $this->lastName; + } + + public function setLastName(?string $lastName): self + { + $this->lastName = $lastName; + + return $this; + } +} diff --git a/src/Entity/PhoneInterface.php b/src/Entity/PhoneInterface.php new file mode 100644 index 0000000..84e5106 --- /dev/null +++ b/src/Entity/PhoneInterface.php @@ -0,0 +1,10 @@ +phone; + } + + public function setPhone(?string $phone): static + { + $this->phone = $phone; + + return $this; + } +} diff --git a/src/Entity/SirenInterface.php b/src/Entity/SirenInterface.php new file mode 100644 index 0000000..787a841 --- /dev/null +++ b/src/Entity/SirenInterface.php @@ -0,0 +1,10 @@ +siren; + } + + public function setSiren(?string $siren): static + { + $this->siren = $siren; + + return $this; + } +} diff --git a/src/Entity/WebsiteInterface.php b/src/Entity/WebsiteInterface.php new file mode 100644 index 0000000..cf61bb8 --- /dev/null +++ b/src/Entity/WebsiteInterface.php @@ -0,0 +1,10 @@ +website; + } + + public function setWebsite(?string $website): static + { + $this->website = $website; + + return $this; + } +}