Updated Satori scripts to new HTTP router.

This commit is contained in:
flash 2024-03-30 00:02:23 +00:00
parent de08e4e4cc
commit 4f1a8c43ab
10 changed files with 54 additions and 54 deletions

40
composer.lock generated
View file

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

View file

@ -3,8 +3,7 @@ namespace Satori\Booru;
use stdClass; use stdClass;
use Index\XArray; use Index\XArray;
use Index\Routing\Route; use Index\Http\Routing\{HttpGet,RouteHandler};
use Index\Routing\RouteHandler;
class BooruRoutes extends RouteHandler { class BooruRoutes extends RouteHandler {
public function __construct( public function __construct(
@ -36,7 +35,7 @@ class BooruRoutes extends RouteHandler {
}); });
} }
#[Route('GET', '/booru.php')] #[HttpGet('/booru.php')]
public function getPHP($response, $request) { public function getPHP($response, $request) {
$sourceName = (string)$request->getParam('b'); $sourceName = (string)$request->getParam('b');
$tags = (string)$request->getParam('t'); $tags = (string)$request->getParam('t');

View file

@ -2,9 +2,7 @@
namespace Satori; namespace Satori;
use Index\Data\IDbConnection; use Index\Data\IDbConnection;
use Index\Data\Migration\IDbMigrationRepo; use Index\Data\Migration\{IDbMigrationRepo,DbMigrationManager,FsDbMigrationRepo};
use Index\Data\Migration\DbMigrationManager;
use Index\Data\Migration\FsDbMigrationRepo;
class DatabaseContext { class DatabaseContext {
public function __construct( public function __construct(

View file

@ -1,15 +1,14 @@
<?php <?php
namespace Satori\Dictionary; namespace Satori\Dictionary;
use Index\Routing\Route; use Index\Http\Routing\{HttpGet,RouteHandler};
use Index\Routing\RouteHandler;
class DictionaryRoutes extends RouteHandler { class DictionaryRoutes extends RouteHandler {
public function __construct( public function __construct(
private DictionaryContext $context private DictionaryContext $context
) {} ) {}
#[Route('GET', '/dictionary/define')] #[HttpGet('/dictionary/define')]
public function getDefine($response, $request) { public function getDefine($response, $request) {
$word = trim((string)$request->getParam('word')); $word = trim((string)$request->getParam('word'));
if($word === '') if($word === '')
@ -36,7 +35,7 @@ class DictionaryRoutes extends RouteHandler {
return $response; return $response;
} }
#[Route('GET', '/word-define.php')] #[HttpGet('/word-define.php')]
public function getPHP($response, $request) { public function getPHP($response, $request) {
$word = trim((string)$request->getParam('word')); $word = trim((string)$request->getParam('word'));
if($word === '') if($word === '')

View file

@ -2,15 +2,14 @@
namespace Satori\ExRate; namespace Satori\ExRate;
use stdClass; use stdClass;
use Index\Routing\Route; use Index\Http\Routing\{HttpGet,RouteHandler};
use Index\Routing\RouteHandler;
class ExRateRoutes extends RouteHandler { class ExRateRoutes extends RouteHandler {
public function __construct( public function __construct(
private ExRateContext $context private ExRateContext $context
) {} ) {}
#[Route('GET', '/exrate/convert')] #[HttpGet('/exrate/convert')]
public function getConvert($response, $request) { public function getConvert($response, $request) {
$from = strtoupper((string)$request->getParam('from')); $from = strtoupper((string)$request->getParam('from'));
$targets = explode(',', strtoupper((string)$request->getParam('to'))); $targets = explode(',', strtoupper((string)$request->getParam('to')));
@ -47,7 +46,7 @@ class ExRateRoutes extends RouteHandler {
return $response; return $response;
} }
#[Route('GET', '/exrate.php')] #[HttpGet('/exrate.php')]
public function getPHP($response, $request) { public function getPHP($response, $request) {
$from = strtoupper((string)$request->getParam('from')); $from = strtoupper((string)$request->getParam('from'));
$to = strtoupper((string)$request->getParam('to')); $to = strtoupper((string)$request->getParam('to'));

View file

@ -1,16 +1,14 @@
<?php <?php
namespace Satori; namespace Satori;
use Index\Http\HttpFx;
use Index\Http\HttpRequest; use Index\Http\HttpRequest;
use Index\Routing\IRouter; use Index\Http\Routing\{HttpRouter,IRouter,IRouteHandler};
use Index\Routing\IRouteHandler;
class RoutingContext { class RoutingContext {
private HttpFx $router; private HttpRouter $router;
public function __construct() { public function __construct() {
$this->router = new HttpFx; $this->router = new HttpRouter(errorHandler: new RoutingErrorHandler);
$this->router->use('/', fn($resp) => $resp->setPoweredBy('Satori')); $this->router->use('/', fn($resp) => $resp->setPoweredBy('Satori'));
} }
@ -18,14 +16,6 @@ class RoutingContext {
return $this->router; return $this->router;
} }
public function registerDefaultErrorPages(): void {
$this->router->addErrorHandler(401, fn($resp) => $resp->setContent(file_get_contents(SAT_DIR_PUBLIC . '/404.html')));
$this->router->addErrorHandler(403, fn($resp) => $resp->setContent(file_get_contents(SAT_DIR_PUBLIC . '/404.html')));
$this->router->addErrorHandler(404, fn($resp) => $resp->setContent(file_get_contents(SAT_DIR_PUBLIC . '/404.html')));
$this->router->addErrorHandler(500, fn($resp) => $resp->setContent(file_get_contents(SAT_DIR_PUBLIC . '/404.html')));
$this->router->addErrorHandler(503, fn($resp) => $resp->setContent(file_get_contents(SAT_DIR_PUBLIC . '/404.html')));
}
public function register(IRouteHandler $handler): void { public function register(IRouteHandler $handler): void {
$this->router->register($handler); $this->router->register($handler);
} }

View file

@ -0,0 +1,18 @@
<?php
namespace Satori;
use Index\Http\{HttpResponseBuilder,HttpRequest};
use Index\Http\ErrorHandling\HtmlErrorHandler;
class RoutingErrorHandler extends HtmlErrorHandler {
#[\Override]
public function handle(HttpResponseBuilder $response, HttpRequest $request, int $code, string $message): void {
if($code === 401 || $code === 403 || $code === 404 || $code === 500 || $code === 503) {
$response->setTypeHTML();
$response->setContent(file_get_contents(SAT_DIR_PUBLIC . '/404.html'));
return;
}
parent::handle($response, $request, $code, $message);
}
}

View file

@ -54,7 +54,6 @@ final class SatoriContext {
public function createRouting(): RoutingContext { public function createRouting(): RoutingContext {
$routingCtx = new RoutingContext; $routingCtx = new RoutingContext;
$routingCtx->registerDefaultErrorPages();
$routingCtx->register(new ExRate\ExRateRoutes($this->createExRates())); $routingCtx->register(new ExRate\ExRateRoutes($this->createExRates()));
$routingCtx->register(new Dictionary\DictionaryRoutes($this->createDictionary())); $routingCtx->register(new Dictionary\DictionaryRoutes($this->createDictionary()));

View file

@ -3,8 +3,7 @@ namespace Satori\Splatoon;
use stdClass; use stdClass;
use Index\XArray; use Index\XArray;
use Index\Routing\Route; use Index\Http\Routing\{HttpGet,RouteHandler};
use Index\Routing\RouteHandler;
class SplatoonRoutes extends RouteHandler { class SplatoonRoutes extends RouteHandler {
public function __construct( public function __construct(
@ -28,7 +27,7 @@ class SplatoonRoutes extends RouteHandler {
]; ];
} }
#[Route('GET', '/splatoon.php')] #[HttpGet('/splatoon.php')]
public function getPHP($response, $request) { public function getPHP($response, $request) {
$gameInfo = $this->context->getGameByName((string)$request->getParam('g')); $gameInfo = $this->context->getGameByName((string)$request->getParam('g'));
if($gameInfo === null) if($gameInfo === null)

View file

@ -2,15 +2,14 @@
namespace Satori\Translation; namespace Satori\Translation;
use DOMDocument; use DOMDocument;
use Index\Routing\Route; use Index\Http\Routing\{HttpGet,RouteHandler};
use Index\Routing\RouteHandler;
class TranslateRoutes extends RouteHandler { class TranslateRoutes extends RouteHandler {
public function __construct( public function __construct(
private TranslateContext $context private TranslateContext $context
) {} ) {}
#[Route('GET', '/translate.php')] #[HttpGet('/translate.php')]
public function getPHP($response, $request) { public function getPHP($response, $request) {
$format = (string)($request->getParam('fmt') ?? 'json'); $format = (string)($request->getParam('fmt') ?? 'json');
if($format !== 'json' && $format !== 'xml') if($format !== 'json' && $format !== 'xml')