2016-11-06 16:04:17 +00:00
|
|
|
<?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;
|
|
|
|
|
2016-11-07 18:46:54 +00:00
|
|
|
//var_dump($_POST);
|
|
|
|
//exit();
|
2016-11-06 16:04:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*******************************************/
|
|
|
|
/* 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();
|
|
|
|
|
|
|
|
?>
|