<?phpnamespace App\Entity;use App\Repository\CountryRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use Gedmo\Blameable\Traits\BlameableEntity;use Gedmo\Timestampable\Traits\TimestampableEntity;use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;use Symfony\Component\Serializer\Annotation\Groups;use Symfony\Component\Validator\Constraints as Assert;#[ORM\Entity(repositoryClass: CountryRepository::class)]#[UniqueEntity('isoCode2')]class Country{ use BlameableEntity; //Hook blameable behaviour. Updates createdBy, updatedBy fields use TimestampableEntity; //Hook timestampable behaviour. Updates createdAt, updatedAt fields #[ORM\Id] #[ORM\GeneratedValue(strategy: "IDENTITY")] #[ORM\Column] #[Groups(['json'])] private ?int $id = null; #[ORM\Column(length: 2, unique: true)] #[Assert\NotNull()] #[Assert\Length(max: 2)] private ?string $isoCode2 = null; #[ORM\Column(length: 100)] #[Assert\NotNull()] #[Assert\Length(max: 100)] private ?string $name = null; #[ORM\OneToMany(mappedBy: 'country', targetEntity: Address::class)] private Collection $addresses; #[ORM\OneToMany(mappedBy: 'country', targetEntity: Province::class)] private Collection $provinces; public function __construct() { $this->addresses = new ArrayCollection(); $this->provinces = new ArrayCollection(); } public function __toString() { return $this->name; } public function getId(): ?int { return $this->id; } public function getIsoCode2(): ?string { return $this->isoCode2; } public function setIsoCode2(string $isoCode2): self { $this->isoCode2 = $isoCode2; return $this; } public function getName(): ?string { return $this->name; } public function setName(string $name): self { $this->name = $name; return $this; } /** * @return Collection<int, Address> */ public function getAddresses(): Collection { return $this->addresses; } public function addAddress(Address $address): self { if (!$this->addresses->contains($address)) { $this->addresses->add($address); $address->setCountry($this); } return $this; } public function removeAddress(Address $address): self { if ($this->addresses->removeElement($address)) { // set the owning side to null (unless already changed) if ($address->getCountry() === $this) { $address->setCountry(null); } } return $this; } /** * @return Collection<int, Province> */ public function getProvinces(): Collection { return $this->provinces; } public function addProvince(Province $province): self { if (!$this->provinces->contains($province)) { $this->provinces->add($province); $province->setCountry($this); } return $this; } public function removeProvince(Province $province): self { if ($this->provinces->removeElement($province)) { // set the owning side to null (unless already changed) if ($province->getCountry() === $this) { $province->setCountry(null); } } return $this; }}