@param ServerRequestInterface  $request
@param RequestHandlerInterface $next

@return ResponseInterface

@throws \InvalidArgumentException
760350
public function process(ServerRequestInterface $request, RequestHandlerInterface $next) : ResponseInterface
    {
        $response = $next->handle($request);
        $memory = $this->getPeakMemory() . ' kbyte';

        return $response->withHeader(self::HEADER, $memory);
    }
30510
public function process(Request $request, callable $next)
    {
        foreach ($_GET as $key => $value) {
            $_GET[$key] = trim($value);
        }

        foreach ($_POST as $key => $value) {
            $_GET[$key] = trim($value);
        }

        return $next($request);
    }
280947
public function handle( $request, Closure $next )
    {
        if( !$this->sentinel->check() )
        {
            return $this->denied( $request );
        }

        return $next( $request );
    }
1058794
public function handle(ServerRequestInterface $request): ResponseInterface
        {
            if (!isset($this->middleware[$this->index])) {
                return $this->response;
            }
    
            $middleware = $this->middleware[$this->index];
            return $middleware->process($request, $this->next());
        }
611914
public function handle($request, Closure $next)
    {
        $paginationKey = config('pagination.key');

        $request->offsetSet($paginationKey, $request->paginationCount());

        return $next($request);
    }
2697
protected function dispatchRoute(
        RouteHandlerInterface $handler,
        ServerRequestInterface $request,
        Closure $next = null
    ): ResponseInterface {
        // callback that will be passed to the route handler call, as last argument.
        $handlerNext = $next ? function ($newRequest = null) use ($next, $request) {
            return $next($newRequest instanceof ServerRequestInterface ? $newRequest : $request);
        } :
            function () {
                // noop
            };
        return $handler($handlerNext);
    }
1133018
protected function get(ServerRequestInterface $request, bool $next = false): ?MiddlewareInterface
    {
        $index = $next ? ++$this->index : $this->index;

        if (!isset($this->middleware[$index])) {
            return null;
        }

        $middleware = $this->middleware[$index];

        if (\is_array($middleware)) {
            $conditions = $middleware;
            $middleware = \array_pop($conditions);

            if (!Matcher\Factory::matches($conditions, $request)) {
                return $this->get($request, true);
            }
        }

        if (\is_callable($middleware)) {
            return new Middleware\CallableWrapper($middleware);
        }

        if (\is_string($middleware)) {
            if ($this->container === null) {
                throw new \RuntimeException("No valid middleware provided: $middleware");
            }

            $middleware = $this->container->get($middleware);
        }

        if (!$middleware instanceof MiddlewareInterface) {
            throw new \RuntimeException('The middleware must be an instance of MiddlewareInterface');
        }

        return $middleware;
    }
62836
public static function handle(
        ServerRequestInterface $request,
        Closure $next,
        ContainerInterface $container
    ): ResponseInterface {
        /** @var AnalyzerInterface $analyzer */
        $analyzer = $container->get(AnalyzerInterface::class);
        $analysis = $analyzer->analyze($request);

        $requestType = $analysis->getRequestType();
        switch ($requestType) {
            case AnalysisResultInterface::TYPE_REQUEST_OUT_OF_CORS_SCOPE:
                // call next middleware handler
                return $next($request);

            case AnalysisResultInterface::TYPE_ACTUAL_REQUEST:
                // actual CORS request
                $corsHeaders = $analysis->getResponseHeaders();

                /** @var ResponseInterface $response */
                $response = $next($request);

                // add CORS headers to Response $response
                foreach ($corsHeaders as $name => $value) {
                    $response = $response->withHeader($name, $value);
                }

                return $response;

            case AnalysisResultInterface::TYPE_PRE_FLIGHT_REQUEST:
                // return 200 HTTP with $corsHeaders
                return new EmptyResponse(200, $analysis->getResponseHeaders());

            case AnalysisResultInterface::ERR_ORIGIN_NOT_ALLOWED:
                return static::getErrorOriginNotAllowedResponse($analysis);

            case AnalysisResultInterface::ERR_METHOD_NOT_SUPPORTED:
                return static::getErrorMethodNotSupportedResponse($analysis);

            case AnalysisResultInterface::ERR_HEADERS_NOT_SUPPORTED:
                return static::getErrorHeadersNotSupportedResponse($analysis);

            case AnalysisResultInterface::ERR_NO_HOST_HEADER:
            default:
                assert($requestType === AnalysisResultInterface::ERR_NO_HOST_HEADER);

                return static::getErrorNoHostHeaderResponse($analysis);
        }
    }
1195658
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        return $this->middleware->process($request, $this->delegate);
    }
1014461
public function dispatch(ServerRequestInterface $request): ResponseInterface
    {
        $resolved = $this->resolve(0);

        return $resolved->handle($request);
    }
789846
public function process(
        RequestInterface $request,
        ResponseInterface $response,
        DelegateInterface $next = null
    ) {
        // before
        $response = $this->before($request, $response);

        // next middleware
        if ($next) {
            $response = $next->next($request, $response);
        }

        // after
        return $this->after($request, $response);
    }
400382
public function process(Request $request, callable $next)
    {
        if (Auth::check()) {
            return $next($request);
        }

        return redirect($this->redirectTo());
    }
1014203
public function dispatchRequest(ServerRequestInterface $request) : ResponseInterface
    {
        $match = $this->dispatch($request->getMethod(), $request->getUri()->getPath());

        switch ($match[0]) {
            case FastRoute::NOT_FOUND:
                $this->setNotFoundDecoratorMiddleware();
                break;
            case FastRoute::METHOD_NOT_ALLOWED:
                $allowed = (array) $match[1];
                $this->setMethodNotAllowedDecoratorMiddleware($allowed);
                break;
            case FastRoute::FOUND:
                $match[1]->setVars($match[2]);
                $this->setFoundMiddleware($match[1]);
                break;
        }

        return $this->handle($request);
    }
1296736
public function handle($request, Closure $next)
    {
        try {
            $response = $next($request);

            // Was an exception thrown? If so and available catch in our middleware
            if (isset($response->exception) && $response->exception) {
                throw $response->exception;
            }

            return $response;
        } catch (OAuthException $e) {
            $message = env('API_DEBUG') ? $e->getMessage() : null;
            throw new HttpException($e->httpStatusCode, $message, $e, $e->getHttpHeaders());
        } catch (HttpResponseException $e) {
            $message = env('API_DEBUG') ? $e->getMessage() : null;
            throw new HttpException($e->getResponse()->getStatusCode(), $message, $e);
        } catch (AuthenticationException $e) {
            throw new UnauthorizedHttpException(null, $e->getMessage(), $e);
        } catch (ValidatorException $e) {
            $messageBag = $e->getMessageBag();
            throw new ResourceException($messageBag->first(), $messageBag->all());
        } catch (ModelNotFoundException $e) {
            throw new NotFoundHttpException('No results found.');
        }
    }
860974
public function handle(Request $request, callable $next)
    {
        $this->serviceManager->add(Request::class, $request);

        return $next($request);
    }
1306936
public function handle($request, Closure $next)
    {
        if ($this->auth->parser()->setRequest($request)->hasToken()) {
            try {
                $this->auth->parseToken()->authenticate();
            } catch (Exception $e) {
                //
            }
        }

        return $next($request);
    }
1355865
public function handle($request, Closure $next)
    {
        $as = $request->input('_as');

        if ($this->authorize() && ! is_null($as)) {
            $this->auth->loginUsingId($as);

            return $this->response->redirectTo($request->url());
        }

        return $next($request);
    }