Beispiel #1
0
 public function handle()
 {
     try {
         $defaultRoles = $this->config->get('acl.default_roles', []);
         foreach ($defaultRoles as $roleName) {
             $newRole = $this->roleManager->createRoleByName($roleName);
             $this->info(sprintf('Role %s has beed added successfully.', $newRole->getName()));
         }
     } catch (\Exception $e) {
         $this->error($e->getMessage());
     }
 }
Beispiel #2
0
 /**
  * @param $roleName
  * @return mixed
  * @throws AclException
  */
 public function addRoleByName($roleName)
 {
     try {
         $role = $this->roleManager->getRole($roleName);
     } catch (ModelNotFoundException $e) {
         $role = $this->roleManager->createRoleByName($roleName);
     }
     return $this->userManager->addRoleToUser($this->getUser(), $role);
 }