ray / role-module
Role Module for Ray.Di
Installs: 115 194
Dependents: 2
Suggesters: 0
Security: 0
Stars: 4
Watchers: 10
Forks: 2
Open Issues: 0
Requires
- php: ^7.3 || ^8.0
- koriym/attributes: ^1.0
- laminas/laminas-permissions-acl: ~2.5
- ray/di: ~2.0
Requires (Dev)
- phpunit/phpunit: ^8.5
README
Installation
Composer install
$ composer require ray/role-module
Module install
You need to provide RoleProvider
.
class AppRoleProvider implements RoleProviderInterface { public function get() { return 'admin'; } }
Install module with RoleProvider
.
use Ray\RoleModule\ZendAclModule; use Ray\Di\AbstractModule; use Laminas\Permissions\Acl\Role\GenericRole; use Laminas\Permissions\Acl\Acl; class AppModule extends AbstractModule { protected function configure() { // @see http://framework.zend.com/manual/current/en/modules/zend.permissions.acl.intro.html $acl = new Acl(); $roleGuest = new GenericRole('guest'); $acl->addRole($roleGuest); $acl->addRole(new GenericRole('staff'), $roleGuest); $acl->addRole(new GenericRole('editor'), 'staff'); $acl->addRole(new GenericRole('administrator')); $this->install(new ZendAclModule($acl, AppRoleProvider::class)); } }
Usage
Simple usage:
use Ray\RoleModule\Annotation\RequiresRoles; #[RequiresRoles(['admin'])] class Foo { public function createUser($id) {
You can annotate individual method too, It has priority over class attribute.
use Ray\RoleModule\Annotation\RequiresRoles; class Foo { #[RequiresRoles(['admin', 'editor'])] public function createUser($id) {
Demo
$ php demo/run.php // It works!