denyCallback AccessControl AccessRule. , allow null. , denyCallback AccessRule:
public function behaviors() {
return [
'access' => [
'class' => AccessControl::className(),
'only' => ['view'],
'rules' => [
[
'allow' => true,
'actions' => ['view'],
'matchCallback' => function ($rule, $action) {
return Yii::$app->authManager->can($rule, $action);
}
],
'denyCallback' => function ($rule, $action){...}
],
],
];
}
AccessRule allows(), false null, , denyCallback , :
class MyAccessRule extends AccessRule
{
public function allows($action, $user, $request)
{
$allows = parent::allows($action, $user, $request);
if ($allows === null) {
return false;
} else {
return $allows;
}
}
}
matchCallback , , matchCallback true, (, , ..), allows() allow true false, . matchCallback false - allow null, denyCallback , AccessControl denyCallback, .
, , allows() .
class MyAccessRule extends AccessRule
{
public $allowCallback;
public function allows($action, $user, $request)
{
if(!empty($this->allowCallback) {
return call_user_func($this->allowCallback);
}
$allows = parent::allows($action, $user, $request);
if ($allows === null) {
return false;
} else {
return $allows;
}
}
}