private function createRouterClassTemplate(string $rootRoute, string $body): string
    {
        $template = <<<'PHP'
<?php
return function ($method, $uri) {
    if ($uri === '') {
{root_route}
    } elseif ($uri[0] !== '/') {
        throw new \RuntimeException("Cannot match route: non-empty uri must be prefixed with '/', '{$uri}' given");
    }

    $segments = \explode('/', \substr($uri, 1));
{body}
};
PHP;

        return \strtr($template, ['{root_route}' => $rootRoute, '{body}' => $body]);
    }