GithubHelp home page GithubHelp logo

rahulyhg / slim-acl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from slimphp-api/slim-acl

0.0 1.0 0.0 21 KB

ACL middleware for slim, using Zend\Permissions\Acl

License: MIT License

PHP 100.00%

slim-acl's Introduction

slim-acl

ACL middleware for slim, using Zend\Permissions\Acl

Coverage Status Code Climate Build Status

Configuration passed into the middleware constructor should look like:

[
    'default_role' => 'guest',
    'roles' => [
        'guest' => [],
        'user'  => ['guest'],
        'admin' => ['user']
    ],
    /*
     * just a list of generic resources for manual checking
     * specified here so can be used in the code if needs be
     */
     'resources' => [
         'banana' => null,
         'orange' => null,
     ],
    // where we specify the guarding!
    'guards' => [
        /*
         * list of resource to roles to permissions
         * optional
         * if included all resources default to deny unless specified.
         */
        'resources' => [
            ['banana', ['user'], ['peel']],
            ['banana', ['admin']],
            ['orange', ['guest'], ['peel']],
            ['orange', ['user'], ['eat']],
        ],
        /*
         * list of literal routes for guarding.
         * optional
         * if included all routes default to deny unless specified.
         * Similar format to resource 'resource' route, roles, 'permission' action
         * ['route', ['roles'], ['methods',' methods1']]
         */
        'routes' => [
            ['/home',       ['user'],  ['get']],
            ['/user',       ['admin'], ['get', 'post']], // $app->map(['POST', 'PUT'], '/user', ...);
            ['/user/{id}',  ['user'],  ['get']], // $app->map(['GET'], '/user/{id}', ...);
        ],
        /*
         * list of callables to resolve against
         * optional
         * if included all callables default to deny unless specified.
         * 'permission' section is combined into the callable section
         * ['callable', ['roles']]
         */
        'callables' => [
            ['App\Controller\UserController',           ['user']], // $app->map(['GET'], '/user',      'App\Controller\UserController'); class with __invoke
            ['App\Controller\UserController:getAction', ['user']], // $app->map(['GET'], '/user/{id}', 'App\Controller\UserController:getAction'); class and method
        ]
    ]
]

Important: The route should be determined before the app middlewares are being fired by:

$app = new Slim\App([
    'settings'  => [
        'determineRouteBeforeAppMiddleware' => true,
    ]
]);

slim-acl's People

Contributors

gabriel403 avatar bnf avatar jcchavezs avatar

Watchers

 avatar

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.