<?php
namespace App\Entity;
use App\Repository\CityRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=CityRepository::class)
*/
class City
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\ManyToOne(targetEntity=Country::class, inversedBy="cities")
* @ORM\JoinColumn(nullable=false)
*/
private $country;
/**
* @ORM\OneToMany(targetEntity=Street::class, mappedBy="city")
*/
private $streets;
public function __construct()
{
$this->streets = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getCountry(): ?Country
{
return $this->country;
}
public function setCountry(?Country $country): self
{
$this->country = $country;
return $this;
}
/**
* @return Collection|Street[]
*/
public function getStreets(): Collection
{
return $this->streets;
}
public function addStreet(Street $street): self
{
if (!$this->streets->contains($street)) {
$this->streets[] = $street;
$street->setCity($this);
}
return $this;
}
public function removeStreet(Street $street): self
{
if ($this->streets->removeElement($street)) {
// set the owning side to null (unless already changed)
if ($street->getCity() === $this) {
$street->setCity(null);
}
}
return $this;
}
}