updated index.php
This commit is contained in:
parent
6cd977ef90
commit
f1987d9512
|
@ -65,6 +65,6 @@
|
|||
"http": "1.0",
|
||||
"orm": "0.8.2",
|
||||
"database": "2.0",
|
||||
"router": "1.0"
|
||||
"router": "2.0"
|
||||
}
|
||||
}
|
|
@ -1,56 +1,8 @@
|
|||
<?php define('__ROOT__', dirname(dirname(__FILE__)) );
|
||||
|
||||
require_once __ROOT__.'/autoloader.php';
|
||||
<?php require_once '../autoloader.php';
|
||||
|
||||
use \router\core\Router;
|
||||
use \api\core\ModuleRequest;
|
||||
use \api\core\ModuleResponse;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* [0] On initialise le routeur
|
||||
===================================================*/
|
||||
$R = new Router( $_GET['url'] );
|
||||
|
||||
|
||||
/* [1] On cree les regles de routage
|
||||
===================================================*/
|
||||
// Racine -> page d'accueil
|
||||
$R->get('/?', function(){ header('Location: /homepage/'); });
|
||||
|
||||
|
||||
/* [2] On recupere la liste des pages du site
|
||||
=========================================================*/
|
||||
// inclusion de la page
|
||||
$R->get('([a-z+])/?', function($pagename){ include __PUBLIC__."/$pagename.php"; });
|
||||
|
||||
|
||||
|
||||
|
||||
// http://host/api/module/method -> ModuleRequest
|
||||
$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();
|
||||
|
||||
});
|
||||
|
||||
|
||||
// N'importe -> page d'accueil
|
||||
$R->get('.+', function(){ header('Location: /homepage/'); });
|
||||
$R->post('.+', function(){ header('Location: /homepage/'); });
|
||||
|
||||
|
||||
|
||||
|
||||
/* [3] On lance le routeur
|
||||
===================================================*/
|
||||
$R->run();
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue