Updated Awaki to new router.

This commit is contained in:
flash 2024-03-28 23:59:45 +00:00
parent acc4e52e3c
commit 03c914ff7a
8 changed files with 60 additions and 58 deletions

40
composer.lock generated
View file

@ -12,7 +12,7 @@
"source": {
"type": "git",
"url": "https://patchii.net/flash/index.git",
"reference": "e31781c69f0b13fe251771c8e7e529222630a44f"
"reference": "9d5b050b8928435416a7efbebe2a19ae8e626224"
},
"require": {
"ext-mbstring": "*",
@ -50,7 +50,7 @@
],
"description": "Composer package for the common library for my projects.",
"homepage": "https://railgun.sh/index",
"time": "2023-11-20T19:01:19+00:00"
"time": "2024-03-28T23:27:04+00:00"
},
{
"name": "flashwave/syokuhou",
@ -58,7 +58,7 @@
"source": {
"type": "git",
"url": "https://patchii.net/flash/syokuhou.git",
"reference": "fdf3c38cc216bf7024af331cbe1758532355c22f"
"reference": "c1fe9371ada20fcea51c225cc53b9ceae4642bc4"
},
"require": {
"flashwave/index": "dev-master",
@ -89,7 +89,7 @@
],
"description": "Configuration library for PHP.",
"homepage": "https://railgun.sh/syokuhou",
"time": "2023-11-20T19:10:04+00:00"
"time": "2024-01-04T02:12:49+00:00"
},
{
"name": "guzzlehttp/psr7",
@ -209,16 +209,16 @@
},
{
"name": "jean85/pretty-package-versions",
"version": "2.0.5",
"version": "2.0.6",
"source": {
"type": "git",
"url": "https://github.com/Jean85/pretty-package-versions.git",
"reference": "ae547e455a3d8babd07b96966b17d7fd21d9c6af"
"reference": "f9fdd29ad8e6d024f52678b570e5593759b550b4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Jean85/pretty-package-versions/zipball/ae547e455a3d8babd07b96966b17d7fd21d9c6af",
"reference": "ae547e455a3d8babd07b96966b17d7fd21d9c6af",
"url": "https://api.github.com/repos/Jean85/pretty-package-versions/zipball/f9fdd29ad8e6d024f52678b570e5593759b550b4",
"reference": "f9fdd29ad8e6d024f52678b570e5593759b550b4",
"shasum": ""
},
"require": {
@ -226,9 +226,9 @@
"php": "^7.1|^8.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.17",
"friendsofphp/php-cs-fixer": "^3.2",
"jean85/composer-provided-replaced-stub-package": "^1.0",
"phpstan/phpstan": "^0.12.66",
"phpstan/phpstan": "^1.4",
"phpunit/phpunit": "^7.5|^8.5|^9.4",
"vimeo/psalm": "^4.3"
},
@ -262,9 +262,9 @@
],
"support": {
"issues": "https://github.com/Jean85/pretty-package-versions/issues",
"source": "https://github.com/Jean85/pretty-package-versions/tree/2.0.5"
"source": "https://github.com/Jean85/pretty-package-versions/tree/2.0.6"
},
"time": "2021-10-08T21:21:46+00:00"
"time": "2024-03-08T09:58:59+00:00"
},
{
"name": "psr/http-factory",
@ -525,16 +525,16 @@
},
{
"name": "sentry/sentry",
"version": "4.1.0",
"version": "4.6.1",
"source": {
"type": "git",
"url": "https://github.com/getsentry/sentry-php.git",
"reference": "89666f297891ff937fceb2f3d1fb967a6848cf37"
"reference": "5a94184175e5830b589bf923da8c9c3af2c0f409"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/getsentry/sentry-php/zipball/89666f297891ff937fceb2f3d1fb967a6848cf37",
"reference": "89666f297891ff937fceb2f3d1fb967a6848cf37",
"url": "https://api.github.com/repos/getsentry/sentry-php/zipball/5a94184175e5830b589bf923da8c9c3af2c0f409",
"reference": "5a94184175e5830b589bf923da8c9c3af2c0f409",
"shasum": ""
},
"require": {
@ -558,7 +558,7 @@
"phpbench/phpbench": "^1.0",
"phpstan/phpstan": "^1.3",
"phpunit/phpunit": "^8.5.14|^9.4",
"symfony/phpunit-bridge": "^5.2|^6.0",
"symfony/phpunit-bridge": "^5.2|^6.0|^7.0",
"vimeo/psalm": "^4.17"
},
"suggest": {
@ -598,7 +598,7 @@
],
"support": {
"issues": "https://github.com/getsentry/sentry-php/issues",
"source": "https://github.com/getsentry/sentry-php/tree/4.1.0"
"source": "https://github.com/getsentry/sentry-php/tree/4.6.1"
},
"funding": [
{
@ -610,7 +610,7 @@
"type": "custom"
}
],
"time": "2023-12-04T12:41:21+00:00"
"time": "2024-03-08T08:18:09+00:00"
},
{
"name": "symfony/deprecation-contracts",
@ -758,5 +758,5 @@
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.3.0"
"plugin-api-version": "2.6.0"
}

View file

