Skip to content

Object-oriented Role Based Access Control for PHP

License

Notifications You must be signed in to change notification settings

phlopsi/php-access-control

Repository files navigation

PHP 7.0 Build Status Coverage Status

Phlopsi's AccessControl API

Usage Examples

How to create a user/role/permission?

$access_control = new \Phlopsi\AccessControl\AccessControl();

$user = $access_control->createUser('phlopsi');
$role = $access_control->createRole('admin');

$access_control->createPermission('user_management/view');

How to delete a user/role/permission?

$access_control = new \Phlopsi\AccessControl\AccessControl();

$access_control->deleteUser('phlopsi');
$access_control->deleteRole('admin');
$access_control->deletePermission('user_management/view');

How to add/remove a permission to/from a role?

$access_control = new \Phlopsi\AccessControl\AccessControl();

$role = $access_control->retrieveRole('admin');

$role->addPermission('user_management/view');
$role->removePermission('user_management/view');

How to add/remove a user to/from a role?

$access_control = new \Phlopsi\AccessControl\AccessControl();

$role = $access_control->retrieveRole('admin');

$role->addUser('phlopsi');
$role->removeUser('phlopsi');

How to check, if a user has a permission?

$access_control = new \Phlopsi\AccessControl\AccessControl();

$user           = $access_control->retrieveUser('phlopsi');
$has_permission = $user->hasPermission('user_management/view');

if ($has_permission) {
    // Do stuff, that needs permission
} else {
    // Prompt login, redirect, output error message, etc.
}

How to get a list of all permissions/roles/users?

$access_control = new \Phlopsi\AccessControl\AccessControl();

$permissions = $access_control->retrievePermissionList();
$roles       = $access_control->retrieveRoleList();
$users       = $access_control->retrieveUserList();

About

Object-oriented Role Based Access Control for PHP

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published