effinix/user-permission-bundle
最新稳定版本:1.1.3
Composer 安装命令:
composer require effinix/user-permission-bundle
包简介
Reusable Symfony bundle for permission handling
README 文档
README
With one easy attribute, you can now protect controller methods and invokable controllers e.g:
src/Controller/Controller.php <?php declare(strict_types=1); namespace App\Controller; use Effinix\UserPermissionBundle\Attribute\Attribute\Routing\RequirePermission; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Attribute\AsController; use Symfony\Component\Routing\Attribute\Route; #[AsController] class Controller { #[Route( name: 'public_website', )] #[RequirePermission('login')] public function index() { return new Response("Hello world!"); } }
Implement UserInterface to provide access to these routes
src/Entity/User.php <?php declare(strict_types=1); namespace App\Entity; use Effinix\UserPermissionBundle\DependencyInversion\UserInterface; class User implements UserInterface { ... public function hasPermission(string $permission) : bool { // check if the permission is valid for this user return in_array($permission, $this->getPermissions()); } /** * @return string[] */ public function getPermissions() : array { // domain logic way of getting user permissions (e.g. storing in the database) return ['login']; } }
Default config file:
effinix_user_permission: permission_store: provider: permissions: - login do_cache: true when@dev: effinix_user_permission: do_cache: false logger: app.my-logger
统计信息
- 总下载量: 49
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-12