src/Entity/Prefecture.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\PrefectureRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use JMS\Serializer\Annotation\ExclusionPolicy;
  8. use JMS\Serializer\Annotation\Expose;
  9. #[ORM\Entity(repositoryClassPrefectureRepository::class)]
  10. class Prefecture
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id null;
  16.     #[ORM\Column(length255)]
  17.     private ?string $name null;
  18.     #[ORM\ManyToOne(targetEntityRegion::class, inversedBy'prefectures')]
  19.         #[ORM\JoinColumn(name'id_region'referencedColumnName'id'nullablefalse)]
  20.         #[Assert\NotBlank]
  21.     private ?Region $region null;
  22.     #[ORM\OneToMany(mappedBy'prefecture'targetEntityCity::class)]
  23.     private Collection $cities;
  24.     public function __construct()
  25.     {
  26.         $this->cities = new ArrayCollection();
  27.     }
  28.     public function getId(): ?int
  29.     {
  30.         return $this->id;
  31.     }
  32.     public function getName(): ?string
  33.     {
  34.         return $this->name;
  35.     }
  36.     public function setName(string $name): self
  37.     {
  38.         $this->name $name;
  39.         return $this;
  40.     }
  41.     public function getRegion(): ?Region
  42.     {
  43.         return $this->region;
  44.     }
  45.     public function setRegion(?Region $region): self
  46.     {
  47.         $this->region $region;
  48.         return $this;
  49.     }
  50.     public function getCountry(): Country {
  51.         return $this->region->getCountry();
  52.     }
  53.     /**
  54.      * @return Collection<int, City>
  55.      */
  56.     public function getCities(): Collection
  57.     {
  58.         return $this->cities;
  59.     }
  60.     public function addCity(City $city): self
  61.     {
  62.         if (!$this->cities->contains($city)) {
  63.             $this->cities->add($city);
  64.             $city->setPrefecture($this);
  65.         }
  66.         return $this;
  67.     }
  68.     public function removeCity(City $city): self
  69.     {
  70.         if ($this->cities->removeElement($city)) {
  71.             // set the owning side to null (unless already changed)
  72.             if ($city->getPrefecture() === $this) {
  73.                 $city->setPrefecture(null);
  74.             }
  75.         }
  76.         return $this;
  77.     }
  78.     public function __toString(): string {
  79.         return  $this->getName();
  80.     }
  81. }