@ -18,7 +18,7 @@
</div>
</div>
<div class="awaki-footer">
<a href="https://flash.moe" target="_blank" rel="noopener">Flashwave</a> 2022-2023
<a href="https://flash.moe" target="_blank" rel="noopener">flashwave</a> 2022-2024
</div>
</div>
</div>

View file

@ -18,7 +18,7 @@
</div>
</div>
<div class="awaki-footer">
<a href="https://flash.moe" target="_blank" rel="noopener">Flashwave</a> 2022-2023
<a href="https://flash.moe" target="_blank" rel="noopener">flashwave</a> 2022-2024
</div>
</div>
</div>

View file

@ -18,7 +18,7 @@
</div>
</div>
<div class="awaki-footer">
<a href="https://flash.moe" target="_blank" rel="noopener">flashwave</a> 2022-2023
<a href="https://flash.moe" target="_blank" rel="noopener">flashwave</a> 2022-2024
</div>
</div>
</div>

View file

@ -4,6 +4,4 @@ namespace Awaki;
require_once __DIR__ . '/../awaki.php';
$awk->setUpHttp();
$awk->dispatchHttp(
\Index\Http\HttpRequest::fromRequest()
);
$awk->dispatchHttp();

View file

@ -2,12 +2,8 @@
namespace Awaki;
use Index\Data\IDbConnection;
use Index\Data\Migration\IDbMigrationRepo;
use Index\Data\Migration\DbMigrationManager;
use Index\Data\Migration\FsDbMigrationRepo;
use Index\Http\HttpFx;
use Index\Http\HttpRequest;
use Index\Routing\IRouter;
use Index\Data\Migration\{IDbMigrationRepo,DbMigrationManager,FsDbMigrationRepo};
use Index\Http\Routing\{HttpRouter,IRouter};
use Syokuhou\IConfig;
// theme colours: #99403d, #592824, #d18c83
@ -17,7 +13,7 @@ class AwakiContext {
private const DB_INIT = 'SET SESSION time_zone = \'+00:00\', sql_mode = \'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION\';';
private IDbConnection $dbConn;
private HttpFx $router;
private HttpRouter $router;
private IConfig $urls;
public function __construct(IDbConnection $dbConn, IConfig $urls) {
@ -44,28 +40,18 @@ class AwakiContext {
}
public function setUpHttp(): void {
$this->router = new HttpFx;
$this->router = new HttpRouter(
errorHandler: new RouterErrorHandler,
);
$this->router->use('/', function($response) {
$response->setPoweredBy('Awaki');
});
$this->registerErrorPages();
$this->registerHttpRoutes();
}
public function dispatchHttp(?HttpRequest $request = null): void {
$this->router->dispatch($request);
}
private function registerErrorPages(): void {
$this->router->addErrorHandler(404, function($response) {
$response->accelRedirect('/err404.html');
$response->setTypeHTML();
});
$this->router->addErrorHandler(500, function($response) {
$response->accelRedirect('/err500.html');
$response->setTypeHTML();
});
public function dispatchHttp(): void {
$this->router->dispatch();
}
private function registerHttpRoutes(): void {

View file

@ -2,7 +2,7 @@
namespace Awaki;
use Index\Data\IDbConnection;
use Index\Routing\IRouter;
use Index\Http\Routing\IRouter;
use Syokuhou\IConfig;
final class RedirectorRoutes {
@ -15,22 +15,24 @@ final class RedirectorRoutes {
$router->get('/', [$this, 'index']);
// databased
$router->get('/:id', [$this, 'redirectDatabase']);
// profile
$router->get('/u/:user', [$this, 'redirectProfile']);
$router->get('/p/:user', [$this, 'redirectProfile']);
$router->get('/u([0-9]+)', [$this, 'redirectProfile']);
$router->get('/p([0-9]+)', [$this, 'redirectProfile']);
$router->get('/u/([A-Za-z0-9\-_]+)', [$this, 'redirectProfile']);
$router->get('/p/([A-Za-z0-9\-_]+)', [$this, 'redirectProfile']);
// forum categories
$router->get('/f/:category', [$this, 'redirectForumCategory']);
$router->get('/fc/:category', [$this, 'redirectForumCategory']);
$router->get('/f/?([0-9]+)', [$this, 'redirectForumCategory']);
$router->get('/fc/?([0-9]+)', [$this, 'redirectForumCategory']);
// forum topic
$router->get('/ft/:topic', [$this, 'redirectForumTopic']);
$router->get('/ft/?([0-9]+)', [$this, 'redirectForumTopic']);
// forum post
$router->get('/fp/:post', [$this, 'redirectForumPost']);
$router->get('/fp/?([0-9]+)', [$this, 'redirectForumPost']);
// databased, registered last cuz it matches everything otherwise!
$router->get('/([A-Za-z0-9\-_]+)', [$this, 'redirectDatabase']);
}
public function index($response): void {

View file

@ -0,0 +1,16 @@
<?php
namespace Awaki;
use Index\Http\{HttpResponseBuilder,HttpRequest};
use Index\Http\ErrorHandling\HtmlErrorHandler;
class RouterErrorHandler extends HtmlErrorHandler {
#[\Override]
public function handle(HttpResponseBuilder $response, HttpRequest $request, int $code, string $message): void {
if($code === 404 || $code === 500) {
$response->setTypeHTML();
$response->accelRedirect(sprintf('/err%d.html', $code));
} else
parent::handle($response, $request, $code, $message);
}
}