You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.5 KiB

<?php
namespace Daiko\NoWiki;
if (!is_dir('vendor')) {
throw new \Exception('You must run "composer install".');
}
$loader = require __DIR__ . '/vendor/autoload.php';
$config = new Configuration('specific/config.php');
$config->load();
$storage = new Storage\Pdo($config->parameters['storage']['parameters']);
try {
$storage->connect();
if ($storage->isInit() === false) {
$storage->init();
// Créé la page par default en attendant l'initialisation
// du contenu par défaut du wiki TODO
$page = new Page(
Controller\Controller::DEFAULT_PAGE,
'# Bienvenue sur la page d\'accueil'
);
$storage->createPage($page);
}
} catch (Storage\StorageException $e) {
die($e->getMessage());
}
$controller = new Controller\Controller($storage);
$router = new Router\Router();
// Routes pour le pages.
$router->get('/', array($controller, 'getDefaultPage'));
$router->get('/pages/{page}', array($controller, 'getPage'));
$router->get('/pages/{page}:{handler}', array($controller, 'getPageWithHandler'));
$router->post('/pages/{page}', array($controller, 'setPage'));
$router->delete('/pages/{page}', array($controller, 'deletePage'));
$uri = '';
if (isset($_GET['uri']) === true) {
$uri = trim($_GET['uri'], '/');
}
try {
$router->run($_SERVER['REQUEST_METHOD'], $uri);
} catch (Router\RouterException $e) {
http_response_code(404);
print("<h1>404</h1>");
die();
} catch (\Exception $e) {
die($e->getMessage());
}