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
-
Create an
UserGrantsProviderInterfaceimplementation 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']; } }
-
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
ANDoperator. - Use character
|to represent anORoperator, 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
其他信息
- 授权协议: ISC
- 更新时间: 2024-05-08