2016-02-01 22:09:35 +00:00
|
|
|
<?php define('__ROOT__', dirname(__FILE__) );
|
2016-07-02 15:10:41 +00:00
|
|
|
|
2016-02-03 22:22:18 +00:00
|
|
|
require_once __ROOT__.'/manager/autoloader.php';
|
2016-02-01 22:09:35 +00:00
|
|
|
|
2016-02-13 17:41:19 +00:00
|
|
|
use \router\Router;
|
|
|
|
use \manager\ResourceDispatcher;
|
2016-07-02 15:10:41 +00:00
|
|
|
|
2016-02-13 17:41:19 +00:00
|
|
|
use \manager\ModuleRequest;
|
2016-07-02 15:10:41 +00:00
|
|
|
use \manager\ModuleResponse;
|
|
|
|
use \manager\ManagerError;
|
2016-07-04 09:04:49 +00:00
|
|
|
use \manager\Authentification;
|
2016-02-13 17:41:19 +00:00
|
|
|
|
2016-07-02 16:35:34 +00:00
|
|
|
|
2016-02-02 22:29:30 +00:00
|
|
|
/*******************************************/
|
|
|
|
/* DEBUGGER */
|
|
|
|
/*******************************************/
|
2016-02-04 22:45:03 +00:00
|
|
|
debug();
|
2016-02-02 22:29:30 +00:00
|
|
|
/*******************************************/
|
2016-07-04 09:04:49 +00:00
|
|
|
/* DEBUGGER */
|
|
|
|
/*******************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [1] Gestion de l'authentification
|
|
|
|
=========================================================*/
|
2016-07-04 13:45:29 +00:00
|
|
|
|
2016-07-04 09:04:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] Gestion du routage
|
|
|
|
=========================================================*/
|
|
|
|
|
|
|
|
/* (1) On initialise le routeur
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
$R = new Router( $_GET['url'] );
|
2016-02-01 22:09:35 +00:00
|
|
|
|
2016-07-03 12:20:42 +00:00
|
|
|
|
2016-07-04 09:04:49 +00:00
|
|
|
/* (2) On cree les regles de routage
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Racine -> page d'accueil */
|
|
|
|
$R->get('/?', function(){ header('Location: /dashboard/'); });
|
2016-02-01 22:09:35 +00:00
|
|
|
|
2016-07-04 09:04:49 +00:00
|
|
|
/* (2) Liste des pages du site */
|
2016-07-04 13:45:29 +00:00
|
|
|
$page_list = [
|
2016-07-04 09:04:49 +00:00
|
|
|
'dashboard',
|
|
|
|
'profile',
|
|
|
|
'machines',
|
|
|
|
'users',
|
|
|
|
'groups',
|
|
|
|
'analytics',
|
|
|
|
'settings'
|
2016-07-04 13:45:29 +00:00
|
|
|
];
|
2016-02-01 22:09:35 +00:00
|
|
|
|
2016-07-04 09:04:49 +00:00
|
|
|
// nomPage/arg1/arg2 -> inclusion de la page
|
|
|
|
$R->get('(?:'.implode('|', $page_list).')(?:/[\w-]+)*/?', function(){ include __ROOT__.'/view.php'; });
|
2016-02-01 22:09:35 +00:00
|
|
|
|
2016-02-03 22:22:18 +00:00
|
|
|
|
2016-07-04 09:04:49 +00:00
|
|
|
/* (3) Dispatcher */
|
|
|
|
$R->get('f(?:/([\w-]+))*/?', function(){ new ResourceDispatcher($_GET['url'], true); });
|
2016-02-02 22:29:30 +00:00
|
|
|
|
|
|
|
|
2016-07-04 09:04:49 +00:00
|
|
|
/* (4) api/module/method -> Api */
|
|
|
|
$R->post('api(?:/(.*))?', function($url){
|
|
|
|
$request = ModuleRequest::fromPost($url, $_POST);
|
|
|
|
$answer = $request->dispatch();
|
2016-07-02 15:10:41 +00:00
|
|
|
|
2016-07-04 09:04:49 +00:00
|
|
|
// Si c'est une réponse (et non un download)
|
|
|
|
if( $answer instanceof ModuleResponse )
|
|
|
|
echo $answer->serialize();
|
|
|
|
});
|
2016-02-04 22:45:03 +00:00
|
|
|
|
2016-07-02 15:10:41 +00:00
|
|
|
|
2016-07-04 09:04:49 +00:00
|
|
|
/* (5) N'importe -> page d'accueil */
|
|
|
|
$R->get('.+', function(){ header('Location: /dashboard/'); });
|
|
|
|
$R->post('.+', function(){ header('Location: /dashboard/'); });
|
2016-02-01 22:09:35 +00:00
|
|
|
|
|
|
|
|
2016-02-02 10:09:48 +00:00
|
|
|
|
2016-07-04 09:04:49 +00:00
|
|
|
/* (3) On lance le routeur
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
$R->run();
|
2016-02-01 22:09:35 +00:00
|
|
|
|
2016-07-02 15:10:41 +00:00
|
|
|
?>
|