public function canSwitchUser()
    {
        if ($this->getUser()->isGuest) {
            return false;
        }

        $allowSwitchUser = false;

        $rule = new AccessRule($this->ruleUserSwitch);

        /** @var Controller $userController */
        $userController = null;
        $controller = $this->module->createController('user');
        if (isset($controller[0]) && $controller[0] instanceof UserController) {
            $userController = $controller[0];
        }

        //check by rule
        if ($userController) {
            $action = $userController->createAction('set-identity');
            $user = $this->userSwitch->getMainUser();
            $request = Yii::$app->request;

            $allowSwitchUser = $rule->allows($action, $user, $request) ?: false;
        }

        return $allowSwitchUser;
    }
public function canSwitchUser()
    {
        if ($this->getUser()->isGuest) {
            return false;
        }

        $allowSwitchUser = false;

        $rule = new AccessRule($this->ruleUserSwitch);

        /** @var Controller $userController */
        $userController = null;
        $controller = $this->module->createController('user');
        if (isset($controller[0]) && $controller[0] instanceof UserController) {
            $userController = $controller[0];
        }

        //check by rule
        if ($userController) {
            $action = $userController->createAction('set-identity');
            $user = $this->userSwitch->getMainUser();
            $request = Yii::$app->request;

            $allowSwitchUser = $rule->allows($action, $user, $request) ?: false;
        }

        return $allowSwitchUser;
    }
public function canSwitchUser ( ) { if ( $ this -> getUser ( ) -> isGuest ) { return false ; } $ allowSwitchUser = false ; $ rule = new AccessRule ( $ this -> ruleUserSwitch ) ; /** @var Controller $userController */ $ userController = null ; $ controller = $ this -> module -> createController ( 'user' ) ; if ( isset ( $ controller [ 0 ] ) && $ controller [ 0 ] instanceof UserController ) { $ userController = $ controller [ 0 ] ; } //check by rule if ( $ userController ) { $ action = $ userController -> createAction ( 'set-identity' ) ; $ user = $ this -> userSwitch -> getMainUser ( ) ; $ request = Yii :: $ app -> request ; $ allowSwitchUser = $ rule -> allows ( $ action , $ user , $ request ) ? : false ; } return $ allowSwitchUser ; }
Check can main user switch identity.
@return bool
@throws InvalidConfigException
Check can main user switch identity .