33</h1 >
44
55<p align =" center " >
6- <strong>Think-authz 是一个专为ThinkPHP6.0打造的授权 (角色和权限控制)工具</strong>
6+ <strong>Think-authz 是一个专为 ThinkPHP6.0 打造的授权 (角色和权限控制)工具</strong>
77</p >
88
99<p align =" center " >
3232* [ 用法] ( #用法 )
3333 * [ 快速开始] ( #快速开始 )
3434 * [ 使用 Enforcer Api] ( #使用-enforcer-api )
35- * [ Using a middleware] ( #using-a-middleware )
36- * [ basic Enforcer Middleware] ( #basic-enforcer-middleware )
37- * [ HTTP Request Middleware ( RESTful is also supported )] ( #http-request-middleware--restful-is-also-supported- )
38- * [ Using commands] ( #using-commands )
39- * [ Cache] ( #using-cache )
35+ * [ 使用中间件] ( #使用中间件 )
4036* [ 感谢] ( #thinks )
4137* [ License] ( #license )
4238
@@ -67,7 +63,7 @@ php think tauthz:publish
6763这将自动生成 ` config/tauthz-rbac-model.conf ` 和 ` config/tauthz.php ` 文件。
6864
6965
70- 执行迁移工具(确保数据库配置信息正确):
66+ 执行迁移工具(** 确保数据库配置信息正确** ):
7167
7268```
7369php think migrate:run
@@ -95,7 +91,7 @@ Enforcer::addPolicy('writer', 'articles','edit');
9591
9692```
9793
98- You can check if a user has a permission like this :
94+ 你可以检查一个用户是否拥有某个权限 :
9995
10096``` php
10197// to check if a user has permission
@@ -109,45 +105,45 @@ if (Enforcer::enforce("eve", "articles", "edit")) {
109105
110106### 使用 Enforcer Api
111107
112- It provides a very rich api to facilitate various operations on the Policy:
108+ 它提供了非常丰富的 ` API ` ,以促进对 ` Policy ` 的各种操作:
113109
114- Gets all roles :
110+ 获取所有角色 :
115111
116112``` php
117113Enforcer::getAllRoles(); // ['writer', 'reader']
118114```
119115
120- Gets all the authorization rules in the policy.:
116+ 获取所有的角色的授权规则:
121117
122118``` php
123119Enforcer::getPolicy();
124120```
125121
126- Gets the roles that a user has.
122+ 获取某个用户的所有角色:
127123
128124``` php
129125Enforcer::getRolesForUser('eve'); // ['writer']
130126```
131127
132- Gets the users that has a role.
128+ 获取某个角色的所有用户:
133129
134130``` php
135131Enforcer::getUsersForRole('writer'); // ['eve']
136132```
137133
138- Determines whether a user has a role.
134+ 决定用户是否拥有某个角色:
139135
140136``` php
141137Enforcer::hasRoleForUser('eve', 'writer'); // true or false
142138```
143139
144- Adds a role for a user.
140+ 给用户添加角色:
145141
146142``` php
147143Enforcer::addRoleForUser('eve', 'writer');
148144```
149145
150- Adds a permission for a user or role.
146+ 赋予权限给某个用户或角色:
151147
152148``` php
153149// to user
@@ -156,37 +152,37 @@ Enforcer::addPermissionForUser('eve', 'articles', 'read');
156152Enforcer::addPermissionForUser('writer', 'articles','edit');
157153```
158154
159- Deletes a role for a user.
155+ 删除用户的角色:
160156
161157``` php
162158Enforcer::deleteRoleForUser('eve', 'writer');
163159```
164160
165- Deletes all roles for a user.
161+ 删除某个用户的所有角色:
166162
167163``` php
168164Enforcer::deleteRolesForUser('eve');
169165```
170166
171- Deletes a role.
167+ 删除单个角色:
172168
173169``` php
174170Enforcer::deleteRole('writer');
175171```
176172
177- Deletes a permission.
173+ 删除某个权限:
178174
179175``` php
180176Enforcer::deletePermission('articles', 'read'); // returns false if the permission does not exist (aka not affected).
181177```
182178
183- Deletes a permission for a user or role.
179+ 删除某个用户或角色的权限:
184180
185181``` php
186182Enforcer::deletePermissionForUser('eve', 'articles', 'read');
187183```
188184
189- Deletes permissions for a user or role.
185+ 删除某个用户或角色的所有权限:
190186
191187``` php
192188// to user
@@ -195,43 +191,46 @@ Enforcer::deletePermissionsForUser('eve');
195191Enforcer::deletePermissionsForUser('writer');
196192```
197193
198- Gets permissions for a user or role.
194+ 获取用户或角色的所有权限:
199195
200196``` php
201197Enforcer::getPermissionsForUser('eve'); // return array
202198```
203199
204- Determines whether a user has a permission.
200+ 决定某个用户是否拥有某个权限
205201
206202``` php
207203Enforcer::hasPermissionForUser('eve', 'articles', 'read'); // true or false
208204```
209205
210- ### Using a middleware
206+ 更多 ` API ` 参考 [ Casbin API ] ( https://casbin.org/docs/en/management-api ) 。
211207
212- 敬请期待...
208+ ### 使用中间件
213209
214- #### basic Enforcer Middleware
215210
211+ 该扩展包带有一个 ` Basic ` 中间件。 您可以将它们添加到您的` app/middleware.php ` 文件中:
216212
213+ ``` php
214+ <?php
217215
218- #### HTTP Request Middleware ( RESTful is also supported )
219-
220-
221- ```
216+ return [
217+ // ... 其他中间件
218+ 'alias' => [
219+ 'authz' => \tauthz\middleware\Basic::class,
220+ ],
221+ ];
222222```
223223
224- ### Using artisan commands
225-
226- 敬请期待...
227-
228- ### Using cache
224+ 然后就可以使用它们来保护路由了:
229225
230- 敬请期待...
226+ ``` php
227+ Route::get('news/:id','News/Show')
228+ ->middleware('authz', ['news', 'read']);
229+ ```
231230
232231## 感谢
233232
234- [ Casbin] ( https://github.com/php-casbin/php-casbin ) . You can find the full documentation of Casbin [ on the website ] ( https://casbin.org/ ) .
233+ [ Casbin] ( https://github.com/php-casbin/php-casbin ) ,你可以查看全部文档在其 [ 官网 ] ( https://casbin.org/ ) 上。
235234
236235## License
237236
0 commit comments