Download the PHP package mathsgod/light-rbac without Composer
On this page you can find all versions of the php package mathsgod/light-rbac. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mathsgod/light-rbac
More information about mathsgod/light-rbac
Files in mathsgod/light-rbac
Package light-rbac
Short Description A simple and lightweight role-based access control library for PHP.
License MIT
Homepage https://github.com/mathsgod/light-rbac
Informations about the package light-rbac
Light RBAC
Light RBAC is a simple Role-Based Access Control (RBAC) system implemented in PHP.
Class: Rbac
The Rbac
class is the main class of the system. It manages roles and users.
Properties
$roles
: An instance ofRoleManager
that manages all roles in the system.$users
: An instance ofUserManager
that manages all users in the system.
Methods
addUser(string $name, array $roles = []): User
: Adds a user with the given name and roles to the system. If the user already exists, it adds the roles to the existing user.addRole(string $name)
: Adds a role with the given name to the system. If the role already exists, it returns the existing role.getRole(string $name)
: Returns the role with the given name.removeRole(string $name)
: Removes the role with the given name from the system.getUser(string $name)
: Returns the user with the given name.removeUser(string $name)
: Removes the user with the given name from the system.getPermissions(): array
: Returns all permissions in the system.
Usage
First, create an instance of the Rbac
class. Then, use the addUser
and addRole
methods to add users and roles to the system. Use the getRole
method to retrieve a role by its name.
Permissions
Permissions can be assigned to roles. A permission is a string that represents a certain action or resource. For example, post:read
, post:write
, post:delete
, etc.
Checking Permissions
To check if a user has a certain permission, use the can
method of the User
class.
Asterisk Permission
You can use the asterisk *
to represent all permissions.
You can also use the asterisk 'resource:*' to represent all permissions for a specific resource.
Checking Roles
To check if a user has a certain role, use the hasRole
method of the User
class.