fighting-pie / symfony-rbac
symfony 权限管理包
0.1.0
2020-11-16 06:30 UTC
Requires
- php: ^7.1
- doctrine/doctrine-bundle: ^2.1
- doctrine/orm: ^2.7
- knplabs/knp-paginator-bundle: ^5.3
- symfony/config: ^3.4 || ^4.4 || ^5.0
- symfony/dependency-injection: 4.4.*
- symfony/framework-bundle: ^4.3||^5.0
- symfony/http-foundation: ^3.4 || ^4.4 || ^5.0
- symfony/http-kernel: ^3.4 || ^4.4 || ^5.0
- symfony/property-access: ^3.4 || ^4.4 || ^5.0
- symfony/serializer: ^3.4 || ^4.4 || ^5.0
- symfony/uid: ^5.1
- symfony/yaml: ^4.3||^5.0
Requires (Dev)
- doctrine/doctrine-fixtures-bundle: ^3.3
- phpunit/phpunit: ^6.4
- symfony/browser-kit: 4.4.*
- symfony/css-selector: 4.4.*
- symfony/dotenv: 4.4.*
- symfony/maker-bundle: ^1.21
- symfony/phpunit-bridge: ^5.1
README
原理说明
安装
安装此扩展的首选方式是通过 Composer.
运行以下命令之一
php composer.phar require fighting-pie/symfony-rbac "*"
或者在 composer.json 的 require 部分添加
"fighting-pie/symfony-rbac": "*"
。
使用方法
安装扩展后,只需按以下方式修改您的应用程序配置
添加路由
#app/config/routes.yml app_file: # loads routes from the given routing file stored in some bundle resource: '@SymfonyRbacBundle/Resources/config/routing/routes.yaml' app_annotations: # loads routes from the PHP annotations of the controllers found in that directory resource: '@SymfonyRbacBundle/Controller/' type: annotation app_bundle: # loads routes from the YAML, XML or PHP files found in some bundle directory resource: '@SymfonyRbacBundle/Resources/config/routing/' type: directory
Rbac 数据库的配置(示例)
#app/config/packages/doctrine.yaml doctrine: dbal: default_connection: default connections: default: ..... rbac: driver: 'pdo_mysql' url: '%env(resolve:DATABASE_RBAC_URL)%' # IMPORTANT: You MUST configure your server version, # either here or in the DATABASE_URL env var (see .env file) #server_version: '5.7' orm: default_entity_manager: default entity_managers: default: ..... rbac: connection: rbac mappings: RbacBundle: is_bundle: true type: annotation dir: 'Entity' prefix: 'SymfonyBundle\SymfonyRbac\Entity' alias: Rbac
代码
use SymfonyRbac\Services\RbacManager; private $rbacManager; public function __construct(RbacManager $rbacManager) { $this->rbacManager = $rbacManager; $userId = 31; $permissionName = '/admin/user/31'; $res = $this->rbacManager->checkAccess($userId,$permissionName,[]); }