1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace modules\rbac; |
4
|
|
|
|
5
|
|
|
use Yii; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class Bootstrap |
9
|
|
|
* @package modules\rbac |
10
|
|
|
*/ |
11
|
|
|
class Bootstrap |
12
|
|
|
{ |
13
|
|
|
public function __construct() |
14
|
|
|
{ |
15
|
|
|
$this->registerTranslate(); |
16
|
|
|
$this->registerRules(); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Translate |
21
|
|
|
*/ |
22
|
|
|
protected function registerTranslate() |
23
|
|
|
{ |
24
|
|
|
$i18n = Yii::$app->i18n; |
25
|
|
|
$i18n->translations['modules/rbac/*'] = [ |
26
|
|
|
'class' => 'yii\i18n\PhpMessageSource', |
27
|
|
|
'basePath' => '@modules/rbac/messages', |
28
|
|
|
'fileMap' => [ |
29
|
|
|
'modules/rbac/module' => 'module.php', |
30
|
|
|
], |
31
|
|
|
]; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Rules |
36
|
|
|
*/ |
37
|
|
|
protected function registerRules() |
38
|
|
|
{ |
39
|
|
|
$urlManager = Yii::$app->urlManager; |
40
|
|
|
$urlManager->addRules($this->rules()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return array |
45
|
|
|
*/ |
46
|
|
|
protected function rules() |
47
|
|
|
{ |
48
|
|
|
$rules = []; |
49
|
|
|
array_push($rules, $this->rulesRoles(), $this->rulesPermissions(), $this->rulesAssign(), $this->rulesDefault()); |
50
|
|
|
return $rules; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return array |
55
|
|
|
*/ |
56
|
|
|
protected function rulesRoles() |
57
|
|
|
{ |
58
|
|
|
return [ |
59
|
|
|
'class' => 'yii\web\GroupUrlRule', |
60
|
|
|
'routePrefix' => 'rbac/roles', |
61
|
|
|
'prefix' => 'rbac', |
62
|
|
|
'rules' => [ |
63
|
|
|
'roles' => 'index', |
64
|
|
|
'role/<id:[\w\-]+>/<_a:[\w\-]+>' => '<_a>', |
65
|
|
|
'role/<_a:[\w\-]+>' => '<_a>', |
66
|
|
|
], |
67
|
|
|
]; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return array |
72
|
|
|
*/ |
73
|
|
|
protected function rulesPermissions() |
74
|
|
|
{ |
75
|
|
|
return [ |
76
|
|
|
'class' => 'yii\web\GroupUrlRule', |
77
|
|
|
'routePrefix' => 'rbac/permissions', |
78
|
|
|
'prefix' => 'rbac', |
79
|
|
|
'rules' => [ |
80
|
|
|
'permissions' => 'index', |
81
|
|
|
'permission/<id:[\w\-]+>/<_a:[\w\-]+>' => '<_a>', |
82
|
|
|
'permission/<_a:[\w\-]+>' => '<_a>', |
83
|
|
|
], |
84
|
|
|
]; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return array |
89
|
|
|
*/ |
90
|
|
|
protected function rulesAssign() |
91
|
|
|
{ |
92
|
|
|
return [ |
93
|
|
|
'class' => 'yii\web\GroupUrlRule', |
94
|
|
|
'routePrefix' => 'rbac/assign', |
95
|
|
|
'prefix' => 'rbac/assign', |
96
|
|
|
'rules' => [ |
97
|
|
|
'' => 'index', |
98
|
|
|
'<id:\d+>/<_a:[\w\-]+>' => '<_a>', |
99
|
|
|
], |
100
|
|
|
]; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @return array |
105
|
|
|
*/ |
106
|
|
|
protected function rulesDefault() |
107
|
|
|
{ |
108
|
|
|
return [ |
109
|
|
|
'class' => 'yii\web\GroupUrlRule', |
110
|
|
|
'routePrefix' => 'rbac/default', |
111
|
|
|
'prefix' => 'rbac', |
112
|
|
|
'rules' => [ |
113
|
|
|
'' => 'index', |
114
|
|
|
'<_a:[\w\-]+>' => '<_a>', |
115
|
|
|
], |
116
|
|
|
]; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|