updated index.php

This commit is contained in:
xdrm-brackets 2016-12-08 19:13:44 +01:00
parent 6cd977ef90
commit f1987d9512
2 changed files with 70 additions and 118 deletions

View File

@ -1,70 +1,70 @@
{ {
"available": { "available": {
"error": { "error": {
"1.0": [], "1.0": [],
"2.0": [] "2.0": []
}, },
"http": { "http": {
"1.0": [] "1.0": []
}, },
"api": { "api": {
"1.0": { "1.0": {
"error": [ "error": [
"1.0" "1.0"
] ]
}, },
"2.0": { "2.0": {
"error": [ "error": [
"2.0" "2.0"
] ]
}, },
"2.2": { "2.2": {
"error": [ "error": [
"2.0" "2.0"
], ],
"http": [ "http": [
"1.0" "1.0"
] ]
} }
}, },
"orm": { "orm": {
"0.8.1": { "0.8.1": {
"database": [ "database": [
"1.0" "1.0"
] ]
}, },
"0.8.2": { "0.8.2": {
"database": [ "database": [
"2.0" "2.0"
] ]
} }
}, },
"database": { "database": {
"1.0": { "1.0": {
"error": [ "error": [
"1.0" "1.0"
] ]
}, },
"2.0": { "2.0": {
"error": [ "error": [
"2.0" "2.0"
] ]
} }
}, },
"lightdb": { "lightdb": {
"1.0": [] "1.0": []
}, },
"router": { "router": {
"1.0": [], "1.0": [],
"2.0": [] "2.0": []
} }
}, },
"installed": { "installed": {
"api": "2.2", "api": "2.2",
"error": "2.0", "error": "2.0",
"http": "1.0", "http": "1.0",
"orm": "0.8.2", "orm": "0.8.2",
"database": "2.0", "database": "2.0",
"router": "1.0" "router": "2.0"
} }
} }

View File

@ -1,56 +1,8 @@
<?php define('__ROOT__', dirname(dirname(__FILE__)) ); <?php require_once '../autoloader.php';
require_once __ROOT__.'/autoloader.php';
use \router\core\Router; use \router\core\Router;
use \api\core\ModuleRequest;
use \api\core\ModuleResponse;
/* [0] On initialise le routeur
===================================================*/
$R = new Router( $_GET['url'] ); $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(); $R->run();
?>