2022-11-27 00:04:34 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// Autoload files using the Composer autoloader.
|
|
|
|
require_once __DIR__ . '/vendor/autoload.php';
|
|
|
|
|
|
|
|
// First Party
|
|
|
|
use Tor\Tor;
|
2022-11-28 21:05:24 +01:00
|
|
|
use Tor\Api;
|
2022-12-03 23:24:18 +01:00
|
|
|
use Cave\Cave;
|
2022-11-27 00:04:34 +01:00
|
|
|
|
2022-11-28 21:05:24 +01:00
|
|
|
use SeriousJSON\JsonDatabase;
|
2022-11-27 00:04:34 +01:00
|
|
|
|
|
|
|
// Third Party Routing Library
|
|
|
|
use Gac\Routing\Exceptions\CallbackNotFound;
|
|
|
|
use Gac\Routing\Exceptions\RouteNotFoundException;
|
|
|
|
use Gac\Routing\Request;
|
|
|
|
use Gac\Routing\Routes;
|
|
|
|
|
|
|
|
// Initialize an instance of the routing library
|
|
|
|
$routes = new Routes();
|
|
|
|
|
|
|
|
// Initialize Twig
|
|
|
|
// TODO: Only do this if needed
|
2022-11-28 21:05:24 +01:00
|
|
|
$loader = new \Twig\Loader\FilesystemLoader(__DIR__ . DIRECTORY_SEPARATOR . 'templates');
|
2022-11-27 00:04:34 +01:00
|
|
|
$twig = new \Twig\Environment($loader, [
|
2022-11-28 21:05:24 +01:00
|
|
|
'cache' => __DIR__ . DIRECTORY_SEPARATOR . 'compilation_cache',
|
2022-11-27 00:04:34 +01:00
|
|
|
]);
|
|
|
|
|
2022-11-28 21:05:24 +01:00
|
|
|
$data = new JsonDatabase(__DIR__ . DIRECTORY_SEPARATOR . 'data');
|
2022-11-27 00:04:34 +01:00
|
|
|
$tor = new Tor();
|
|
|
|
$api = new Api();
|
2022-12-03 04:09:44 +01:00
|
|
|
$cave = new Cave();
|
2022-11-27 00:04:34 +01:00
|
|
|
|
|
|
|
try {
|
2022-11-28 21:05:24 +01:00
|
|
|
// Initialize Database
|
|
|
|
$data->init();
|
|
|
|
|
2022-11-27 00:04:34 +01:00
|
|
|
// Initialize Tor in order to register routes
|
|
|
|
$tor->init();
|
|
|
|
|
|
|
|
// Initialize Tor API in order to register routes
|
|
|
|
$api->init();
|
|
|
|
|
2022-12-03 04:09:44 +01:00
|
|
|
// Initialize CA Endpoint
|
|
|
|
$cave->init();
|
|
|
|
|
2022-11-27 00:04:34 +01:00
|
|
|
// Handle routes
|
|
|
|
$routes->handle();
|
|
|
|
} catch (RouteNotFoundException $ex) {
|
|
|
|
$routes->request->status(404, "Route not found")->send(["error" => ["message" => $ex->getMessage()]]);
|
|
|
|
} catch (CallbackNotFound $ex) {
|
|
|
|
$routes->request->status(404, "Callback method not found")->send(["error" => ["message" => $ex->getMessage()]]);
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
$code = $ex->getCode() ?? 500;
|
|
|
|
$routes->request->status($code)->send(["error" => ["message" => $ex->getMessage()]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|