src/Entity/City.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CityRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=CityRepository::class)
  9.  */
  10. class City
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="string", length=255)
  20.      */
  21.     private $name;
  22.     /**
  23.      * @ORM\ManyToOne(targetEntity=Country::class, inversedBy="cities")
  24.      * @ORM\JoinColumn(nullable=false)
  25.      */
  26.     private $country;
  27.     /**
  28.      * @ORM\OneToMany(targetEntity=Street::class, mappedBy="city")
  29.      */
  30.     private $streets;
  31.     public function __construct()
  32.     {
  33.         $this->streets = new ArrayCollection();
  34.     }
  35.     public function getId(): ?int
  36.     {
  37.         return $this->id;
  38.     }
  39.     public function getName(): ?string
  40.     {
  41.         return $this->name;
  42.     }
  43.     public function setName(string $name): self
  44.     {
  45.         $this->name $name;
  46.         return $this;
  47.     }
  48.     public function getCountry(): ?Country
  49.     {
  50.         return $this->country;
  51.     }
  52.     public function setCountry(?Country $country): self
  53.     {
  54.         $this->country $country;
  55.         return $this;
  56.     }
  57.     /**
  58.      * @return Collection|Street[]
  59.      */
  60.     public function getStreets(): Collection
  61.     {
  62.         return $this->streets;
  63.     }
  64.     public function addStreet(Street $street): self
  65.     {
  66.         if (!$this->streets->contains($street)) {
  67.             $this->streets[] = $street;
  68.             $street->setCity($this);
  69.         }
  70.         return $this;
  71.     }
  72.     public function removeStreet(Street $street): self
  73.     {
  74.         if ($this->streets->removeElement($street)) {
  75.             // set the owning side to null (unless already changed)
  76.             if ($street->getCity() === $this) {
  77.                 $street->setCity(null);
  78.             }
  79.         }
  80.         return $this;
  81.     }
  82. }