Backend\Classes\RoleManager

Overview

RoleManager manages the backend roles and permissions.


Protected Properties

protected array|null $permissions

permissions registered.

protected array|null $permissionRoles

permissionRoles is a list of registered permission roles.


Public Methods

public hasPermissionsForRole()

public hasPermissionsForRole($role): bool 

hasPermissionsForRole checks if the user has the permissions for a role.

public init()

public init(): void

init this class items

public static instance()

public static instance(): static 

instance creates a new instance of this singleton

public listPermissions()

public listPermissions(): array 

listPermissions returns a list of the registered permissions items.

public listPermissionsForRole()

public listPermissionsForRole(
    string $role,
    bool $includeOrphans = true
): array 

listPermissionsForRole returns an array of registered permissions belonging to a given role code.

public listPermissionsForUser()

public listPermissionsForUser($user): array 

listPermissionsForUser returns permissions that the user has access to.

public registerCallback()

public registerCallback(callable $callback): void

registerCallback registers a callback function that defines authentication permissions. The callback function should register permissions by calling the manager's registerPermissions() function. The manager instance is passed to the callback function as an argument. Usage:

RoleManager::registerCallback(function ($manager) {
    $manager->registerPermissions([...]);
});

public registerPermissions()

public registerPermissions(string $owner, array $definitions): void

registerPermissions registers the back-end permission items. The argument is an array of the permissions. The array keys represent the permission codes, specific for the plugin/module. Each element in the array should be an associative array with the following keys:

  • label - specifies the menu label localization string key, required.
  • order - a position of the item in the menu, optional.
  • comment - a brief comment that describes the permission, optional.
  • tab - assign this permission to a tabbed group, optional.

public removePermission()

public removePermission($owner, $code): void

removePermission removes a single back-end permission. Where owner specifies the permissions' owner plugin or module in the format Author.Plugin. Where code is the permission to remove.

public resetCache()

public resetCache(): void

resetCache resets any memory or cache involved with the sites

Protected Methods

protected loadPermissions()

protected loadPermissions(): void

loadItems from modules and plugins