francerz/access-manager 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

francerz/access-manager

最新稳定版本:v0.1.3

Composer 安装命令:

composer require francerz/access-manager

包简介

A PSR-15 based Access Manager handler.

README 文档

README

The francerz\access-manager library provides a PSR-15 middleware class that manages access control to routes based on granted permissions.

Installation

You can install the library via Composer. Run the following command:

composer require francerz/access-manager

Usage

Using Slim Framework

  1. Create an UserGrantsProviderInterface implementation to retrieve current user grants.

    use Francerz\AccessManager\UserGrantsProviderInterface;
    
    class CurrentUserGrantsProvider implements UserGrantsProviderInterface
    {
        public function getUserGrants(): string
        {
            // Returns the current user grants.
            return $_SESSION['user_grants'];
        }
    }
  2. Configure the access middleware in your Slim\App routing:

    use Francerz\AccessManager\AccessMiddleware;
    use Slim\Routing\RouteCollectorProxy;
    
    $app = new \Slim\App();
    
    // A PSR-17 ResponseFactory implemenation
    $responseFactory = new \GuzzleHttp\Psr7\HttpFactory();
    
    $userPermissionProvider = new CurrentUserGrantsProvider();
    $accessMiddleware = new AccessMiddleware($userPermissionProvider, $responseFactory);
    
    $app->get('[/]', [HomeController::class, 'indexGet'])
        ->addMiddleware($accessMiddleware->allow('user'));
    
    $app->group('/admin', function(RouteCollectorProxy $route) {
        // Restricted admin routes.
        $route->get('[/]', [AdminController::class, 'indexGet']);
    })->addMiddleware($accessMiddleware->allow('admin'));

Permission Syntax

The allow method accept a permission string with a syntax similar to boolean logic:

  • Use space to separate individual permissions; each space acts as an AND operator.
  • Use character | to represent an OR operator, e.g., 'read | write'.

License

This library is licensed under the MIT License. see the LICENSE file for details.

统计信息

  • 总下载量: 343
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: ISC
  • 更新时间: 2024-05-08