zendframework/zend-permissions-acl
Lightweight, flexible Access Control List (ACL) library for managing roles, resources, and privileges in PHP apps. Note: this Zend Framework repository was abandoned on 2019-12-31 and moved to laminas/laminas-permissions-acl.
This package is a legacy ACL (Access Control List) component originally from Zend Framework, now archived and unmaintained. Before integrating it, confirm there isn’t a more modern alternative (e.g., spatie/laravel-permissions for Laravel). If you must use it (e.g., in a legacy codebase), start by installing via Composer:
composer require zendframework/zend-permissions-acl:^2.7
The core concept remains simple: define roles, resources, and permissions. The package now officially supports PHP 7.3, though no other changes were introduced. For a minimal demo:
use Zend\Permissions\Acl\Acl;
use Zend\Permissions\Acl\Role\RoleInterface;
use Zend\Permissions\Acl\Resource\ResourceInterface;
$acl = new Acl();
$acl->addRole(new class implements RoleInterface { public function getRoleId() { return 'guest'; } });
$acl->addResource(new class implements ResourceInterface { public function getResourceId() { return 'blog'; } });
$acl->allow('guest', 'blog', 'view');
// Later: $acl->isAllowed('guest', 'blog', 'view'); // true
Acl in a service provider (e.g., Laravel’s AppServiceProvider), caching rules for performance. Note: Ensure your Laravel app’s PHP version (7.3+) aligns with this package’s support.config/acl.php) and load them programmatically—ideal for dynamic roles or role hierarchies.// In HandleAcl middleware
$acl = app(Acl::class);
if (!$acl->isAllowed($user->role, $resourceId, $permission)) {
abort(403);
}
RoleInterface/ResourceInterface to tie roles to Eloquent models (e.g., User::getRoleId() returning user_{$user->id}).denyAll() before selectively allow()ing to avoid accidental openness.'User' !== 'user'. Use consistent casing (e.g., lowercase).isAllowed() can become expensive with many rules. Use caching (e.g., laravel/cache) around the ACL instance or ruleset.addRole($child, $parent) only supports single inheritance. For complex hierarchies (e.g., editor inheriting from user and reviewer), build custom logic.spatie/laravel-permissions, this has no built-in facades, migrations, or blade directives. Expect boilerplate (e.g., sync roles to DB manually).classmap or custom autoloading covers it if namespace issues arise.casbin/casbin or spatie/laravel-permissions)—its API is more intuitive and actively maintained.How can I help you explore Laravel packages today?