Process global middleware

@param Eden\Registry\Index $request  The request object
@param Eden\Registry\Index $response The response object

@return bool
488054
protected function processGlobal($request, $response)
    {
        $args = array($request, $response);
        foreach ($this->globalMiddleware as $callback) {
            //bind callback
            $callback = $callback->bindTo($this, get_class($this));
            
            if (call_user_func_array($callback, $args) === false) {
                return false;
            }
        }
        
        return true;
    }
232493
protected function callTerminableMiddleware($response)
    {
        if ($this->shouldSkipMiddleware()) {
            return;
        }

        $response = $this->prepareResponse($response);

        foreach ($this->middleware as $middleware) {
            if (! is_string($middleware)) {
                continue;
            }

            $instance = $this->make(explode(':', $middleware)[0]);

            if (method_exists($instance, 'terminate')) {
                $instance->terminate($this->make('request'), $response);
            }
        }
    }
1020804
public function resolve(Request $request, Response $response)
    {
        return $response->methodNotAllowed(
                $request->method(),
                $this->allowedMethods
        );
    }
1045635
public function onSwooleRequest($request, $response)
    {
        if (Start::$testUnity) {
            $server_port = $request->server_port;
        } else {
            $server_port = $this->getServerPort($request->fd);
        }

        $middleware_names = $this->portManager->getMiddlewares($server_port);
        $context = [];
        $path = $request->server['path_info'];
        $middlewares = $this->middlewareManager->create($middleware_names, $context, [$request, $response], true);
        //before
        try {
            $this->middlewareManager->before($middlewares);
            //client_data进行处理
            $route = $this->portManager->getRoute($server_port);
            try {
                $route->handleClientRequest($request);
                $controller_name = $route->getControllerName();
                $method_name = $this->portManager->getMethodPrefix($server_port) . $route->getMethodName();
                $path = $route->getPath();
                if ($route->getMethodName() == ConsulHelp::HEALTH) {//健康检查
                    $response->end('ok');
                } else {
                    $controller_instance = ControllerFactory::getInstance()->getController($controller_name);
                    if ($controller_instance != null) {
                        $controller_instance->setContext($context);
                        $controller_instance->setRequestResponse($request, $response, $controller_name, $method_name, $route->getParams());
                    } else {
                        throw new \Exception('no controller');
                    }
                }
            } catch (\Throwable $e) {
                $route->errorHttpHandle($e, $request, $response);
            }
        } catch (\Exception $e) {
            //被中断
        }
        //after
        try {
            $this->middlewareManager->after($middlewares, $path);
        } catch (\Exception $e) {
            //被中断
        }
        $this->middlewareManager->destory($middlewares);
        if (Start::getDebug()) {
            secho("DEBUG", $context);
        }
        unset($context);
    }
807232
protected function processRoutes($request, $response)
    {
        $method = strtoupper($request->get('method'));
        
        //if no routing on this
        if (!isset($this->routeMiddleware[$method])
        || !is_array($this->routeMiddleware[$method])) {
            return false;
        }
        
        $args = array($request, $response);
        $path = $request->get('path', 'string');
        
        //determine the route
        foreach ($this->routeMiddleware[$method] as $route) {
            $pattern = $route[0];
            $callback = $route[1];
            
            $regex = str_replace('**', '!!', $pattern);
            $regex = str_replace('*', '([^/]*)', $regex);
            $regex = str_replace('!!', '(.*)', $regex);
            
            $regex = '#^'.$regex.'(.*)#';
            if (!preg_match($regex, $path, $matches)) {
                continue;
            }
            
            //get dynamic variables
            $variables = $this->getVariables($matches);
            
            //and stuff it in the request object
            $request->set('variables', $variables);
            
            //bind callback
            $callback = $callback->bindTo($this, get_class($this));
            
            //call the callback
            //and keep going unles they say explicitly to stop
            if (call_user_func_array($callback, $args) === false) {
                break;
            }
        }
        
        return true;
    }
197391
public function dispatch(ServerRequest $request, Response $response)
    {
        if (Router::getRequest(true) !== $request) {
            Router::pushRequest($request);
        }
        $beforeEvent = $this->dispatchEvent('Dispatcher.beforeDispatch', compact('request', 'response'));

        $request = $beforeEvent->getData('request');
        if ($beforeEvent->getResult() instanceof Response) {
            return $beforeEvent->getResult();
        }

        // Use the controller built by an beforeDispatch
        // event handler if there is one.
        if ($beforeEvent->getData('controller') instanceof Controller) {
            $controller = $beforeEvent->getData('controller');
        } else {
            $controller = $this->factory->create($request, $response);
        }

        $response = $this->_invoke($controller);
        if ($request->getParam('return')) {
            return $response;
        }

        $afterEvent = $this->dispatchEvent('Dispatcher.afterDispatch', compact('request', 'response'));

        return $afterEvent->getData('response');
    }
