https://github.com/maplephp/roles
Create and manage user roles
https://github.com/maplephp/roles
Last synced: 10 months ago
JSON representation
Create and manage user roles
- Host: GitHub
- URL: https://github.com/maplephp/roles
- Owner: MaplePHP
- License: apache-2.0
- Created: 2023-11-16T14:18:46.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-05T21:23:54.000Z (over 2 years ago)
- Last Synced: 2025-06-04T16:17:28.448Z (about 1 year ago)
- Language: PHP
- Size: 13.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Roles
Create and manage user roles
### Initiate
Initiate and set the current user role. This will usally come from the database.
```php
use MaplePHP\Roles\Role;
$loggedInUserRole = 3;
$roles = new Role($loggedInUserRole);
```
### Specify the roles
Propagate the roles with permissions for specific page
```php
$roles->set(Role::getRole("ADMIN"), "r=1&i=1&u=1&d=1");
$roles->set(Role::getRole("EDITOR"), "read=1&insert=1&update=1&delete=1");
$roles->set([
Role::getRole("AUTHOR") => "r=1&i=1&u=1&d=0",
Role::getRole("MEMBER") => "r=1&i=0&u=0&d=0",
]);
```
### Validate permissions
Now you only need to validate the permissions with in every specific controller method
```php
var_dump($roles->hasRead(), $roles->hasInsert(), $roles->hasUpdate(), $roles->hasDelete());
// Result: bool(true) bool(true) bool(true) bool(false)
```