PHP code example of maplephp / roles

1. Go to this page and download the library: Download maplephp/roles 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/ */

    

maplephp / roles example snippets


use MaplePHP\Roles\Role;

$loggedInUserRole = 3;
$roles = new Role($loggedInUserRole);

$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",
]);

var_dump($roles->hasRead(), $roles->hasInsert(), $roles->hasUpdate(), $roles->hasDelete());
// Result: bool(true) bool(true) bool(true) bool(false)