public function dispatch(Request $request)
    {
        if (ltrim($_SERVER['REQUEST_URI'], '/') === '') {
            return new DispatcherResult(200, $this->defaultHandler);
        }

        $dispatcher = $this->getDispatcher();

        $match = $dispatcher->dispatch($request->getMethod(), $_SERVER['REQUEST_URI']);

        $code = null;
        $handler = null;

        switch ($match[0]) {
            case Dispatcher::NOT_FOUND:
                $code = 404;
                $handler = $this->errorHandlers[$code];
                break;
            case Dispatcher::METHOD_NOT_ALLOWED:
                $code = 405;
                $handler = $this->errorHandlers[$code];
                $handler->setSuppliedParameters(['allowedMethods' => $match[1]]);
                break;
            case Dispatcher::FOUND:
                $code = 200;
                /** @var RouteCallbackDTOInterface $handler */
                $handler = $match[1];
                $handler->setSuppliedParameters($match[2]);
                break;
        }

        if ($code !== null) {
            return new DispatcherResult($code, $handler);
        }

        return new DispatcherResult(200, $this->defaultHandler);
    }