Ejemplo n.º 1
0
 /**
  * Checks if the given Role ID exists in the RolesStorage ArrayObject,
  * i.e. if the client is assigned to this role.
  *
  * @param  int|RoleInterface $id RoleInterface instance or role ID
  * @return bool
  */
 public function contains($id)
 {
     $iterator = $this->getIterator();
     $role_id = $id instanceof RoleInterface ? $id->getId() : $id;
     while ($iterator->valid()) {
         if ($iterator->current() == $role_id) {
             return true;
         }
         $iterator->next();
     }
     return false;
 }
Ejemplo n.º 2
0
 /**
  * Check if the user has a role.
  *
  * @param  RoleInterface|int $role
  * @return boolean
  */
 public function hasRole($role)
 {
     $id = $role instanceof RoleInterface ? $role->getId() : $role;
     foreach ($this->getRoles() as $role) {
         if ($id == $role->getId()) {
             return true;
         }
     }
     return false;
 }