<?php
namespace App\Core;

final class RouteCache
{
    public static function build(): void
    {
        $routes = [];
        require BASE_PATH . '/config/routes.php';

        file_put_contents(
            BASE_PATH . '/storage/cache/routes.cache.php',
            '<?php return ' . var_export($routes, true) . ';'
        );
    }

    public static function load(): array
    {
        $file = BASE_PATH . '/storage/cache/routes.cache.php';

        if (file_exists($file)) {
            return require $file;
        }

        require BASE_PATH . '/config/routes.php';
        return $routes ?? [];
    }
}
