public static function createRouteDispatcher(
        ContainerInterface $container,
        ?callable $getPrevious = null
    ): DispatcherContract {
        // @codeCoverageIgnoreStart
        if (\is_callable($getPrevious)) {
            $dispatcher = $getPrevious();
        } elseif (\class_exists(Pipeline::class)) {
            $dispatcher = new MiddlewareBasedDispatcher();
        } else {
            $dispatcher = new SimpleDispatcher();
        }
        // @codeCoverageIgnoreStop

        if ($container->has(EventManagerContract::class)) {
            $dispatcher->setEventManager($container->get(EventManagerContract::class));
        }

        return $dispatcher;
    }