format(format: 'Y-m-d'); $newApis = []; $updated = false; // Checa se tem versão esperando que começa hoje foreach ($manifest['apis'] as $api) { if ($api['status'] === 'planned' && $api['start_date'] === $now) { // Promote a nova $api['status'] = 'active'; $newApis[] = $api; $updated = true; } elseif ($api['status'] === 'active' && $api['start_date'] !== $now) { // Ignora versão antiga ativa continue; } else { $newApis[] = $api; } } // Atualiza manifest se tiver mudança if ($updated) { $manifest['apis'] = $newApis; file_put_contents(filename: $manifestPath, data: json_encode(value: $manifest, flags: JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); } // Carrega a versão ativa $loaded = false; foreach ($manifest['apis'] as $api) { $startDate = new DateTime(datetime: $api['start_date']); if ($api['status'] === 'active' && $startDate <= new DateTime()) { $routeFile = MODULE_PATH . "/{$manifest['dirName']}/{$api['version']}/Routes/Routes.php"; // Carrega arquivo de rotas if (file_exists(filename: $routeFile)) { Router::group( prefix: "/{$manifest['slug']}", callback: function() use ($routeFile) { require_once realpath(path: $routeFile); }, middlewares: [] ); $loaded = true; break; } else { throw new Exception(message: "Arquivo de rotas não encontrado para a versão '{$api['version']}'."); } } } // Verifica se carregou if (!$loaded) { throw new Exception(message: "Nenhuma versão ativa da API foi carregada."); }