68 lines
2.0 KiB
PHP
68 lines
2.0 KiB
PHP
<?php
|
|
|
|
// Basic autoloader
|
|
spl_autoload_register(function ($class) {
|
|
$prefix = 'Api\\';
|
|
$base_dir = __DIR__ . '/';
|
|
$len = strlen($prefix);
|
|
if (strncmp($prefix, $class, $len) !== 0) return;
|
|
$relative_class = substr($class, $len);
|
|
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
|
|
if (file_exists($file)) require $file;
|
|
});
|
|
|
|
require_once __DIR__ . '/../../db/config.php';
|
|
require_once __DIR__ . '/Core/Response.php';
|
|
|
|
use Api\Core\Router;
|
|
|
|
$router = new Router();
|
|
|
|
// Auth
|
|
$router->add('POST', '/auth/login', 'AuthController@login');
|
|
$router->add('GET', '/auth/me', 'AuthController@me');
|
|
|
|
// Schools (Super Admin)
|
|
$router->add('GET', '/schools', 'SchoolController@index');
|
|
$router->add('GET', '/schools/stats', 'SchoolController@stats');
|
|
$router->add('POST', '/schools', 'SchoolController@store');
|
|
|
|
// Learners
|
|
$router->add('GET', '/learners', 'LearnerController@index');
|
|
$router->add('GET', '/learners/:id', 'LearnerController@show');
|
|
|
|
// Assessments
|
|
$router->add('GET', '/assessments', 'AssessmentController@index');
|
|
$router->add('POST', '/assessments', 'AssessmentController@store');
|
|
|
|
// Events
|
|
$router->add('GET', '/events', 'EventController@index');
|
|
$router->add('POST', '/events', 'EventController@store');
|
|
|
|
// Collaboration
|
|
$router->add('GET', '/collaboration/resources', 'CollaborationController@resources');
|
|
$router->add('POST', '/collaboration/resources', 'CollaborationController@storeResource');
|
|
|
|
// Gamification
|
|
$router->add('GET', '/leaderboard', 'LeaderboardController@index');
|
|
|
|
// Health
|
|
$router->add('GET', '/health', 'HealthController@index');
|
|
|
|
// Get request method and URI
|
|
$method = $_SERVER['REQUEST_METHOD'];
|
|
$uri = $_GET['request'] ?? $_SERVER['REQUEST_URI'];
|
|
|
|
// Handle InfinityFree style routing if needed
|
|
if (strpos($uri, '/api/v1') === 0) {
|
|
$uri = substr($uri, 7);
|
|
}
|
|
|
|
// Remove query string
|
|
$uri = explode('?', $uri)[0];
|
|
|
|
// Remove trailing slash
|
|
$uri = rtrim($uri, '/');
|
|
if (empty($uri)) $uri = '/';
|
|
|
|
$router->handle($method, $uri); |