/** * Attempt to delete the given role * * @param RoleInterface $role * @return boolean */ public function delete(RoleInterface $role) { /** * @var EloquentRole $role */ return $role->delete(); }
/** * 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; }
/** * Add a child role * * @param RoleInterface $child */ public function addChild(RoleInterface $child) { $this->children[$child->getName()] = $child; }
/** * Get the roles associated with the given identity * * @param MultiRoles|RoleInterface|string $identity * @return array * @throws InvalidArgumentException If invalid identity is provided */ public function getIdentityRoles($identity) { $roles = array(); if ($identity instanceof MultiRoles) { foreach ($identity->getRoles() as $role) { array_push($roles, $role); } } else { if ($identity instanceof RoleInterface || is_string($identity)) { array_push($roles, $identity); } else { throw new InvalidArgumentException('Invalid model specified'); } } return $roles; }
/** * 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; }