PHP Classes

File: tests/rbac_guard_test.php

Recommend this page to a friend!
  Packages of Adrian M   PHP CRUD API Generator   tests/rbac_guard_test.php   Download  
File: tests/rbac_guard_test.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP CRUD API Generator
Create an API to access MySQL database record
Author: By
Last change:
Date: 3 months ago
Size: 558 bytes
 

Contents

Class file image Download
<?php
// Minimal test for RbacGuard allowed path (no exit)
require_once __DIR__ . '/../vendor/autoload.php';

use
App\Security\Rbac;
use
App\Security\RbacGuard;

$roles = [
   
'admin' => ['*' => ['list','read','create','update','delete']],
   
'viewer' => ['*' => ['list','read']],
];
$userRoles = ['john' => 'viewer'];

$rbac = new Rbac($roles, $userRoles);
$guard = new RbacGuard($rbac);

// Should not exit: auth enabled, role viewer, table posts, action read permitted
$guard->guard(true, 'viewer', 'posts', 'read');

echo
"rbac_guard allowed: PASS\n";