private static function generateDirectory(string $dir): void
    {
        if (\is_dir($dir) && \is_writable($dir)) {
            return;
        }

        if (! @\mkdir($dir, 0777, true) || ! \is_writable($dir)) {
            throw new RuntimeException(\sprintf(
                'Route cache directory [%s] cannot be created or is write protected.',
                $dir
            ));
        }
    }