public function run()
    {
        if (YII_ENABLE_ERROR_HANDLER) {
            $this->get('errorHandler')->register();
        }

        try {
            $this->state = self::STATE_BEFORE_REQUEST;
            $this->trigger(RequestEvent::BEFORE);

            $this->state = self::STATE_HANDLING_REQUEST;
            $this->response = $this->handleRequest($this->getRequest());

            $this->state = self::STATE_AFTER_REQUEST;
            $this->trigger(RequestEvent::AFTER);

            $this->state = self::STATE_SENDING_RESPONSE;
            $this->response->send();

            $this->state = self::STATE_END;

            return $this->response->exitStatus;
        } catch (ExitException $e) {
            $this->end($e->statusCode, $this->response ?? null);
            return $e->statusCode;
        }
    }