<?phpnamespace App\Entity\Gos;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;/** * @ORM\Entity(repositoryClass="App\Repository\Gos\GroupRepository") * @ORM\Table(name="user_groups") */class Group{ /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="string") */ private $name; /** * @ORM\Column(type="array") */ private $roles; /** * @ORM\ManyToMany(targetEntity="App\Entity\Gos\User", mappedBy="groups") */ private $users; public function __construct() { $this->users = new ArrayCollection(); $this->roles = array(); } public function __toString() { return $this->name; } public function getId(): ?int { return $this->id; } /** * @return Collection|User[] */ public function getUsers(): Collection { return $this->users; } public function addUser(User $user): self { if (!$this->users->contains($user)) { $this->users[] = $user; $user->addGroup($this); } return $this; } public function removeUser(User $user): self { if ($this->users->contains($user)) { $this->users->removeElement($user); $user->removeGroup($this); } return $this; } public function getName(): ?string { return $this->name; } public function setName(string $name): self { $this->name = $name; return $this; } public function getRoles(): ?array { return $this->roles; } public function hasRole($role): bool { return in_array(strtoupper($role), $this->roles, true); } public function addRole($role): self { if (!$this->hasRole($role)) { $this->roles[] = strtoupper($role); } return $this; } public function setRoles(array $roles): self { $this->roles = $roles; return $this; } public function removeRole($role): self { if (false !== $key = array_search(strtoupper($role), $this->roles, true)) { unset($this->roles[$key]); $this->roles = array_values($this->roles); } return $this; }}