80 lines
2.0 KiB
PHP
80 lines
2.0 KiB
PHP
|
<?php
|
||
|
|
||
|
// Autoload files using the Composer autoloader.
|
||
|
require_once __DIR__ . '/vendor/autoload.php';
|
||
|
|
||
|
// First Party
|
||
|
use Tor\Tor;
|
||
|
use Tor\Api\Api;
|
||
|
|
||
|
use Tor\Data\Ticket;
|
||
|
use Tor\Data\Grant;
|
||
|
use Tor\Data\Service;
|
||
|
use Tor\Data\User;
|
||
|
|
||
|
// 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
|
||
|
$loader = new \Twig\Loader\FilesystemLoader(__DIR__ . '/templates');
|
||
|
$twig = new \Twig\Environment($loader, [
|
||
|
'cache' => __DIR__. '/compilation_cache',
|
||
|
]);
|
||
|
|
||
|
$tor = new Tor();
|
||
|
$api = new Api();
|
||
|
|
||
|
$service = new Service();
|
||
|
$service->id = "minetest";
|
||
|
$service->token = "45678-hsjsndjs-272892-shgdzusjd-6788";
|
||
|
|
||
|
$user = new User();
|
||
|
$user->id = "bananafish";
|
||
|
$user->serial = '0C:87:64:78';
|
||
|
$user->cert = "Yee Haw";
|
||
|
|
||
|
$grant = new Grant();
|
||
|
$grant->id = uniqid();
|
||
|
$grant->service = $service;
|
||
|
|
||
|
$ticket = new Ticket();
|
||
|
$ticket->id = uniqid();
|
||
|
$ticket->start = 1471111;
|
||
|
$ticket->end = 1474567;
|
||
|
$ticket->user = $user;
|
||
|
$ticket->grant = $grant;
|
||
|
|
||
|
echo(microtime(true));
|
||
|
echo($ticket->Serialize(true));
|
||
|
echo(var_dump(Ticket::Deserialize($ticket->Serialize(true), true)));
|
||
|
echo(Ticket::Deserialize($ticket->Serialize(true), true))->Serialize(true);
|
||
|
echo(microtime(true));
|
||
|
|
||
|
|
||
|
try {
|
||
|
// Initialize Tor in order to register routes
|
||
|
$tor->init();
|
||
|
|
||
|
// Initialize Tor API in order to register routes
|
||
|
$api->init();
|
||
|
|
||
|
// 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()]]);
|
||
|
}
|
||
|
|
||
|
?>
|