['role:read']], denormalizationContext: ['groups' => ['role:write']], security: "is_granted('ROLE_USER')" )] class Role { #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] #[Groups(['role:read', 'user:read'])] private ?int $id = null; #[ORM\Column(length: 100, unique: true)] #[Groups(['role:read', 'role:write', 'user:read'])] private ?string $name = null; #[ORM\Column(length: 255, nullable: true)] #[Groups(['role:read', 'role:write', 'user:read'])] private ?string $description = null; #[ORM\Column] #[Groups(['role:read', 'role:write', 'user:read'])] private bool $isSystem = false; /** * @var Collection */ #[ORM\ManyToMany(targetEntity: User::class, mappedBy: 'userRoles')] private Collection $users; /** * @var Collection */ #[ORM\OneToMany(targetEntity: RolePermission::class, mappedBy: 'role', cascade: ['persist', 'remove'], orphanRemoval: true)] #[Groups(['role:read', 'role:write'])] private Collection $permissions; #[ORM\Column] private ?\DateTimeImmutable $createdAt = null; #[ORM\Column(nullable: true)] private ?\DateTimeImmutable $updatedAt = null; public function __construct() { $this->users = new ArrayCollection(); $this->permissions = new ArrayCollection(); $this->createdAt = new \DateTimeImmutable(); } public function getId(): ?int { return $this->id; } public function getName(): ?string { return $this->name; } public function setName(string $name): static { $this->name = $name; return $this; } public function getDescription(): ?string { return $this->description; } public function setDescription(?string $description): static { $this->description = $description; return $this; } public function isSystem(): bool { return $this->isSystem; } public function setIsSystem(bool $isSystem): static { $this->isSystem = $isSystem; return $this; } /** * @return Collection */ public function getUsers(): Collection { return $this->users; } public function addUser(User $user): static { if (!$this->users->contains($user)) { $this->users->add($user); $user->addUserRole($this); } return $this; } public function removeUser(User $user): static { if ($this->users->removeElement($user)) { $user->removeUserRole($this); } return $this; } /** * @return Collection */ public function getPermissions(): Collection { return $this->permissions; } public function addPermission(RolePermission $permission): static { if (!$this->permissions->contains($permission)) { $this->permissions->add($permission); $permission->setRole($this); } return $this; } public function removePermission(RolePermission $permission): static { if ($this->permissions->removeElement($permission)) { if ($permission->getRole() === $this) { $permission->setRole(null); } } return $this; } public function getCreatedAt(): ?\DateTimeImmutable { return $this->createdAt; } public function setCreatedAt(\DateTimeImmutable $createdAt): static { $this->createdAt = $createdAt; return $this; } public function getUpdatedAt(): ?\DateTimeImmutable { return $this->updatedAt; } public function setUpdatedAt(?\DateTimeImmutable $updatedAt): static { $this->updatedAt = $updatedAt; return $this; } public function __toString(): string { return $this->name ?? ''; } }