590793
public function onRequest(Request $request, Response $response)
    {
        // Initialize Request and Response and set to RequestContent
        $psr7Request = \Swoft\Http\Message\Server\Request::loadFromSwooleRequest($request);
        $psr7Response = new \Swoft\Http\Message\Server\Response($response);

        /** @var \Swoft\Http\Server\ServerDispatcher $dispatcher */
        $dispatcher = App::getBean('serverDispatcher');
        $dispatcher->dispatch($psr7Request, $psr7Response);
    }
380268
public function method($event, $request = [], Response $response = null)
    {
        if (is_array($request)) {
            $request = Request::i()->load()->setStage($request);
        }

        if (!($request instanceof Request)) {
            $request = Request::i()->load();
        }

        if (is_null($response)) {
            $response = Response::i()->load();
        }

        $this->trigger($event, $request, $response);

        if ($response->isError()) {
            return false;
        }

        return $response->getResults();
    }
463200
public function executeFilters(Request $request, Response $response)
    {
        $middlewares = $this->filterMiddleware(Filter::class);

        foreach ($middlewares as $middleware) {
            if (($returnResponse = $middleware->doFilter($request, $response)) !== null) {
                return $returnResponse;
            }
            unset($returnResponse);
        }

        unset($middlewares);
    }
170255
public function execute(ServerRequestInterface $request, ResponseInterface $response) : ResponseInterface {
		$httpRequestResponse = new HTTPRequestResponseContainer($request, $response);

		$this->dispatchRequestFilters($httpRequestResponse);

		$this->dispatchResponseFilters($httpRequestResponse);

		return $httpRequestResponse->getResponse();
	}
390593
public function process(RequestInterface $request, HandlerInterface $handler)
    {
        $middleware = $this->callback;

        return $middleware($request, $handler);
    }
316197
public function run(ServerRequestInterface $request, ResponseInterface $response)
    {
        $route = $request->getAttribute('route');
        $callback = !empty($route->fn) ? $route->fn : null;

        if (!is_callable($callback)) {
            trigger_error("'fn' property of route shoud be a callable", E_USER_NOTICE);
            return $this->notFound($request, $response);
        }

        return $callback($request, $response);
    }
1313206
public function terminate(Request $request, $response)
    {
        if ($this->isLaravel()) {
            $this->getKernel()->terminate($request, $response);

            return;
        }

        $app = $this->getApplication();
        $reflection = new \ReflectionObject($app);

        $middleware = $reflection->getProperty('middleware');
        $middleware->setAccessible(true);

        $callTerminableMiddleware = $reflection->getMethod('callTerminableMiddleware');
        $callTerminableMiddleware->setAccessible(true);

        if (count($middleware->getValue($app)) > 0) {
            $callTerminableMiddleware->invoke($app, $response);
        }
    }
1247287
public function execute(ServerRequestInterface $request, ResponseInterface $response)
    {
        try {
            return $this->router->start($request, $response);
        } catch (\Exception $e) {
            $this->logger->warning('Unexpected exception: ' . $e->getMessage());
            $this->logger->debug($e->__toString());

            return $response->withStatus(500)
                ->withBody(new StringStream($e->getMessage()));
        }
    }
1327286
public function execute(\Owl\Http\Request $request, \Owl\Http\Response $response)
    {
        $exception_handler = $this->getExceptionHandler();
        $method = $request->getMethod();
        try {
            if (!in_array($method, ['HEAD', 'OPTIONS', 'GET', 'POST', 'PUT', 'DELETE', 'PATCH'])) {
                throw \Owl\Http\Exception::factory(501);
            }

            $this->middleware->execute([$request, $response]);
        } catch (\Exception $exception) {
            call_user_func($exception_handler, $exception, $request, $response);
        } catch (\Throwable $error) {
            call_user_func($exception_handler, $error, $request, $response);
        }

        if (!TEST) {
            $response->end();
        }

        if (function_exists('fastcgi_finish_request')) {
            fastcgi_finish_request();
        }
    }
1101623
public function terminate($request, $response)
    {
        $routeMiddlewares = $this->gatherRouteMiddlewares($request);
        foreach (array_merge($routeMiddlewares, $this->middleware) as $middleware) {
            $instance = $this->app->make($middleware);
            if ($instance instanceof TerminableMiddleware) {
                $instance->terminate($request, $response);
            }
        }
        $this->app->terminate();
    }
1143100
public function executeTerminators(Request $request, Response $response): Response
    {
        $middlewares = $this->filterMiddleware(Terminator::class);

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

        unset($middlewares);

        return $response;
    }