1. Go to this page and download the library: Download alexshelkov/simpleacl 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/ */
alexshelkov / simpleacl example snippets
$view = new Rule('View');
$view->setRole(new Role('User'));
$view->setResource(new Resource('Page'));
$view->setAction(true); // true means that we allow access
var_dump((bool)$view->isAllowed('User', 'Page')); // true
$acl = new Acl();
$user = new Role('User');
$admin = new Role('Admin');
$siteFrontend = new Resource('SiteFrontend');
$siteBackend = new Resource('SiteBackend');
$acl->addRule($user, $siteFrontend, new Rule('View'), true);
$acl->addRule($admin, $siteFrontend, 'View', true); // you can use string as rule
$acl->addRule($admin, $siteBackend, 'View', true);
var_dump($acl->isAllowed('User', 'SiteFrontend', 'View')); // true
var_dump($acl->isAllowed('User', 'SiteBackend', 'View')); // false
var_dump($acl->isAllowed('Admin', 'SiteFrontend', 'View')); // true
var_dump($acl->isAllowed('Admin', 'SiteBackend', 'View')); // true
// before add $view rule to Acl you can set it action, role or resource
$acl->addRule($view);
// where is true -- is action
$acl->addRule($view, true);
// in that case action must be set before adding rule
$acl->addRule($user, $siteBackend, $view);