feat: better router

This commit is contained in:
TheClashFruit 2023-09-15 17:42:27 +02:00
parent 5758aee730
commit 78bfef9a1c
Signed by: TheClashFruit
GPG key ID: CF4A319B9A73290C
6 changed files with 81 additions and 18 deletions

View file

@ -2,6 +2,7 @@
"require": {
"twig/twig": "^3.0",
"anlutro/curl": "^1.5",
"vlucas/phpdotenv": "^5.5"
"vlucas/phpdotenv": "^5.5",
"bramus/router": "1.6"
}
}

53
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "3f1571128a1e9ef26dd6298b243bdd9d",
"content-hash": "37fb0f4a910e4ba4add92cd9abbdf84a",
"packages": [
{
"name": "anlutro/curl",
@ -50,6 +50,57 @@
},
"time": "2023-06-27T07:39:41+00:00"
},
{
"name": "bramus/router",
"version": "1.6",
"source": {
"type": "git",
"url": "https://github.com/bramus/router.git",
"reference": "d2cf97d5c471e272ac5a2a88b652bc75089c8ae3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/bramus/router/zipball/d2cf97d5c471e272ac5a2a88b652bc75089c8ae3",
"reference": "d2cf97d5c471e272ac5a2a88b652bc75089c8ae3",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "~2.14",
"phpunit/php-code-coverage": "~2.0",
"phpunit/phpunit": "~4.8"
},
"type": "library",
"autoload": {
"psr-0": {
"Bramus": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Bram(us) Van Damme",
"email": "bramus@bram.us",
"homepage": "http://www.bram.us"
}
],
"description": "A lightweight and simple object oriented PHP Router",
"homepage": "https://github.com/bramus/router",
"keywords": [
"router",
"routing"
],
"support": {
"issues": "https://github.com/bramus/router/issues",
"source": "https://github.com/bramus/router/tree/1.6"
},
"time": "2021-07-23T09:48:14+00:00"
},
{
"name": "graham-campbell/result-type",
"version": "v1.1.1",

BIN
favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

View file

@ -3,20 +3,31 @@
require_once '_config.php';
use Bramus\Router\Router;
$router = new Router();
session_start();
if(isset($_SESSION['user']))
$twig->addGlobal('user', $_SESSION['user']);
switch ($_SERVER['REQUEST_URI']) {
case "/":
echo $twig->render('index.twig');
break;
case "/nations":
echo $twig->render('nations.twig');
break;
default:
http_response_code(404);
echo $twig->render('404.twig');
break;
}
$router->get('/u/([a-z0-9_\.]+)', function($name) {
echo 'Hello ' . htmlentities($name);
});
$router->get('/', function() {
echo $twig->render('index.twig');
});
$router->get('/nations', function() {
echo $twig->render('index.twig');
});
$router->set404(function() {
http_response_code(404);
echo $twig->render('404.twig');
});
$router->run();

View file

@ -7,7 +7,7 @@
<title>Clyde's Real Survival SMP &bull; {{ pageTitle }}</title>
<link rel="icon" href="favicon.ico">
<link rel="stylesheet" href="css/style.min.css">
<link rel="icon" href="/favicon.ico">
<link rel="stylesheet" href="/css/style.min.css">
</head>
<body>

View file

@ -25,7 +25,7 @@
<ul class="navRight">
{% if user %}
<li>
<a class="userButton">
<a class="userButton" href="/u/{{ user.username }}">
{{ user.global_name }}
</a>
</li>