2016-04-04 09:47:17 +00:00
|
|
|
<?php define('__ROOT__', dirname(__FILE__) );
|
|
|
|
|
|
|
|
require_once __ROOT__.'/manager/autoloader.php';
|
|
|
|
|
|
|
|
use \router\Router;
|
|
|
|
use \manager\ResourceDispatcher;
|
|
|
|
use \manager\ModuleRequest;
|
|
|
|
|
|
|
|
/*******************************************/
|
|
|
|
/* DEBUGGER */
|
|
|
|
/*******************************************/
|
|
|
|
debug();
|
|
|
|
/*******************************************/
|
|
|
|
|
|
|
|
|
2016-04-04 12:04:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-04 09:47:17 +00:00
|
|
|
/* [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/'); });
|
|
|
|
|
2016-04-04 12:04:36 +00:00
|
|
|
|
|
|
|
/* [2] On recupere la liste des pages du site
|
|
|
|
=========================================================*/
|
|
|
|
$views = json_decode( ResourceDispatcher::getResource( 'f/json/views/conf', true ) );
|
|
|
|
|
|
|
|
|
2016-04-04 09:47:17 +00:00
|
|
|
|
|
|
|
// nomPage/arg1/arg2 -> inclusion de la page
|
2016-04-04 12:04:36 +00:00
|
|
|
$R->get('(?:'.implode('|', $views).')(?:/[\w-]+)*/?', function(){ include __ROOT__.'/view.php'; });
|
2016-04-04 09:47:17 +00:00
|
|
|
|
|
|
|
// Dispatcher
|
2016-04-04 12:04:36 +00:00
|
|
|
$R->get('f(?:/([\w-]+))*/?', function(){ new ResourceDispatcher($_GET['url'], true); });
|
2016-04-04 09:47:17 +00:00
|
|
|
|
|
|
|
// 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/'); });
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-04 12:04:36 +00:00
|
|
|
/* [3] On lance le routeur
|
2016-04-04 09:47:17 +00:00
|
|
|
===================================================*/
|
|
|
|
$R->run();
|
|
|
|
|
|
|
|
?>
|