2022-12-05 20:52:40 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// Autoload files using the Composer autoloader.
|
|
|
|
require_once __DIR__ . '/vendor/autoload.php';
|
|
|
|
|
|
|
|
// First Party
|
|
|
|
use GeNF\Dispatcher;
|
2023-08-14 11:52:57 +02:00
|
|
|
use GeNF\Data\ShortLink;
|
|
|
|
use GeNF\Data\ELinkType;
|
|
|
|
|
|
|
|
use TrueBV\Punycode;
|
2022-12-05 20:52:40 +01:00
|
|
|
|
|
|
|
use SeriousJSON\JsonDatabase;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
$loader = new \Twig\Loader\FilesystemLoader(__DIR__ . DIRECTORY_SEPARATOR . 'templates');
|
|
|
|
$twig = new \Twig\Environment($loader, [
|
|
|
|
'cache' => __DIR__ . DIRECTORY_SEPARATOR . 'compilation_cache',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$data = new JsonDatabase(__DIR__ . DIRECTORY_SEPARATOR . 'data');
|
|
|
|
$dispatcher = new Dispatcher();
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Initialize Database
|
|
|
|
$data->init();
|
|
|
|
|
|
|
|
// Initialize ge.nf Dispatcher in order to register routes
|
|
|
|
$dispatcher->init();
|
|
|
|
|
|
|
|
// Handle routes
|
|
|
|
$routes->handle();
|
2023-08-14 11:52:57 +02:00
|
|
|
|
|
|
|
// Test
|
|
|
|
$shortLink = new ShortLink();
|
|
|
|
$punycode = new Punycode();
|
|
|
|
$shortLink->setIdentifier($punycode->encode('🤣🤣🤣⚑⚑⚑'));
|
|
|
|
$shortLink->linkType = ELinkType::Emoji;
|
|
|
|
$shortLink->create = time();
|
|
|
|
$data->save($shortLink);
|
2022-12-05 20:52:40 +01:00
|
|
|
} 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()]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|