50 lines
1.2 KiB
PHP
50 lines
1.2 KiB
PHP
|
<?php define('__ROOT__', dirname(dirname(__FILE__)) );
|
||
|
|
||
|
require_once __ROOT__.'/autoloader.php';
|
||
|
|
||
|
use \router\core\Router;
|
||
|
use \api\core\ModuleRequest;
|
||
|
use \api\core\ModuleResponse;
|
||
|
use \manager\ManagerError;
|
||
|
|
||
|
// var_dump($_SESSION);
|
||
|
|
||
|
|
||
|
/*******************************************/
|
||
|
/* DEBUGGER */
|
||
|
/*******************************************/
|
||
|
debug();
|
||
|
/*******************************************/
|
||
|
|
||
|
|
||
|
/* [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(){ header(__REDIRECT__); });
|
||
|
$R->post('.+', function(){ header(__REDIRECT__); });
|
||
|
|
||
|
|
||
|
/* [8] Launch Router
|
||
|
===================================================*/
|
||
|
$R->run();
|
||
|
|
||
|
?>
|