From 1890215278a83232e34cf71cbdbe78b1cc59d3aa Mon Sep 17 00:00:00 2001 From: Yury Pikhtarev Date: Sun, 22 Jun 2025 02:35:54 +0400 Subject: [PATCH] refactor(controllers): move ajax.php to controllers directory and improve routing - Move ajax.php to controllers/ajax.php for better file organization - Update require path and add conditional loading check in ajax.php - Add ajax.php to legacy routes array in web.php - Change route methods from GET to ANY for legacy controllers to support all HTTP methods - Update root route to support all HTTP methods as well --- ajax.php => controllers/ajax.php | 5 ++++- src/Presentation/Http/Routes/web.php | 7 ++++--- 2 files changed, 8 insertions(+), 4 deletions(-) rename ajax.php => controllers/ajax.php (86%) diff --git a/ajax.php b/controllers/ajax.php similarity index 86% rename from ajax.php rename to controllers/ajax.php index abe638c8e..bc6fbc562 100644 --- a/ajax.php +++ b/controllers/ajax.php @@ -10,7 +10,10 @@ define('BB_SCRIPT', 'ajax'); define('IN_AJAX', true); -require __DIR__ . '/common.php'; +// Skip loading common.php if already loaded (when run through routing system) +if (!defined('IN_TORRENTPIER')) { + require __DIR__ . '/../common.php'; +} // Init Ajax class $ajax = new TorrentPier\Ajax(); diff --git a/src/Presentation/Http/Routes/web.php b/src/Presentation/Http/Routes/web.php index f006ebd24..04fca7efb 100644 --- a/src/Presentation/Http/Routes/web.php +++ b/src/Presentation/Http/Routes/web.php @@ -13,6 +13,7 @@ return function (Router $router): void { // Legacy controller routes (hacky but organized approach) $legacyRoutes = [ + 'ajax.php', 'index.php', 'terms.php', // Add more legacy controllers here as needed: @@ -23,15 +24,15 @@ return function (Router $router): void { foreach ($legacyRoutes as $route) { // Route with .php extension - $router->get('/' . $route, [LegacyController::class, 'handle']); + $router->any('/' . $route, [LegacyController::class, 'handle']); // Route without .php extension (e.g., /terms for /terms.php) $routeWithoutExtension = str_replace('.php', '', $route); - $router->get('/' . $routeWithoutExtension, [LegacyController::class, 'handle']); + $router->any('/' . $routeWithoutExtension, [LegacyController::class, 'handle']); } // Root route should serve the legacy index.php controller - $router->get('/', [LegacyController::class, 'handle']); + $router->any('/', [LegacyController::class, 'handle']); // Future modern routes will be added here };