diff --git a/composer.json b/composer.json index 87f789c..e061b41 100644 --- a/composer.json +++ b/composer.json @@ -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" } } diff --git a/composer.lock b/composer.lock index 2eb91f3..26ee4c8 100644 --- a/composer.lock +++ b/composer.lock @@ -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", diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000..849a6cd Binary files /dev/null and b/favicon.ico differ diff --git a/index.php b/index.php index d209c1a..7c2ddc1 100644 --- a/index.php +++ b/index.php @@ -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; - } \ No newline at end of file + + $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(); \ No newline at end of file diff --git a/template/includes/head.twig b/template/includes/head.twig index f57d2f8..8fafa7b 100644 --- a/template/includes/head.twig +++ b/template/includes/head.twig @@ -7,7 +7,7 @@ Clyde's Real Survival SMP • {{ pageTitle }} - - + + \ No newline at end of file diff --git a/template/includes/nav.twig b/template/includes/nav.twig index d59e015..8116969 100644 --- a/template/includes/nav.twig +++ b/template/includes/nav.twig @@ -25,7 +25,7 @@