src/Entity/Country.php line 17

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. use Gedmo\Blameable\Traits\BlameableEntity;
  8. use Gedmo\Timestampable\Traits\TimestampableEntity;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. #[ORM\Entity(repositoryClassCountryRepository::class)]
  13. #[UniqueEntity('isoCode2')]
  14. class Country
  15. {
  16.     use BlameableEntity//Hook blameable behaviour. Updates createdBy, updatedBy fields
  17.     use TimestampableEntity//Hook timestampable behaviour. Updates createdAt, updatedAt fields 
  18.     
  19.     
  20.     #[ORM\Id]
  21.     #[ORM\GeneratedValue(strategy"IDENTITY")]
  22.     #[ORM\Column]
  23.     #[Groups(['json'])]
  24.     private ?int $id null;
  25.     #[ORM\Column(length2uniquetrue)]
  26.     #[Assert\NotNull()]
  27.     #[Assert\Length(max2)]
  28.     private ?string $isoCode2 null;
  29.     #[ORM\Column(length100)]
  30.     #[Assert\NotNull()]
  31.     #[Assert\Length(max100)]
  32.     private ?string $name null;
  33.     #[ORM\OneToMany(mappedBy'country'targetEntityAddress::class)]
  34.     private Collection $addresses;
  35.     #[ORM\OneToMany(mappedBy'country'targetEntityProvince::class)]
  36.     private Collection $provinces;
  37.     public function __construct()
  38.     {
  39.         $this->addresses = new ArrayCollection();
  40.         $this->provinces = new ArrayCollection();
  41.     }
  42.     
  43.     public function __toString()
  44.     {
  45.         return $this->name;
  46.     }
  47.     public function getId(): ?int
  48.     {
  49.         return $this->id;
  50.     }
  51.     public function getIsoCode2(): ?string
  52.     {
  53.         return $this->isoCode2;
  54.     }
  55.     public function setIsoCode2(string $isoCode2): self
  56.     {
  57.         $this->isoCode2 $isoCode2;
  58.         return $this;
  59.     }
  60.     public function getName(): ?string
  61.     {
  62.         return $this->name;
  63.     }
  64.     public function setName(string $name): self
  65.     {
  66.         $this->name $name;
  67.         return $this;
  68.     }
  69.     /**
  70.      * @return Collection<int, Address>
  71.      */
  72.     public function getAddresses(): Collection
  73.     {
  74.         return $this->addresses;
  75.     }
  76.     public function addAddress(Address $address): self
  77.     {
  78.         if (!$this->addresses->contains($address)) {
  79.             $this->addresses->add($address);
  80.             $address->setCountry($this);
  81.         }
  82.         return $this;
  83.     }
  84.     public function removeAddress(Address $address): self
  85.     {
  86.         if ($this->addresses->removeElement($address)) {
  87.             // set the owning side to null (unless already changed)
  88.             if ($address->getCountry() === $this) {
  89.                 $address->setCountry(null);
  90.             }
  91.         }
  92.         return $this;
  93.     }
  94.     /**
  95.      * @return Collection<int, Province>
  96.      */
  97.     public function getProvinces(): Collection
  98.     {
  99.         return $this->provinces;
  100.     }
  101.     public function addProvince(Province $province): self
  102.     {
  103.         if (!$this->provinces->contains($province)) {
  104.             $this->provinces->add($province);
  105.             $province->setCountry($this);
  106.         }
  107.         return $this;
  108.     }
  109.     public function removeProvince(Province $province): self
  110.     {
  111.         if ($this->provinces->removeElement($province)) {
  112.             // set the owning side to null (unless already changed)
  113.             if ($province->getCountry() === $this) {
  114.                 $province->setCountry(null);
  115.             }
  116.         }
  117.         return $this;
  118.     }
  119. }