src/Entity/Role.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\RoleRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClassRoleRepository::class)]
  8. class Role
  9. {
  10.     #[ORM\Id]
  11.     #[ORM\GeneratedValue]
  12.     #[ORM\Column(type'integer')]
  13.     private $id;
  14.     #[ORM\Column(type'string'length255)]
  15.     private $title;
  16.     #[ORM\ManyToMany(targetEntityUser::class, mappedBy'userRoles')]
  17.     private $users;
  18.     public function __construct()
  19.     {
  20.         $this->users = new ArrayCollection();
  21.     }
  22.     public function getId(): ?int
  23.     {
  24.         return $this->id;
  25.     }
  26.     public function getTitle(): ?string
  27.     {
  28.         return $this->title;
  29.     }
  30.     public function setTitle(string $title): self
  31.     {
  32.         $this->title $title;
  33.         return $this;
  34.     }
  35.     /**
  36.      * @return Collection|User[]
  37.      */
  38.     public function getUsers(): Collection
  39.     {
  40.         return $this->users;
  41.     }
  42.     public function addUser(User $user): self
  43.     {
  44.         if (!$this->users->contains($user)) {
  45.             $this->users[] = $user;
  46.             $user->addUserRole($this);
  47.         }
  48.         return $this;
  49.     }
  50.     public function removeUser(User $user): self
  51.     {
  52.         if ($this->users->removeElement($user)) {
  53.             $user->removeUserRole($this);
  54.         }
  55.         return $this;
  56.     }
  57. }