rmrevin / yii2-rbac-command

为 Yii2 更新 RBAC 规则的扩展

安装次数: 16,494

依赖者: 3

建议者: 0

安全性: 0

星标: 7

关注者: 2

分支: 1

开放问题: 0

类型:yii2-extension

1.6.1 2017-03-08 13:42 UTC

This package is not auto-updated.

Last update: 2024-09-14 16:57:50 UTC


README

本扩展为 Yii framework 2.0 应用程序提供更新 RBAC 规则、角色和权限的命令行工具。

安装

composer require "rmrevin/yii2-rbac-command:~1.6"

配置

创建新的控制台命令,继承 \rmrevin\yii\rbac\Command示例

<?php

namespace app\commands;

class RbacCommand extends \rmrevin\yii\rbac\Command
{

    protected function rules()
    {
        // ...
    }

    protected function roles()
    {
        // ...
    }

    protected function permissions()
    {
        // ...
    }

    protected function inheritanceRoles()
    {
        // ...
    }

    protected function inheritancePermissions()
    {
        // ...
    }
}

在控制台应用程序配置中(例如: /protected/config/console.php

<?
return [
  // ...
	'controllerMap' => [
		// ...
		'rbac' => [
			'class' => 'app\commands\RbacCommand',
			'batchSize' => 1000,
			'forceAssign' => ['user'], // force assign user role for all users
			'assignmentsMap' => [
			    'frontend.old' => 'frontend.new', // after next update all `frontend.old` will be replaced by `frontend.new`
			],
			'useTransaction' => true,
			'useCache' => true,
		],
	],
	// ...
];

用法

在命令行中执行命令

yii rbac/update