执行匹配的拦截器

@param \One\Protocol\Contracts\Request  $request
@param \One\Protocol\Contracts\Response $response

@return [\One\Protocol\Contracts\Request, \One\Protocol\Contracts\Response]
355989
public function executeInterceptors(Request $request, Response $response)
    {
        $middlewares = $this->filterMiddleware(Interceptor::class);

        foreach ($middlewares as $middleware) {
            list(
                $request,
                $response
            ) = $middleware->doIntercept($request, $response);
        }

        unset($middlewares);

        return [$request, $response];
    }
482878
protected function handleRequestHeader(Request $request, Response $response): Response
    {
        // 处理 No-Cache
        if ($request->header('Cache-Control') === 'no-cache') {
            $response = $response->withHeader('Cache-Control', [
                'no-store',
                'no-cache',
                'must-revalidate'
            ]);
        }

        // 处理 Gzip 请求
        // 不知道为什么，老是出错，还需要再查查
        // https://blog.csdn.net/cs958903980/article/details/76890034?locationNum=6&fps=1
        //
        // $encoding = $request->getHeaderLine('Accept-Encoding');

        // if (! empty($encoding)) {
        //     $negotiator = new EncodingNegotiator;
        //     $preferred = $negotiator->getBest($encoding, ['gzip']);

        //     if (! empty($preferred)) {
        //         $response = $response->withHeader('Content-Encoding', 'gzip');
        //         $response->setGzip(1);
        //     }
        //     unset($negotiator, $preferred);
        // }
        // unset($encoding);

        return $response;
    }
781450
public function fromResponse($response)
    {
        $this->page        = $response->list_info->page;
        $this->num_pages   = $response->list_info->num_pages;
        $this->num_results = $response->list_info->num_results;
        $this->page_size   = $response->list_info->page_size;

        property_exists($response, $this->list_type) && $this->setCollection($response->{$this->list_type});

        return $this;
    }
1337082
public function handle($request, $response)
    {
        // init options, don't place this in __construct, because defaultOptions could be get action name.
        if ($doptions = static::defaultOptions()) {
            $this->options = array_merge($this->options, $doptions);
        }
        
        // start ob, ob_flush() 由具体render()方法根据情况调用
        ob_start();
        
        $this->request  = $request;
        $this->response = $response;
        
        $this->getHandleStack($request);
        
        static::trigger('beforeHandle');
        
        if (!$this->handleStack) {
            return $this->response;
        }
        
        $handler = $this->getHandler();
        if (!$handler instanceof Controller) {
            $handler->request   = $request;
            $handler->response  = $response;
            $handler->module    = $this->module;
            $handler->handleStack = & $this->handleStack;
        }
        
        // call handler stack
        $output = null;
        
        foreach ($this->handleStack as $do) {
            if ($this->isStopped()) {
                if ($res = $this->getError()) {
                    $output = $this->error($res);
                }
                break;
            };
            
            $output = is_callable($do) ? call_user_func_array($do, [$request, $response]) : $handler->$do();
        }
        
        // output handle, must be run
        $this->_outputHandle($output);
        
        static::trigger('afterHandle');
        
        // Return the response
        return $this->response;
    }
683651
protected function response(Response $response)
    {
        return $this->response->create(
            (string)$response->getContent(),
            $response->getStatusCode(),
            (array)$response->headers->all()
        );
    }
329567
public function parse( Request $request, Response $response )
    {
        $error = parent::parse( $request, $response );

        if ( $error )
        {
            return $error;
        }

        $method = null;
        $params = xmlrpc_decode_request(
            $request->getContent(),
            $method,
            'utf-8'
        );

        if ( ! $params )
        {
            return self::PARSE;
        }

        if ( empty( $method ) || empty( $params ) )
        {
            return self::INVALID_REQUEST;
        }

        $this->method   = $method;
        $this->params   = $params;

        return null;
    }
