src/Entity/Country.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CountryRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClassCountryRepository::class)]
  8. #[ORM\Table(name'country')]
  9. class Country
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\Column(length100)]
  16.     private ?string $name null;
  17.     #[ORM\Column(name'iso_code'length2uniquetrue)]
  18.     private ?string $isoCode null;
  19.     #[ORM\Column(name'phone_code'length8nullabletrue)]
  20.     private ?string $phoneCode null;
  21.     /** @var Collection<int, Region> */
  22.     #[ORM\OneToMany(mappedBy'country'targetEntityRegion::class, cascade: ['persist'])]
  23.     private Collection $regions;
  24.     public function __construct()
  25.     {
  26.         $this->regions = new ArrayCollection();
  27.     }
  28.     public function getId(): ?int { return $this->id; }
  29.     public function getName(): ?string { return $this->name; }
  30.     public function setName(string $name): self $this->name $name; return $this; }
  31.     public function getIsoCode(): ?string { return $this->isoCode; }
  32.     public function setIsoCode(string $isoCode): self $this->isoCode strtoupper($isoCode); return $this; }
  33.     public function getPhoneCode(): ?string { return $this->phoneCode; }
  34.     public function setPhoneCode(?string $phoneCode): self $this->phoneCode $phoneCode; return $this; }
  35.     /** @return Collection<int, Region> */
  36.     public function getRegions(): Collection { return $this->regions; }
  37.     public function addRegion(Region $region): self
  38.     {
  39.         if (!$this->regions->contains($region)) {
  40.             $this->regions->add($region);
  41.             $region->setCountry($this);
  42.         }
  43.         return $this;
  44.     }
  45.     public function removeRegion(Region $region): self
  46.     {
  47.         if ($this->regions->removeElement($region)) {
  48.             if ($region->getCountry() === $this) {
  49.                 $region->setCountry(null);
  50.             }
  51.         }
  52.         return $this;
  53.     }
  54.     public function __toString(): string { return $this->name ?? ''; }
  55. }