src/Dispatcher/DispatcherMiddleware.php
public function process(ServerRequestInterface $request, RequestHandlerInterface $requestHandler): ResponseInterface
    {
        $route = $request->getAttribute(Route::class, false);

        if (!$route) {
            return $requestHandler->handle($request);
        }

        $middleware = $route->getMiddlewares();
        $middlewareBuilder = new MiddlewareBuilder(
            $this->container,
            $this->router,
            $requestHandler
        );

        if (!$middleware instanceof MiddlewareInterface) {
            $middleware = $middlewareBuilder->buildMiddleware($middleware);
        }

        return $middleware->process($request, $requestHandler);
    }
public function process(ServerRequestInterface $request, RequestHandlerInterface $requestHandler): ResponseInterface
    {
        $route = $request->getAttribute(Route::class, false);

        if (!$route) {
            return $requestHandler->handle($request);
        }

        $middleware = $route->getMiddlewares();
        $middlewareBuilder = new MiddlewareBuilder(
            $this->container,
            $this->router,
            $requestHandler
        );

        if (!$middleware instanceof MiddlewareInterface) {
            $middleware = $middlewareBuilder->buildMiddleware($middleware);
        }

        return $middleware->process($request, $requestHandler);
    }
Process an incoming server request and return a response, optionally delegating
to the next middleware component to create the response.

@param ServerRequestInterface  $request
@param RequestHandlerInterface $requestHandler

@return ResponseInterface