1. Go to this page and download the library: Download tihloh/prefab-permissions 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/ */
tihloh / prefab-permissions example snippets
$permissions = new PermissionManager([
'definitions' => __DIR__ . '/config/permissions.php',
]);
$permissions = new PermissionManager([
'definitions' => __DIR__ . '/config/permissions.json',
]);
'users.manage' => [
'name' => 'Manage Users',
'description' => 'Manage authorized user accounts.', // optional general fallback
'default' => false,
'scopes' => ['global', 'organization'],
'scope_descriptions' => [ // optional
'global' => 'Manage users across the platform.',
'organization' => 'Manage users within the selected organization.',
],
],
$permissions->permissionDescription('users.manage');
// "Manage authorized user accounts."
$permissions->permissionDescription('users.manage', 'organization');
// "Manage users within the selected organization."
$permissions->permissionScopeDescriptions('users.manage');
// ['global' => 'Manage users across the platform.', 'organization' => ...]
// The lower-level definition API also supports:
$definitions->description('users.manage', 'global');
$definitions->scopeDescriptions('users.manage');
class User implements PermissionSubjectInterface
{
public function __construct(
public int $id,
public array $groupIds = [],
) {}
public function permissionSubjectId(): int|string
{
return $this->id;
}
public function permissionGroupIds(): array
{
return $this->groupIds;
}
}
$permissions->can($user, 'documents.approve');
$permissions = new PermissionManager(
definitions: $definitions,
store: $customStore,
);
$permissions = new PermissionManager(
$definitions,
new PdoPermissionStore($pdo),
);