1 | <?php |
||
57 | class AccessControl extends ActionFilter |
||
58 | { |
||
59 | /** |
||
60 | * @var User|array|string|false 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 | * Starting from version 2.0.12, you can set it to `false` to explicitly switch this component support off for the filter. |
||
63 | */ |
||
64 | public $user = 'user'; |
||
65 | /** |
||
66 | * @var callable a callback that will be called if the access should be denied |
||
67 | * to the current user. If not set, [[denyAccess()]] will be called. |
||
68 | * |
||
69 | * The signature of the callback should be as follows: |
||
70 | * |
||
71 | * ```php |
||
72 | * function ($rule, $action) |
||
73 | * ``` |
||
74 | * |
||
75 | * where `$rule` is the rule that denies the user, and `$action` is the current [[Action|action]] object. |
||
76 | * `$rule` can be `null` if access is denied because none of the rules matched. |
||
77 | */ |
||
78 | public $denyCallback; |
||
79 | /** |
||
80 | * @var array the default configuration of access rules. Individual rule configurations |
||
81 | * specified via [[rules]] will take precedence when the same property of the rule is configured. |
||
82 | */ |
||
83 | public $ruleConfig = ['class' => AccessRule::class]; |
||
84 | /** |
||
85 | * @var array a list of access rule objects or configuration arrays for creating the rule objects. |
||
86 | * If a rule is specified via a configuration array, it will be merged with [[ruleConfig]] first |
||
87 | * before it is used for creating the rule object. |
||
88 | * @see ruleConfig |
||
89 | */ |
||
90 | public $rules = []; |
||
91 | |||
92 | |||
93 | /** |
||
94 | * Initializes the [[rules]] array by instantiating rule objects from configurations. |
||
95 | */ |
||
96 | 1 | public function init() |
|
108 | |||
109 | /** |
||
110 | * This method is invoked right before an action is to be executed (after all possible filters.) |
||
111 | * You may override this method to do last-minute preparation for the action. |
||
112 | * @param Action $action the action to be executed. |
||
113 | * @return bool whether the action should continue to be executed. |
||
114 | */ |
||
115 | public function beforeAction($action) |
||
141 | |||
142 | /** |
||
143 | * Denies the access of the user. |
||
144 | * The default implementation will redirect the user to the login page if he is a guest; |
||
145 | * if the user is already logged, a 403 HTTP exception will be thrown. |
||
146 | * @param User|false $user the current user or boolean `false` in case of detached User component |
||
147 | * @throws ForbiddenHttpException if the user is already logged in or in case of detached User component. |
||
148 | */ |
||
149 | protected function denyAccess($user) |
||
157 | } |
||
158 |