1 | <?php |
||
57 | class AccessControl extends ActionFilter |
||
58 | { |
||
59 | /** |
||
60 | * @var User|array|string the user object representing the authentication status or the ID of the user application component. |
||
61 | * Starting from version 2.0.2, this can also be a configuration array for creating the object. |
||
62 | */ |
||
63 | public $user = 'user'; |
||
64 | /** |
||
65 | * @var callable a callback that will be called if the access should be denied |
||
66 | * to the current user. If not set, [[denyAccess()]] will be called. |
||
67 | * |
||
68 | * The signature of the callback should be as follows: |
||
69 | * |
||
70 | * ```php |
||
71 | * function ($rule, $action) |
||
72 | * ``` |
||
73 | * |
||
74 | * where `$rule` is the rule that denies the user, and `$action` is the current [[Action|action]] object. |
||
75 | * `$rule` can be `null` if access is denied because none of the rules matched. |
||
76 | */ |
||
77 | public $denyCallback; |
||
78 | /** |
||
79 | * @var array the default configuration of access rules. Individual rule configurations |
||
80 | * specified via [[rules]] will take precedence when the same property of the rule is configured. |
||
81 | */ |
||
82 | public $ruleConfig = ['class' => AccessRule::class]; |
||
83 | /** |
||
84 | * @var array a list of access rule objects or configuration arrays for creating the rule objects. |
||
85 | * If a rule is specified via a configuration array, it will be merged with [[ruleConfig]] first |
||
86 | * before it is used for creating the rule object. |
||
87 | * @see ruleConfig |
||
88 | */ |
||
89 | public $rules = []; |
||
90 | |||
91 | /** |
||
92 | * This method is invoked right before an action is to be executed (after all possible filters.) |
||
93 | * You may override this method to do last-minute preparation for the action. |
||
94 | * @param Action $action the action to be executed. |
||
95 | * @return boolean whether the action should continue to be executed. |
||
96 | */ |
||
97 | public function beforeAction($action) |
||
126 | |||
127 | /** |
||
128 | * Denies the access of the user. |
||
129 | * The default implementation will redirect the user to the login page if he is a guest; |
||
130 | * if the user is already logged, a 403 HTTP exception will be thrown. |
||
131 | * @param User $user the current user |
||
132 | * @throws ForbiddenHttpException if the user is already logged in. |
||
133 | */ |
||
134 | protected function denyAccess($user) |
||
142 | } |
||
143 |