530173
public function run(Request $request, Response $response)
    {
        $this["logger.service"]("System")->info("Beginning process for request.", [$request]);

        $this->setRequestProperties($request);

        $result = $this["hooks.service"]->exec(
            "application.dispatch.before",
            $request,
            $response,
            $this
        );
        if ($result === "exit"
            || (is_array($result) && in_array("exit", $result))) {
            return;
        }

        // record the time before execution
        $start = microtime(true);

        // dispatch request
        try {
            $this["routeDispatcher.service"]->dispatch($request, $response, $this);
        } catch (RouteNotFoundException $routeNotFound) {
            $this["logger.service"]("System")->error("No Route found for Request");
            $this["logger.service"]("System")->debug(
                "No Route Found Debug Information",
                ["exception" => $routeNotFound]
            );

            $response->setStatusCode(404);
            $response->setContent($this->load404Page());
            throw $routeNotFound;
        }

        $this["logger.service"]("System")->info(
            "Request has finished processing, Response is ready to be sent to "
            . "caller."
        );

        $this["hooks.service"]->exec("application.dispatch.after");

        // record the time after execution
        $end = microtime(true);
        $this["logger.service"]("System")->debug(
            "Time taken to finish Request processing",
            [
                "start"     =>  $start,
                "end"       =>  $end,
                "elapsed"   =>  $end - $start,
                "uri"       =>  $request->getRequestUri()
            ]
        );
    }
590512
public function clean(Response $response)
    {
        $body = $response->json();
        $resources = $body["list"]["resources"];

        $cleaned = array_pop($resources);

        return $cleaned;
    }
353404
public static function parseResponse(Response $response)
    {
        $jsonData = \GuzzleHttp\json_decode($response->getBody(), true);
        if ($jsonData && 0 == $jsonData['retcode']) {
            $profileData = $jsonData['result'];
            //注意获取好友详情接口并不返回account和lnick
            return EntityFactory::createEntity(Profile::class, [
                'account' => isset($profileData['account']) ? $profileData['account'] : null,
                'lnick' => isset($profileData['lnick']) ? $profileData['lnick'] : null,
                'face' => $profileData['face'],
                'birthday' => Birthday::createFromArray($profileData['birthday']),
                'occupation' => $profileData['occupation'],
                'phone' => $profileData['phone'],
                'allow' => $profileData['allow'],
                'college' => $profileData['college'],
                'uin' => $profileData['uin'],
                'constel' => $profileData['constel'],
                'blood' => $profileData['blood'],
                'homepage' => $profileData['homepage'],
                'stat' => isset($profileData['stat']) ? $profileData['stat'] : null,
                'vipInfo' => $profileData['vip_info'],
                'country' => $profileData['country'],
                'city' => $profileData['city'],
                'personal' => $profileData['personal'],
                'nick' => $profileData['nick'],
                'shengXiao' => $profileData['shengxiao'],
                'email' => $profileData['email'],
                'province' => $profileData['province'],
                'gender' => $profileData['gender'],
                'mobile' => $profileData['mobile'],
            ]);
        }
        throw new ResponseException($jsonData['retcode'], $response);
    }
186009
public static function exec($request_uri, \Swoole\Http\Request $request, \Swoole\Http\Response $response)
    {

        $filename = APP_PATH . "/public{$request_uri}";
        $extension = pathinfo($filename, PATHINFO_EXTENSION);

        // 发送Mime
        $comm_response = new Response($response);
        $contentType = $comm_response->contentType($extension);

        $config = AgileCore::getInstance()->getConfig('statics');



        // 浏览器缓存 && \Comm\Misc::isProEnv()
        if (isset($config['expire']) && $config['expire'] > 0) {
            $response->header('Cache-control', "max-age={$config['expire']}");
        }

        if (method_exists($response, 'gzip')) {
            $response->gzip(1);
        }

        self::_sendfile($filename, $response, $contentType);

    }
