getRoles(); if (in_array('ROLE_CLIENT', $roles, true) && !in_array('ROLE_ADMIN', $roles, true)) { throw new AccessDeniedException('Mail not accessible to clients'); } if (!in_array('ROLE_USER', $roles, true) && !in_array('ROLE_ADMIN', $roles, true)) { throw new AccessDeniedException('ROLE_USER required'); } } /** * Verifie que l'utilisateur est ROLE_ADMIN. * * @throws AccessDeniedException */ public function ensureIsAdmin(?UserInterface $user): void { if (!$user instanceof User || !$this->authorizationChecker->isGranted('ROLE_ADMIN')) { throw new AccessDeniedException('Admin only'); } } }