PHP code example of dotkernel / dot-rbac-route-guard
1. Go to this page and download the library: Download dotkernel/dot-rbac-route-guard 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/ */
dotkernel / dot-rbac-route-guard example snippets
declare(strict_types=1);
use Dot\Rbac\Route\Guard\Guard\GuardInterface;
return [
'dot_authorization' => [
//define how it will treat non-matching guard rules, allow all by default
'protection_policy' => \Dot\Rbac\Route\Guard\Guard\GuardInterface::POLICY_ALLOW,
'event_listeners' => [
[
'type' => 'class or service name of the listener',
'priority' => 1,
],
],
//define custom guards here
'guard_manager' => [],
//register custom guards providers here
'guards_provider_manager' => [],
//define which guard provider to use, along with its configuration
//the guard provider should know how to build a list of GuardInterfaces based on its configuration
'guards_provider' => [
'type' => 'ArrayGuards',
'options' => [
'guards' => [
[
'type' => 'Route',
'options' => [
'rules' => [
'premium' => ['admin'],
'login' => ['guest'],
'logout' => ['admin', 'user', 'viewer'],
'account' => ['admin', 'user'],
'home' => ['*'],
],
],
],
[
'type' => 'RoutePermission',
'options' => [
'rules' => [
'premium' => ['premium'],
'account' => ['my-account'],
'logout' => ['only-logged'],
],
],
],
],
],
],
//overwrite default messages
'messages_options' => [
'messages' => [
//MessagesOptions::UNAUTHORIZED => 'You must sign in first to access the requested content',
//MessagesOptions::FORBIDDEN => 'You don\'t have enough permissions to access the requested content',
],
],
],
];