midnight / permissions
Simple permissions system
Installs: 17 656
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 1
Open Issues: 1
Requires
- php: ^7.4 || ^8.0
- psr/container: ^1.1 || ^2.0
Requires (Dev)
- eventjet/coding-standard: ^3.2
- infection/infection: ^0.22.1
- maglnet/composer-require-checker: ^3.2
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: ^0.12.32
- phpstan/phpstan-phpunit: ^0.12.16
- phpstan/phpstan-strict-rules: ^0.12.2
- phpunit/phpunit: ^9.3
This package is auto-updated.
Last update: 2024-10-14 20:51:56 UTC
README
midnight/permissions
ACL and RBAC weren't the permission models I was looking for. So I wrote my own.
Installation
Install midnight/permissions
via Composer.
Usage
You need a Container that can provide your PermissionService
with permissions. In this example, we're going to use league/container
, but any container implementing
Psr\Container\ContainerInterface
will work.
For brevity, the user and resource are arrays in this example. Most likely, they will be objects any real-world project.
class CanDoSomething implements Midnight\Permissions\PermissionInterface { public function isAllowed($user = null, $resource = null): bool { return $user === $resource['owner']; } } $container = new League\Container\Container(); $container->add('can_do_something', CanDoSomething::class); $permissionService = new Midnight\Permissions\PermissionService($container); $permissionService->isAllowed('Rudolph', 'can_do_something', ['owner' => 'Rudolph']); // true $permissionService->isAllowed('Rudolph', 'can_do_something', ['owner' => 'Christoph']); // false
Laminas Module
There's also a Laminas module that will let you access the PermissionService
via the Service Manager, add permissions
via the config and give you view helpers and controller plugins. It's called
midnight/permissions-module.