Coder Social home page Coder Social logo

ray.rolemodule's Introduction

Ray.RoleModule

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!

ray.rolemodule's People

Contributors

jingu avatar koriym avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

koriym jingu

ray.rolemodule's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.