1. Go to this page and download the library: Download tomkyle/rbac library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tomkyle / rbac example snippets
use \tomkyle\Roles\RolesStorage;
$roles = new RolesStorage( 1, 2 );
echo $roles->contains( 2 ) ? "YES" : "NO";
use \tomkyle\Roles\RolesStorage;
use \tomkyle\Roles\RolesAwareInterface;
use \tomkyle\AccessControlList\AccessControlList;
use \tomkyle\AccessControlList\AccessControlListAwareInterface;
class MyUser implements RolesAwareInterface {
use RolesAwareTrait;
}
class MyService implements AccessControlListAwareInterface {
use AccessControlListAwareTrait;
}
$service = new MyService;
$service->setAccessControlList( new AccessControlList( 1, 2) );
$user = new MyUser;
$user->setRoles( new RolesStorage( 2, 3 ) );
echo $service->isAllowed( $user ) ? "YES" : "NO";
use \tomkyle\Permissions\PermissionsAwareInterface;
use \tomkyle\Permissions\PermissionsAwareTrait;
use \tomkyle\Permissions\ApplyPermissionsStorage;
class MyUser implements PermissionsAwareInterface {
use PermissionsAwareTrait;
}
$user = new MyUser;
// Reads users permissions from database:
new ApplyPermissionsStorage( $user, $pdo );
echo $user->hasPermission( "my_action" ) ? "YES" : "NO";
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.