Dispatch the next available middleware and return the response.

@param ServerRequestInterface $request

@return ResponseInterface
@SuppressWarnings("Unused")
@throws NotFoundExceptionInterface
4606
public function process(ServerRequestInterface $request): ResponseInterface
    {
        /** @var Middleware $middleware */
        $middleware = current($this->middlewares);
        next($this->middlewares);

        // return $middleware->process($request, $this);
        try {
            $response = $middleware->process($request, $this);
        } catch (Throwable $error) {
            // next lines
        }
        if (!isset($response)) {
            $response = App::response();
        }

        if (isset($error) && $response instanceof Response) {
            $response->setError($error);
        }
        return $response;
    }
760350
public function process(ServerRequestInterface $request, RequestHandlerInterface $next) : ResponseInterface
    {
        $response = $next->handle($request);
        $memory = $this->getPeakMemory() . ' kbyte';

        return $response->withHeader(self::HEADER, $memory);
    }
1272599
final protected function next(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface {
        if ($this->_next) {
            return $this->_next->process($request, $handler);
        }
        return $handler->handle($request);
    }
539898
public function createServer(ServerRequestInterface $request): Server
    {
        if ($this->server === null) {
            $this->server = Server::createServerFromRequest(
                $this->config('middleware'),
                $request
            );
        } else {
            $this->server->setRequest($request);
        }

        $this->setRequest($request);

        return $this->server;
    }
624894
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        $input = $this->input($request);

        $payload = $this->domain->payload($input);

        return $this->responder->response($request, $payload);
    }
732363
public function process(ServerRequestInterface $request, ResponseInterface $response) : ResponseInterface
    {
        try {
            // disable halt shutdown
            $this->haltShutDown = false;
            // if shutdown configuration for `handleShutdown` is enable
            // add handler, because on some error type, error only handle in shutdown
            if ($this->getConfiguration('handleShutdown') === true) {
                register_shutdown_function($this->shutdownHandlerCallback($request, $response));
            }

            /**
             * Dispatch Route before middleware called
             */
            if ($this->getConfiguration('dispatchRouteBeforeMiddleware') === true) {
                $router = $this->getRouter();
                // override request from route dispatcher
                $request = $this->dispatchRouterRoute($request, $router);
            }

            $response = $this->callMiddlewareStack($request, $response);
            // if configuration of : clearMiddlewareAfterExecute
            // set into true , clear the middleware
            if ($this->getConfiguration('clearMiddlewareAfterExecute') === true) {
                // reset middleware sorted
                $this->middlewareSorted = false;
                $this->middleware = [];
            }
        } catch (RequestResponseException $e) {
            $response = $this->handleForResponseException($e->getRequest(), $e->getResponse(), $e);
        } catch (\Throwable $e) {
            $response = $this->handleForResponseException($request, $response, $e);
        }

        // halt the shutdown to tell the shutdown handler no need to handle error
        $this->haltShutDown = true;
        $response           = $this->finalizeResponse($response);
        return $response;
    }
984495
public static function handle(
        ServerRequestInterface $request,
        Closure $next,
        ContainerInterface $container
    ): ResponseInterface {

        $sessionFunctions = static::getSessionFunctions($container);

        $couldBeStarted = call_user_func($sessionFunctions->getCouldBeStartedCallable());
        if ($couldBeStarted === true) {
            call_user_func($sessionFunctions->getStartCallable(), static::getSessionSettings($container));
        }

        $response = $next($request);

        call_user_func($sessionFunctions->getWriteCloseCallable());

        return $response;
    }
353341
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        if (false === $this->booted) {
            $this->boot();
        }

        try {
            return $this->pipe->handle($request);
        } catch (Exception $e) {
            $this->getContainer()->get('logger')->error($e);
        }
    }
489361
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $this->nextHandler = (isset($this->nextHandler)) ? next($this->handlers) : current($this->handlers);

        // nextHandler is a stack
        if ($this->nextHandler instanceof \Peak\Blueprint\Http\Stack) {
            return $this->returnResponse($this->handleStack($this->nextHandler, $request));
        }

        // no more handlers, look for parent
        if ($this->nextHandler === false && isset($this->parentStack)) {
            return $this->returnResponse($this->parentStack->process($request, $this->parentStack));
        } elseif ($this->nextHandler === false) {
            throw new StackEndedWithoutResponseException($this);
        }

        // resolve nextHandler if not already a object
        $handlerInstance = $this->nextHandler;
        if (is_callable($handlerInstance) || !is_object($handlerInstance)) {
            $handlerInstance = $this->handlerResolver->resolve($this->nextHandler);
        }

        // how to call the handler (MiddlewareInterface or RequestHandlerInterface)
        if ($handlerInstance instanceof MiddlewareInterface) {
            return $this->returnResponse($handlerInstance->process($request, $this));
        } elseif($handlerInstance instanceof RequestHandlerInterface) {
            return $this->returnResponse($handlerInstance->handle($request));
        }

        // at this point, the handler is not good
        throw new InvalidHandlerException($handlerInstance);
    }