1238646
protected function configureIO(Request $request, Response $response)
	{
	    if (true === $request->hasParameterOption(['--ansi'])) {
	        $response->setDecorated(true);
	    } elseif (true === $request->hasParameterOption(['--no-ansi'])) {
	        $response->setDecorated(false);
	    }
	    
	    if (true === $request->hasParameterOption(['--no-interaction', '-n'])) {
	        $request->setInteractive(false);
	    }
	    
	    if (true === $request->hasParameterOption(['--quiet', '-q'])) {
	        $response->setVerbosity(Response::VERBOSITY_QUIET);
	    } else {
	        if ($request->hasParameterOption('-vvv') || $request->hasParameterOption('--verbose=3') || $request->getParameterOption('--verbose') === 3) {
	            $response->setVerbosity(Response::VERBOSITY_DEBUG);
	        } elseif ($request->hasParameterOption('-vv') || $request->hasParameterOption('--verbose=2') || $request->getParameterOption('--verbose') === 2) {
	            $response->setVerbosity(Response::VERBOSITY_VERY_VERBOSE);
	        } elseif ($request->hasParameterOption('-v') || $request->hasParameterOption('--verbose=1') || $request->hasParameterOption('--verbose') || $request->getParameterOption('--verbose')) {
	            $response->setVerbosity(Response::VERBOSITY_VERBOSE);
	        }
	    }
	}
823456
public static function toResponse($request, $response)
    {
        if ($response instanceof Responsable) {
            $response = $response->toResponse($request);
        }

        if ($response instanceof PsrResponseInterface) {
            $response = (new HttpFoundationFactory)->createResponse($response);
        } elseif ($response instanceof Model && $response->wasRecentlyCreated) {
            $response = new JsonResponse($response, 201);
        } elseif (! $response instanceof SymfonyResponse &&
                   ($response instanceof Arrayable ||
                    $response instanceof Jsonable ||
                    $response instanceof ArrayObject ||
                    $response instanceof JsonSerializable ||
                    is_array($response))) {
            $response = new JsonResponse($response);
        } elseif (! $response instanceof SymfonyResponse) {
            $response = new Response($response);
        }

        if ($response->getStatusCode() === Response::HTTP_NOT_MODIFIED) {
            $response->setNotModified();
        }

        return $response->prepare($request);
    }
1157045
public function run(ServerRequestInterface $request, ResponseInterface $response)
    {
        $route = $request->getAttribute('route');        
        $name = !empty($route->controller) ? $route->controller : 'default';
        
        try {
            $controller = call_user_func($this->getFactory(), $name);
        } catch (\Exception $ex) {
            trigger_error($ex->getMessage(), E_USER_NOTICE);
            return $this->notFound($request, $response);
        }

        if (!method_exists($controller, '__invoke')) {
            $class = get_class($controller);
            trigger_error("Can't route to controller '$class': class does not have '__invoke' method", E_USER_NOTICE);
            return $this->notFound($request, $response);
        }
        
        return $controller($request, $response);
    }
757995
public function transformEarly(Request $request, SymfonyResponse $response)
    {
        $responseModel = $response->getContent();

        if (!$responseModel instanceof ResponseModelInterface) {
            $responseModel = $this->responseModelFactory->createFromContent(
                $response
            );
        }

        $responseModel->setReturnStackTrace($this->isDebug());
        $response->setStatusCode($responseModel->getStatusCode());
        $this->forceStatusCodeHttpOK($request, $response, $responseModel);
        $response = $this->createSerializedResponse(
            $request,
            $response,
            $responseModel
        );

        return $response;
    }
1088042
public function parse( Request $request, Response $response )
    {
        $error = parent::parse( $request, $response );

        if ( $error )
        {
            return $error;
        }

        $body = json_decode( $request->getContent() );

        if ( empty( $body ) )
        {
            return self::PARSE;
        }

        if ( empty( $body->method ) || ! isset( $body->params ) )
        {
            return self::INVALID_REQUEST;
        }

        $this->id       = $body->id;
        $this->method   = $body->method;
        $this->params   = $body->params;

        return null;
    }
1007273
public static function respond(Response $response)
    {
        $next = function () use ($response) {
            return $response;
        };

        (new static())->handle(Request::capture(), $next)->send();

        exit;
    }
860479
protected function sendResetLinkResponse(Request $request, $response)
    {
        if ($request->expectsJson()) {
            return response()->json([
                'status' => trans($response)
            ]);
        }
        return back()->with('status', trans($response));
    }