/**
  * @param array $roles
  * @return array
  */
 protected function flattenRoles(array $roles)
 {
     $roleNames = [];
     $iterator = $this->traversalStrategy->getRolesIterator($roles);
     foreach ($iterator as $role) {
         $roleNames[] = $role;
     }
     return array_unique($roleNames);
 }
Exemple #2
0
 /**
  * Determines if access is granted by checking the roles for permission.
  *
  * @param  RoleInterface|RoleInterface[]|Traversable $roles
  * @param  mixed                                     $permission
  * @return bool
  */
 public function isGranted($roles, $permission)
 {
     if ($roles instanceof RoleInterface) {
         $roles = [$roles];
     }
     $iterator = $this->traversalStrategy->getRolesIterator($roles);
     foreach ($iterator as $role) {
         /* @var RoleInterface $role */
         if ($role->hasPermission($permission)) {
             return true;
         }
     }
     return false;
 }