1. Go to this page and download the library: Download vaened/php-sentinel 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/ */
vaened / php-sentinel example snippets
// Registry: handled by a seeder or your admin UI
$admin = $roleRegistry->create('admin', 'Administrator');
$edit = $permissionRegistry->create('posts.edit', 'Edit Posts');
// Assignment
$granter->grant($admin, $edit);
$granter->grant($user, $admin);
// Evaluation
$authorizer->can($user, ['posts.edit']); // true
$authorizer->is($user, ['admin']); // true
// Deny overrides inherited grant
$denier->deny($user, $edit);
$authorizer->can($user, ['posts.edit']); // false
// Revoke clears any denial or previous assignment
$revoker->revoke($user, $edit);
$authorizer->can($user, ['posts.edit']); // true again
use Vaened\Sentinel\Cache\CacheSettings;
use Vaened\Sentinel\Cache\SentinelCacheFactory;
$factory = SentinelCacheFactory::from(
driver: $psr16Driver,
settings: new CacheSettings(prefix: 'my_app:sentinel'),
);
use Vaened\Sentinel\Cache\AuthorizationCacheStore;
use Vaened\Sentinel\Cache\SentinelCacheFactory;
$factory = SentinelCacheFactory::as(new MyCustomCacheStore(...));
use Vaened\Sentinel\Cache\CacheSettings;
use Vaened\Sentinel\Cache\Stores\Psr16AuthorizationCacheStore;
$store = new Psr16AuthorizationCacheStore(
cache: $psr16Driver,
settings: new CacheSettings(prefix: 'my_app:sentinel'),
);
$store->invalidate(); // bumps the global version
$store->forget($subject); // invalidates one specific subject
$granter->grant($user, $admin); // user has the admin role
$granter->grant($admin, $edit, $delete); // admin role has two permissions
$granter->grant($user, $admin, $edit, $delete); // everything in one call