Download the PHP package tobento/acl without Composer
On this page you can find all versions of the php package tobento/acl. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package acl
Short Description A simple role and user-level access control system.
License MIT
Homepage https://www.tobento.ch
Informations about the package acl
ACL Service
The ACL Service is a simple role and user-level access control system.
Table of Contents
- Getting started
- Requirements
- Highlights
- Simple Example
- Documentation
- Rules
- Default Rule
- Default Rule Custom
- Custom Rules
- Permissions
- Roles
- Trust Scope
- Rules
- Credits
Getting started
Add the latest version of the Acl service running this command.
Requirements
- PHP 8.4 or greater
Highlights
- Framework-agnostic, will work with any project
- Customize permission behaviour
- Decoupled design
Simple Example
Here is a simple example of how to use the Acl service.
Documentation
Rules
Adding and getting rules.
Default Rule
The default rule has the following permission behaviour:
Areas bahviour:
Default Rule Custom
You can easily add a custom handler for extending a specific rule behaviour.
Custom Rules
You can easily add a custom rule for a different permission strategy.
Your Rule must implement the following RuleInterface.
Lets make a custum rule for just letting user specific permissions have access ignoring acl and role permissions.
Permissions
The following methods are available on objects implementing the Permissionable Interface or the Authorizable Interface.
- Tobento\Service\Acl\Acl::class
- Tobento\Service\Acl\Role::class
Available methods for checking permissions on acl:
Checking permissions on Authorizable object:
For more information on Helper Function visit tobento/helper-function
Roles
Working with roles.
Trust Scope
Use the AclTrustScope to temporarily run code with a trusted user and a set of permissions, for example for seeding, tests or background jobs which are not triggered by a user request. When the scope ends, the previous permissions and current user are restored.
Make sure the scope is always ended, even if the trusted code throws:
Configuring the scope
Each method returns a new instance, leaving the original unchanged. Configure the scope before calling start().
| Method | Description |
|---|---|
| The trusted user which becomes the current user while the scope is active. If not set, the current user is kept. | |
The permissions to grant. If not set, every rule key known at start() is granted (full trust). |
|
A callback receiving the Acl, run on start() to configure it, for example to add rules. May be called multiple times, the callbacks run in the order they were added. |
Granting specific permissions only
Configuring the Acl
The callbacks run before the permissions are granted, so rules added by them are included when all rule keys are granted.
Good to know
- Permissions are added to the permissions already set on the Acl.
end()restores the previous permissions. - Rule changes made with
withConfigure()are not restored byend(), as the Acl cannot remove or reset rules once added. Only use it for changes you are fine persisting for the life of the Acl instance. - Permissions do not bypass areas. The trusted user needs a role which includes the areas of the rules being checked.
- Calling
start()while the scope is active, orend()while it is not active, does nothing. A scope may be started again after it has ended.
Credits
- Tobias Strub
- All Contributors