src/Dispatcher/Dispatcher.php
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        if ($this->middlewares->isEmpty()) {
            if (null !== $this->requestHandler) {
                return $this->requestHandler->handle($request);
            }

            return $this->response;
        }

        $middleware = $this->middlewares->dequeue();

        if ('*' !== $middleware->getPath()) {
            $uri = $request->getUri()->getPath();
            $regex = '#^' . $middleware->getPath() . '#';

            if (!preg_match($regex, $uri, $matches)) {
                return $this->handle($request);
            }
        }

        $middleware = $middleware->getMiddlewares();
        $response = $middleware->process($request, $this);

        if (!$response instanceof ResponseInterface) {
            throw new \RuntimeException('No valid response sending.');
        }

        return $response;
    }
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        if ($this->middlewares->isEmpty()) {
            if (null !== $this->requestHandler) {
                return $this->requestHandler->handle($request);
            }

            return $this->response;
        }

        $middleware = $this->middlewares->dequeue();

        if ('*' !== $middleware->getPath()) {
            $uri = $request->getUri()->getPath();
            $regex = '#^' . $middleware->getPath() . '#';

            if (!preg_match($regex, $uri, $matches)) {
                return $this->handle($request);
            }
        }

        $middleware = $middleware->getMiddlewares();
        $response = $middleware->process($request, $this);

        if (!$response instanceof ResponseInterface) {
            throw new \RuntimeException('No valid response sending.');
        }

        return $response;
    }
@param ServerRequestInterface $request

@return ResponseInterface