67 lines
1.6 KiB
PHP
Executable File
67 lines
1.6 KiB
PHP
Executable File
<?php define('__ROOT__', dirname(__FILE__) );
|
|
|
|
require_once __ROOT__.'/manager/autoloader.php';
|
|
|
|
use \router\Router;
|
|
use \manager\ResourceDispatcher;
|
|
use \manager\ModuleRequest;
|
|
|
|
/*******************************************/
|
|
/* DEBUGGER */
|
|
/*******************************************/
|
|
debug();
|
|
/*******************************************/
|
|
|
|
|
|
/* [0] On initialise le routeur
|
|
===================================================*/
|
|
$R = new Router( $_GET['url'] );
|
|
// var_dump($R);
|
|
|
|
/* [1] On cree les regles de routage
|
|
===================================================*/
|
|
// Racine -> page d'accueil
|
|
$R->get('/?', function(){ header('Location: /dashboard/'); });
|
|
|
|
// Liste des pages du site
|
|
$page_list = array(
|
|
'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'; });
|
|
|
|
// Dispatcher
|
|
$R->get('f(?:/([\w-]+))*/?', function(){ new ResourceDispatcher($_GET['url'], true); });
|
|
|
|
// Api
|
|
$R->post('api/?', function(){
|
|
$request = ModuleRequest::fromPost($_POST);
|
|
$answer = $request->dispatch();
|
|
|
|
echo $answer->serialize();
|
|
});
|
|
|
|
// N'importe -> page d'accueil
|
|
$R->get('.+', function(){ header('Location: /dashboard/'); });
|
|
|
|
|
|
// $R->post('.*', function(){
|
|
// var_dump( 'Acces POST : '.$_GET['url'] );
|
|
// var_dump( $_POST );
|
|
// });
|
|
|
|
|
|
|
|
|
|
/* [2] On lance le routeur
|
|
===================================================*/
|
|
$R->run();
|
|
|
|
?>
|