55 lines
1.5 KiB
PHP
Executable File
55 lines
1.5 KiB
PHP
Executable File
<?php define('__ROOT__', dirname(dirname(__FILE__)) );
|
|
|
|
require_once __ROOT__.'/al.php';
|
|
|
|
use \router\core\Router;
|
|
use \api\core\ModuleRequest;
|
|
use \api\core\ModuleResponse;
|
|
use \api\core\Authentification;
|
|
use \error\core\Error;
|
|
|
|
|
|
/*******************************************/
|
|
/* DEBUGGER */
|
|
/*******************************************/
|
|
debug();
|
|
/*******************************************/
|
|
|
|
/* [1] Gestion des authentifications et des droits
|
|
=========================================================*/
|
|
/* (1) On met à jour l'authentification et les permissions */
|
|
Authentification::check();
|
|
$auth = Authentification::auth();
|
|
|
|
|
|
/* [3] On initialise le routeur
|
|
===================================================*/
|
|
/* (1) New Router */
|
|
$R = new Router( $_GET['url'] );
|
|
|
|
|
|
/* [2] host.xxx/api/{module}/{method} -> api
|
|
=========================================================*/
|
|
$R->post('api(?:/(.*))?', function($url){
|
|
$request = ModuleRequest::fromPost($url, $_POST);
|
|
$answer = $request->dispatch();
|
|
|
|
// Si c'est une réponse
|
|
if( $answer instanceof ModuleResponse )
|
|
echo $answer->serialize();
|
|
|
|
});
|
|
|
|
|
|
/* [3] Any other URL -> homepage
|
|
=========================================================*/
|
|
$R->get('.+', function(){ http_response_code(417); exit(); });
|
|
$R->post('.+', function(){ http_response_code(417); exit(); });
|
|
|
|
|
|
/* [8] Launch Router
|
|
===================================================*/
|
|
$R->run();
|
|
|
|
?>
|