99 lines
2.1 KiB
PHP
Executable File
99 lines
2.1 KiB
PHP
Executable File
<?php define('__ROOT__', dirname(__FILE__) );
|
|
|
|
require_once __ROOT__.'/manager/autoloader.php';
|
|
|
|
use \router\Router;
|
|
use \manager\ResourceDispatcher;
|
|
|
|
use \manager\ModuleRequest;
|
|
use \manager\ModuleResponse;
|
|
use \manager\ManagerError;
|
|
use \manager\Authentification;
|
|
|
|
|
|
/*******************************************/
|
|
/* DEBUGGER */
|
|
/*******************************************/
|
|
debug();
|
|
/*******************************************/
|
|
/* DEBUGGER */
|
|
/*******************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [1] Gestion de l'authentification
|
|
=========================================================*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] Gestion du routage
|
|
=========================================================*/
|
|
|
|
/* (1) On initialise le routeur
|
|
---------------------------------------------------------*/
|
|
$R = new Router( $_GET['url'] );
|
|
|
|
|
|
/* (2) On cree les regles de routage
|
|
---------------------------------------------------------*/
|
|
/* (1) Racine -> page d'accueil */
|
|
$R->get('/?', function(){ header('Location: /dashboard/'); });
|
|
|
|
/* (2) Liste des pages du site */
|
|
$page_list = [
|
|
'dashboard',
|
|
'profile',
|
|
'machines',
|
|
'users',
|
|
'groups',
|
|
'analytics',
|
|
'settings'
|
|
];
|
|
|
|
// nomPage/arg1/arg2 -> inclusion de la page
|
|
$R->get('(?:'.implode('|', $page_list).')(?:/[\w-]+)*/?', function(){ include __ROOT__.'/view.php'; });
|
|
|
|
|
|
/* (3) Dispatcher */
|
|
$R->get('f(?:/([\w-]+))*/?', function(){ new ResourceDispatcher($_GET['url'], true); });
|
|
|
|
|
|
/* (4) api/module/method -> Api */
|
|
$R->post('api(?:/(.*))?', function($url){
|
|
$request = ModuleRequest::fromPost($url, $_POST);
|
|
$answer = $request->dispatch();
|
|
|
|
// Si c'est une réponse (et non un download)
|
|
if( $answer instanceof ModuleResponse )
|
|
echo $answer->serialize();
|
|
});
|
|
|
|
|
|
/* (5) N'importe -> page d'accueil */
|
|
$R->get('.+', function(){ header('Location: /dashboard/'); });
|
|
$R->post('.+', function(){ header('Location: /dashboard/'); });
|
|
|
|
|
|
|
|
/* (3) On lance le routeur
|
|
---------------------------------------------------------*/
|
|
$R->run();
|
|
|
|
?>
|