689779
public function handleRequest(ServerRequestInterface $request): ResponseInterface
    {
        $this->request = $request;
        $action = $request->getQueryParams()['action'] ?? $request->getParsedBody()['action'] ?? 'overview';
        $this->initializeView($action);

        $result = call_user_func_array([$this, $action . 'Action'], [$request]);
        if ($result instanceof ResponseInterface) {
            return $result;
        }
        $this->moduleTemplate->setContent($this->view->render());
        return new HtmlResponse($this->moduleTemplate->renderContent());
    }
545251
public function process(ServerRequestInterface $request)
    {
        if (null === $this->dispatcher) {
            throw new \BadMethodCallException("Middleware stack must first be provided via the init() method.");
        }
        return $this->dispatcher->dispatch($request);
    }
61194
public function executeMiddlewares(
        ServerRequestInterface $request,
        ResponseInterface $response,
        callable $requestHandler = null,
        callable $next = null
    ) : ResponseInterface {
        return $this->getRequestMiddlewares()->__invoke($request, $response, $requestHandler, $next);
    }
1221026
public function handle(ServerRequestInterface $request): ResponseInterface{
        $routing        = $this->getRouteCollector()
            ->router($request->getUri()->getHost(), $request->getMethod())
            ->search($request->getUri()->getPath())
        ;
        $handlerBuilder = $kernel->getRequestHandlerBuilder();

        if($routing->found){
            $method = $routing->data["action"]["method"];
            $object = $kernel->getContainer()->getInstance(
                $routing->data["action"]["class"]
            );
            $action = [$object, $method];

            if($object instanceof Bundle\MiddlewareRegisterInterface){
                $object->middlewareRegister($handlerBuilder);
            }
        }else{
            $action = function(){
                throw new \Fratily\Http\Message\Status\NotFound();
            };
        }

        return $handlerBuilder
            ->append(
                new Controller\ActionMiddleware($this->getContainer())
            )
            ->create(
                $kernel->getContainer()->has("kernel.responseFactory")
                    ? $kernel->getContainer()->get("kernel.responseFactory")
                    : new \Fratily\Http\Message\ResponseFactory()
            )
            ->handle(
                $request
                    ->withAttribute("action", $action)
                    ->withAttribute("routing", $routing)
                    ->withAttribute("kernel", $kernel)
                    ->withAttribute(
                        "environment",
                        $kernel->getConfig()->getEnvironment()
                    )
                    ->withAttribute(
                        "debug",
                        $kernel->getConfig()->isDebug()
                    )
            )
        ;
    }
35554
public function process(ServerRequestInterface $request, RequestHandlerInterface $next) : ResponseInterface
    {
        $path = $request->getUri()->getPath();
        if (!empty($this->basePath) && 0 === strpos($path, $this->basePath)) {
            $cleanPath = substr($path, strlen($this->basePath));

            if ($cleanPath === false) {
                $cleanPath = '';
            }

            $request = $request->withUri($request->getUri()->withPath($cleanPath));
        }
        return $next->handle($request);
    }
941392
public function dispatchRequest(ServerRequestInterface $request): RouteResult
    {
        $httpMethod = $request->getMethod();
        $uri = rawurldecode($request->getUri()->getPath()); //$uri = '/' . ltrim($request->getUri()->getPath(), '/');

        $result = $this->dispatch($httpMethod, $uri);

        return $result[0] !== self::FOUND
            ? $this->marshalFailedRoute($result)
            : $this->marshalMatchedRoute($result);
    }
130582
public function dispatch(ServerRequestInterface $request): ResponseInterface
    {
        if ($this->currentRoute === null) {
            return $this->generate404($request);
        }

        foreach ($this->hostParameters as $param => $value) {
            $request = $request->withAttribute($param, $value);
        }

        foreach ($this->currentRoute->getHostParameters() as $param => $value) {
            $request = $request->withAttribute($param, $value);
        }

        foreach ($this->routeParameters as $param => $value) {
            $request = $request->withAttribute($param, $value);
        }

        $this->pushMiddlewaresToApplyInPipe();

        return $this->handle($request);
    }
838615
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $result = $this->router->dispatch(
            $request->getMethod(),
            $request->getUri()->getPath()
        );

        return $handler->handle(
            $request->withAttribute('routing', $result)
        );
    }