<?phpnamespace App\Entity;use App\Repository\ContactEmailRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;#[ORM\Entity(repositoryClass: ContactEmailRepository::class)]class ContactEmail implements ContactInterface{ #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: 'integer')] private $id; #[ORM\Column(type: 'string', length: 100)] private $email; #[ORM\ManyToOne(targetEntity: Person::class, cascade: ['persist'], inversedBy: 'ownedEmails')] #[ORM\JoinColumn(nullable: false)] private $owner; #[ORM\OneToMany(mappedBy: 'firstEmail', targetEntity: Person::class)] private $firstEmailPersons; #[ORM\OneToMany(mappedBy: 'secondEmail', targetEntity: Person::class)] private $secondEmailPersons; public function __construct() { $this->firstEmailPersons = new ArrayCollection(); $this->secondEmailPersons = new ArrayCollection(); } public function __toString(): string { return $this->getEmail() ?? ''; } public function getId(): ?int { return $this->id; } public function getEmail(): ?string { return $this->email; } public function setEmail(string $email): self { $this->email = $email; return $this; } public function getOwner(): ?Person { return $this->owner; } public function setOwner(Person $owner): self { $this->owner = $owner; return $this; } /** * @return Collection<int, Person> */ public function getFirstEmailPersons(): Collection { return $this->firstEmailPersons; } public function addFirstEmailPerson(Person $firstEmailPerson): self { if (!$this->firstEmailPersons->contains($firstEmailPerson)) { $this->firstEmailPersons[] = $firstEmailPerson; $firstEmailPerson->setFirstEmail($this); } return $this; } public function removeFirstEmailPerson(Person $firstEmailPerson): self { if ($this->firstEmailPersons->removeElement($firstEmailPerson)) { // set the owning side to null (unless already changed) if ($firstEmailPerson->getFirstEmail() === $this) { $firstEmailPerson->setFirstEmail(null); } } return $this; } /** * @return Collection<int, Person> */ public function getSecondEmailPersons(): Collection { return $this->secondEmailPersons; } public function addSecondEmailPerson(Person $secondEmailPerson): self { if (!$this->secondEmailPersons->contains($secondEmailPerson)) { $this->secondEmailPersons[] = $secondEmailPerson; $secondEmailPerson->setSecondEmail($this); } return $this; } public function removeSecondEmailPerson(Person $secondEmailPerson): self { if ($this->secondEmailPersons->removeElement($secondEmailPerson)) { // set the owning side to null (unless already changed) if ($secondEmailPerson->getSecondEmail() === $this) { $secondEmailPerson->setSecondEmail(null); } } return $this; } public function getFirstPerson(): ?Person { $person = $this->getFirstEmailPersons()->first(); if (false === $person) { $person = $this->getSecondEmailPersons()->first(); } return $person === false ? null : $person; } /** * @return Person[] */ public function getPersons(): array { return array_merge( $this->getFirstEmailPersons()->toArray(), $this->getSecondEmailPersons()->toArray() ); }}