src/Entity/HotelType.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\HotelTypeRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. #[ORM\Entity(repositoryClassHotelTypeRepository::class)]
  10. #[UniqueEntity(['name'])]
  11. class HotelType
  12. {
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column(type'integer')]
  16.     private $id;
  17.     #[ORM\Column(type'string'length128)]
  18.     #[Assert\NotBlank]
  19.     #[Assert\Length(max128)]
  20.     #[Assert\Regex(
  21.         pattern'/^[\p{L}\p{M}0-9\s\'-]+$/u',
  22.     )]
  23.     private ?string $name;
  24.     #[ORM\OneToMany(mappedBy'type'targetEntityHotel::class)]
  25.     private $hotels;
  26.     public function __construct()
  27.     {
  28.         $this->hotels = new ArrayCollection();
  29.     }
  30.     public function getId(): ?int
  31.     {
  32.         return $this->id;
  33.     }
  34.     public function getName(): ?string
  35.     {
  36.         return $this->name;
  37.     }
  38.     public function setName(string $name): self
  39.     {
  40.         $this->name $name;
  41.         return $this;
  42.     }
  43.     /**
  44.      * @return Collection<int, Hotel>
  45.      */
  46.     public function getHotels(): Collection
  47.     {
  48.         return $this->hotels;
  49.     }
  50.     public function addHotel(Hotel $hotel): self
  51.     {
  52.         if (!$this->hotels->contains($hotel)) {
  53.             $this->hotels[] = $hotel;
  54.             $hotel->setType($this);
  55.         }
  56.         return $this;
  57.     }
  58.     public function removeHotel(Hotel $hotel): self
  59.     {
  60.         if ($this->hotels->removeElement($hotel)) {
  61.             // set the owning side to null (unless already changed)
  62.             if ($hotel->getType() === $this) {
  63.                 $hotel->setType(null);
  64.             }
  65.         }
  66.         return $this;
  67.     }
  68.     public function __toString(): string
  69.     {
  70.         return $this->name;
  71.     }
  72. }