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
This commit is contained in:
Yury Pikhtarev 2025-06-22 02:35:54 +04:00
commit 1890215278
No known key found for this signature in database
2 changed files with 8 additions and 4 deletions

View file

@ -10,7 +10,10 @@
define('BB_SCRIPT', 'ajax'); define('BB_SCRIPT', 'ajax');
define('IN_AJAX', true); 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 // Init Ajax class
$ajax = new TorrentPier\Ajax(); $ajax = new TorrentPier\Ajax();

View file

@ -13,6 +13,7 @@ return function (Router $router): void {
// Legacy controller routes (hacky but organized approach) // Legacy controller routes (hacky but organized approach)
$legacyRoutes = [ $legacyRoutes = [
'ajax.php',
'index.php', 'index.php',
'terms.php', 'terms.php',
// Add more legacy controllers here as needed: // Add more legacy controllers here as needed:
@ -23,15 +24,15 @@ return function (Router $router): void {
foreach ($legacyRoutes as $route) { foreach ($legacyRoutes as $route) {
// Route with .php extension // 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) // Route without .php extension (e.g., /terms for /terms.php)
$routeWithoutExtension = str_replace('.php', '', $route); $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 // 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 // Future modern routes will be added here
}; };