/**
* Check access route for user.
* @param string|array $route
* @param integer|User $user
* @return boolean
*/
public static function checkRoute($route, $params = [], $user = null)
{
$config = Configs::instance();
$r = static::normalizeRoute($route);
if ($config->onlyRegisteredRoute && !isset(static::getRegisteredRoutes()[$r])) {
return true;
}
if ($user === null) {
$user = Yii::$app->getUser();
}
$userId = $user instanceof User ? $user->getId() : $user;
if ($config->strict) {
if ($user->can($r, $params)) {
return true;
}
while (($pos = strrpos($r, '/')) > 0) {
$r = substr($r, 0, $pos);
if ($user->can($r . '/*', $params)) {
return true;
}
}
return $user->can('/*', $params);
} else {
$routes = static::getRoutesByUser($userId);
if (isset($routes[$r])) {
return true;
}
while (($pos = strrpos($r, '/')) > 0) {
$r = substr($r, 0, $pos);
if (isset($routes[$r . '/*'])) {
return true;
}
}
return isset($routes['/*']);
}
}
你这不太好分析,因为这时用户自己写的而不是框架里的,而且调用了各种其它自定义的方法。大体来说就是判定用户是否可以使用此路由的一个权限判定的方法。