mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-22 06:13:58 -07:00
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:
parent
273121a49f
commit
1890215278
2 changed files with 8 additions and 4 deletions
|
@ -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();
|
|
@ -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
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue