Updated HTTP router.

This commit is contained in:
flash 2024-03-30 00:38:44 +00:00
parent b5f9e40079
commit e4f152bf5d
12 changed files with 150 additions and 175 deletions

View file

@ -1,6 +1,6 @@
BSD 2-Clause License BSD 2-Clause License
Copyright (c) 2021-2022, flashwave <me@flash.moe> Copyright (c) 2021-2024, flashwave <me@flash.moe>
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without

156
composer.lock generated
View file

@ -62,7 +62,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": "*",
@ -100,7 +100,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/sasae", "name": "flashwave/sasae",
@ -108,7 +108,7 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://patchii.net/flash/sasae.git", "url": "https://patchii.net/flash/sasae.git",
"reference": "b56dd222acb8f138729e6258d4a90bbb8401ff52" "reference": "c8a9f2974e6591215b3f898dd5525de1e8367f66"
}, },
"require": { "require": {
"flashwave/index": "dev-master", "flashwave/index": "dev-master",
@ -141,7 +141,7 @@
], ],
"description": "A wrapper for Twig with added common functionality.", "description": "A wrapper for Twig with added common functionality.",
"homepage": "https://railgun.sh/sasae", "homepage": "https://railgun.sh/sasae",
"time": "2023-11-20T19:09:35+00:00" "time": "2024-01-04T02:13:42+00:00"
}, },
{ {
"name": "flashwave/syokuhou", "name": "flashwave/syokuhou",
@ -149,7 +149,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",
@ -180,7 +180,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",
@ -300,16 +300,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": {
@ -317,9 +317,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"
}, },
@ -353,9 +353,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",
@ -616,16 +616,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": {
@ -649,7 +649,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": {
@ -689,7 +689,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": [
{ {
@ -701,7 +701,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",
@ -772,16 +772,16 @@
}, },
{ {
"name": "symfony/mime", "name": "symfony/mime",
"version": "v7.0.0", "version": "v7.0.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/mime.git", "url": "https://github.com/symfony/mime.git",
"reference": "0a2fff95c1a10df97f571d67e76c7ae0f0d4f535" "reference": "c1ffe24ba6fdc3e3f0f3fcb93519103b326a3716"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/mime/zipball/0a2fff95c1a10df97f571d67e76c7ae0f0d4f535", "url": "https://api.github.com/repos/symfony/mime/zipball/c1ffe24ba6fdc3e3f0f3fcb93519103b326a3716",
"reference": "0a2fff95c1a10df97f571d67e76c7ae0f0d4f535", "reference": "c1ffe24ba6fdc3e3f0f3fcb93519103b326a3716",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -835,7 +835,7 @@
"mime-type" "mime-type"
], ],
"support": { "support": {
"source": "https://github.com/symfony/mime/tree/v7.0.0" "source": "https://github.com/symfony/mime/tree/v7.0.3"
}, },
"funding": [ "funding": [
{ {
@ -851,7 +851,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-10-19T14:20:43+00:00" "time": "2024-01-30T08:34:29+00:00"
}, },
{ {
"name": "symfony/options-resolver", "name": "symfony/options-resolver",
@ -922,16 +922,16 @@
}, },
{ {
"name": "symfony/polyfill-ctype", "name": "symfony/polyfill-ctype",
"version": "v1.28.0", "version": "v1.29.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-ctype.git", "url": "https://github.com/symfony/polyfill-ctype.git",
"reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb" "reference": "ef4d7e442ca910c4764bce785146269b30cb5fc4"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb", "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/ef4d7e442ca910c4764bce785146269b30cb5fc4",
"reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb", "reference": "ef4d7e442ca910c4764bce785146269b30cb5fc4",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -945,9 +945,6 @@
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": {
"dev-main": "1.28-dev"
},
"thanks": { "thanks": {
"name": "symfony/polyfill", "name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill" "url": "https://github.com/symfony/polyfill"
@ -984,7 +981,7 @@
"portable" "portable"
], ],
"support": { "support": {
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.28.0" "source": "https://github.com/symfony/polyfill-ctype/tree/v1.29.0"
}, },
"funding": [ "funding": [
{ {
@ -1000,20 +997,20 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-01-26T09:26:14+00:00" "time": "2024-01-29T20:11:03+00:00"
}, },
{ {
"name": "symfony/polyfill-intl-idn", "name": "symfony/polyfill-intl-idn",
"version": "v1.28.0", "version": "v1.29.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-intl-idn.git", "url": "https://github.com/symfony/polyfill-intl-idn.git",
"reference": "ecaafce9f77234a6a449d29e49267ba10499116d" "reference": "a287ed7475f85bf6f61890146edbc932c0fff919"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/ecaafce9f77234a6a449d29e49267ba10499116d", "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/a287ed7475f85bf6f61890146edbc932c0fff919",
"reference": "ecaafce9f77234a6a449d29e49267ba10499116d", "reference": "a287ed7475f85bf6f61890146edbc932c0fff919",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1026,9 +1023,6 @@
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": {
"dev-main": "1.28-dev"
},
"thanks": { "thanks": {
"name": "symfony/polyfill", "name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill" "url": "https://github.com/symfony/polyfill"
@ -1071,7 +1065,7 @@
"shim" "shim"
], ],
"support": { "support": {
"source": "https://github.com/symfony/polyfill-intl-idn/tree/v1.28.0" "source": "https://github.com/symfony/polyfill-intl-idn/tree/v1.29.0"
}, },
"funding": [ "funding": [
{ {
@ -1087,20 +1081,20 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-01-26T09:30:37+00:00" "time": "2024-01-29T20:11:03+00:00"
}, },
{ {
"name": "symfony/polyfill-intl-normalizer", "name": "symfony/polyfill-intl-normalizer",
"version": "v1.28.0", "version": "v1.29.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-intl-normalizer.git", "url": "https://github.com/symfony/polyfill-intl-normalizer.git",
"reference": "8c4ad05dd0120b6a53c1ca374dca2ad0a1c4ed92" "reference": "bc45c394692b948b4d383a08d7753968bed9a83d"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/8c4ad05dd0120b6a53c1ca374dca2ad0a1c4ed92", "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/bc45c394692b948b4d383a08d7753968bed9a83d",
"reference": "8c4ad05dd0120b6a53c1ca374dca2ad0a1c4ed92", "reference": "bc45c394692b948b4d383a08d7753968bed9a83d",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1111,9 +1105,6 @@
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": {
"dev-main": "1.28-dev"
},
"thanks": { "thanks": {
"name": "symfony/polyfill", "name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill" "url": "https://github.com/symfony/polyfill"
@ -1155,7 +1146,7 @@
"shim" "shim"
], ],
"support": { "support": {
"source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.28.0" "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.29.0"
}, },
"funding": [ "funding": [
{ {
@ -1171,20 +1162,20 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-01-26T09:26:14+00:00" "time": "2024-01-29T20:11:03+00:00"
}, },
{ {
"name": "symfony/polyfill-mbstring", "name": "symfony/polyfill-mbstring",
"version": "v1.28.0", "version": "v1.29.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git", "url": "https://github.com/symfony/polyfill-mbstring.git",
"reference": "42292d99c55abe617799667f454222c54c60e229" "reference": "9773676c8a1bb1f8d4340a62efe641cf76eda7ec"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/42292d99c55abe617799667f454222c54c60e229", "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9773676c8a1bb1f8d4340a62efe641cf76eda7ec",
"reference": "42292d99c55abe617799667f454222c54c60e229", "reference": "9773676c8a1bb1f8d4340a62efe641cf76eda7ec",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1198,9 +1189,6 @@
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": {
"dev-main": "1.28-dev"
},
"thanks": { "thanks": {
"name": "symfony/polyfill", "name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill" "url": "https://github.com/symfony/polyfill"
@ -1238,7 +1226,7 @@
"shim" "shim"
], ],
"support": { "support": {
"source": "https://github.com/symfony/polyfill-mbstring/tree/v1.28.0" "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.29.0"
}, },
"funding": [ "funding": [
{ {
@ -1254,20 +1242,20 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-07-28T09:04:16+00:00" "time": "2024-01-29T20:11:03+00:00"
}, },
{ {
"name": "symfony/polyfill-php72", "name": "symfony/polyfill-php72",
"version": "v1.28.0", "version": "v1.29.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-php72.git", "url": "https://github.com/symfony/polyfill-php72.git",
"reference": "70f4aebd92afca2f865444d30a4d2151c13c3179" "reference": "861391a8da9a04cbad2d232ddd9e4893220d6e25"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/70f4aebd92afca2f865444d30a4d2151c13c3179", "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/861391a8da9a04cbad2d232ddd9e4893220d6e25",
"reference": "70f4aebd92afca2f865444d30a4d2151c13c3179", "reference": "861391a8da9a04cbad2d232ddd9e4893220d6e25",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1275,9 +1263,6 @@
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": {
"dev-main": "1.28-dev"
},
"thanks": { "thanks": {
"name": "symfony/polyfill", "name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill" "url": "https://github.com/symfony/polyfill"
@ -1314,7 +1299,7 @@
"shim" "shim"
], ],
"support": { "support": {
"source": "https://github.com/symfony/polyfill-php72/tree/v1.28.0" "source": "https://github.com/symfony/polyfill-php72/tree/v1.29.0"
}, },
"funding": [ "funding": [
{ {
@ -1330,20 +1315,20 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-01-26T09:26:14+00:00" "time": "2024-01-29T20:11:03+00:00"
}, },
{ {
"name": "symfony/polyfill-php80", "name": "symfony/polyfill-php80",
"version": "v1.28.0", "version": "v1.29.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-php80.git", "url": "https://github.com/symfony/polyfill-php80.git",
"reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5" "reference": "87b68208d5c1188808dd7839ee1e6c8ec3b02f1b"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/6caa57379c4aec19c0a12a38b59b26487dcfe4b5", "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/87b68208d5c1188808dd7839ee1e6c8ec3b02f1b",
"reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5", "reference": "87b68208d5c1188808dd7839ee1e6c8ec3b02f1b",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1351,9 +1336,6 @@
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": {
"dev-main": "1.28-dev"
},
"thanks": { "thanks": {
"name": "symfony/polyfill", "name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill" "url": "https://github.com/symfony/polyfill"
@ -1397,7 +1379,7 @@
"shim" "shim"
], ],
"support": { "support": {
"source": "https://github.com/symfony/polyfill-php80/tree/v1.28.0" "source": "https://github.com/symfony/polyfill-php80/tree/v1.29.0"
}, },
"funding": [ "funding": [
{ {
@ -1413,7 +1395,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-01-26T09:26:14+00:00" "time": "2024-01-29T20:11:03+00:00"
}, },
{ {
"name": "twig/html-extra", "name": "twig/html-extra",
@ -1555,16 +1537,16 @@
"packages-dev": [ "packages-dev": [
{ {
"name": "phpstan/phpstan", "name": "phpstan/phpstan",
"version": "1.10.50", "version": "1.10.66",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpstan/phpstan.git", "url": "https://github.com/phpstan/phpstan.git",
"reference": "06a98513ac72c03e8366b5a0cb00750b487032e4" "reference": "94779c987e4ebd620025d9e5fdd23323903950bd"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/06a98513ac72c03e8366b5a0cb00750b487032e4", "url": "https://api.github.com/repos/phpstan/phpstan/zipball/94779c987e4ebd620025d9e5fdd23323903950bd",
"reference": "06a98513ac72c03e8366b5a0cb00750b487032e4", "reference": "94779c987e4ebd620025d9e5fdd23323903950bd",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1613,7 +1595,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-12-13T10:59:42+00:00" "time": "2024-03-28T16:17:31+00:00"
} }
], ],
"aliases": [], "aliases": [],
@ -1627,5 +1609,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

@ -1,8 +1,7 @@
<?php <?php
namespace Seria; namespace Seria;
use Index\Routing\Route; use Index\Http\Routing\{HttpGet,RouteHandler};
use Index\Routing\RouteHandler;
use Sasae\SasaeEnvironment; use Sasae\SasaeEnvironment;
class HomeRoutes extends RouteHandler { class HomeRoutes extends RouteHandler {
@ -10,12 +9,12 @@ class HomeRoutes extends RouteHandler {
private ?SasaeEnvironment $templating private ?SasaeEnvironment $templating
) {} ) {}
#[Route('GET', '/')] #[HttpGet('/')]
public function getIndex() { public function getIndex() {
return $this->templating->render('index'); return $this->templating->render('index');
} }
#[Route('GET', '/index.php')] #[HttpGet('/index.php')]
public function getIndexPHP($response): void { public function getIndexPHP($response): void {
$response->redirect('/', true); $response->redirect('/', true);
} }

View file

@ -1,17 +1,13 @@
<?php <?php
namespace Seria; namespace Seria;
use Index\Http\HttpFx; use Index\Http\Routing\{HttpRouter,IRouter,IRouteHandler};
use Index\Http\HttpResponseBuilder;
use Index\Http\HttpRequest;
use Index\Routing\IRouter;
use Index\Routing\IRouteHandler;
class RoutingContext { class RoutingContext {
private HttpFx $router; private HttpRouter $router;
public function __construct() { public function __construct(SeriaContext $context) {
$this->router = new HttpFx; $this->router = new HttpRouter(errorHandler: new RoutingErrorHandler($context));
$this->router->use('/', fn($resp) => $resp->setPoweredBy('Seria')); $this->router->use('/', fn($resp) => $resp->setPoweredBy('Seria'));
} }
@ -19,31 +15,11 @@ class RoutingContext {
return $this->router; return $this->router;
} }
public function registerDefaultErrorPages(): void {
$this->router->setDefaultErrorHandler($this->defaultErrorHandler(...));
$this->router->addErrorHandler(500, fn($resp) => $resp->setContent(file_get_contents(SERIA_DIR_TEMPLATES . '/500.html')));
}
public function defaultErrorHandler(
HttpResponseBuilder $responseBuilder,
HttpRequest $request,
int $code,
string $message
): void {
// todo: render using templating
$responseBuilder->setTypeHTML();
$responseBuilder->setContent(sprintf(
'<!doctype html><html><head><meta charset="utf-8"/><title>%1$03d %2$s</title></head><body><center><h1>%1$03d %2$s</h1></center><hr/><center>Seria</center></body></html>',
$code,
$message
));
}
public function register(IRouteHandler $handler): void { public function register(IRouteHandler $handler): void {
$this->router->register($handler); $this->router->register($handler);
} }
public function dispatch(?HttpRequest $request = null): void { public function dispatch(): void {
$this->router->dispatch($request); $this->router->dispatch();
} }
} }

View file

@ -0,0 +1,32 @@
<?php
namespace Seria;
use Index\Http\{HttpResponseBuilder,HttpRequest};
use Index\Http\ErrorHandling\IErrorHandler;
class RoutingErrorHandler implements IErrorHandler {
public function __construct(
private SeriaContext $context
) {}
public function handle(HttpResponseBuilder $response, HttpRequest $request, int $code, string $message): void {
if($code === 500) {
$response->setTypeHTML();
$response->setContent(file_get_contents(SERIA_DIR_TEMPLATES . '/500.html'));
return;
}
$templating = $this->context->getTemplating();
if($templating === null) {
$response->setTypePlain();
$response->setContent((string)$code);
return;
}
$response->setTypeHTML();
$response->setContent($templating->render('http-error', [
'http_code' => $code,
'http_text' => $message,
]));
}
}

View file

@ -4,9 +4,7 @@ namespace Seria;
use InvalidArgumentException; use InvalidArgumentException;
use Index\Environment; use Index\Environment;
use Index\Data\IDbTransactions; use Index\Data\IDbTransactions;
use Index\Data\Migration\IDbMigrationRepo; use Index\Data\Migration\{IDbMigrationRepo,DbMigrationManager,FsDbMigrationRepo};
use Index\Data\Migration\DbMigrationManager;
use Index\Data\Migration\FsDbMigrationRepo;
use Index\Security\CSRFP; use Index\Security\CSRFP;
use Sasae\SasaeEnvironment; use Sasae\SasaeEnvironment;
use Syokuhou\IConfig; use Syokuhou\IConfig;
@ -101,11 +99,7 @@ final class SeriaContext {
} }
public function createRouting(): RoutingContext { public function createRouting(): RoutingContext {
$routing = new RoutingContext; $routing = new RoutingContext($this);
$routing->registerDefaultErrorPages();
$self = $this;
$router = $routing->getRouter();
$routing->register(new HomeRoutes($this->templating)); $routing->register(new HomeRoutes($this->templating));
$routing->register(new Users\ProfileRoutes($this->authInfo, $this->torrentsCtx, $this->usersCtx, $this->templating)); $routing->register(new Users\ProfileRoutes($this->authInfo, $this->torrentsCtx, $this->usersCtx, $this->templating));

View file

@ -2,8 +2,7 @@
namespace Seria\Torrents; namespace Seria\Torrents;
use RuntimeException; use RuntimeException;
use Index\Routing\Route; use Index\Http\Routing\{HttpGet,RouteHandler};
use Index\Routing\RouteHandler;
use Index\Serialisation\Bencode; use Index\Serialisation\Bencode;
use Seria\Users\UsersContext; use Seria\Users\UsersContext;
@ -16,10 +15,10 @@ class AnnounceRouting extends RouteHandler {
private UsersContext $usersCtx private UsersContext $usersCtx
) {} ) {}
#[Route('GET', '/announce')] #[HttpGet('/announce')]
#[Route('GET', '/announce.php')] #[HttpGet('/announce.php')]
#[Route('GET', '/announce/:key')] #[HttpGet('/announce/:key')]
#[Route('GET', '/announce.php/:key')] #[HttpGet('/announce.php/:key')]
public function getAnnounce($response, $request, string $key = '') { public function getAnnounce($response, $request, string $key = '') {
if(strlen(inet_pton($_SERVER['REMOTE_ADDR'])) !== 4) if(strlen(inet_pton($_SERVER['REMOTE_ADDR'])) !== 4)
return new AnnounceFailure('Tracker is only supported over IPv4, please reset your DNS cache.'); return new AnnounceFailure('Tracker is only supported over IPv4, please reset your DNS cache.');

View file

@ -4,8 +4,7 @@ namespace Seria\Torrents;
use Exception; use Exception;
use RuntimeException; use RuntimeException;
use Index\Data\IDbTransactions; use Index\Data\IDbTransactions;
use Index\Routing\Route; use Index\Http\Routing\{HttpGet,HttpMiddleware,HttpPost,RouteHandler};
use Index\Routing\RouteHandler;
use Index\Security\CSRFP; use Index\Security\CSRFP;
use Sasae\SasaeEnvironment; use Sasae\SasaeEnvironment;
use Seria\Auth\AuthInfo; use Seria\Auth\AuthInfo;
@ -20,7 +19,7 @@ class TorrentCreateRouting extends RouteHandler {
private ?SasaeEnvironment $templating private ?SasaeEnvironment $templating
) {} ) {}
#[Route('/create')] #[HttpMiddleware('/create')]
public function checkAccess() { public function checkAccess() {
if(!$this->authInfo->isLoggedIn()) if(!$this->authInfo->isLoggedIn())
return 403; return 403;
@ -28,7 +27,7 @@ class TorrentCreateRouting extends RouteHandler {
return 403; return 403;
} }
#[Route('GET', '/create')] #[HttpGet('/create')]
public function getCreate($response, $request) { public function getCreate($response, $request) {
$template = $this->templating->load('create'); $template = $this->templating->load('create');
@ -44,7 +43,7 @@ class TorrentCreateRouting extends RouteHandler {
return $template; return $template;
} }
#[Route('POST', '/create')] #[HttpPost('/create')]
public function postCreate($response, $request) { public function postCreate($response, $request) {
if(!$request->isFormContent()) if(!$request->isFormContent())
return 400; return 400;
@ -95,7 +94,7 @@ class TorrentCreateRouting extends RouteHandler {
$response->redirect(sprintf('/info/%s', $torrentId)); $response->redirect(sprintf('/info/%s', $torrentId));
} }
#[Route('GET', '/create.php')] #[HttpGet('/create.php')]
public function getCreatePHP($response, $request) { public function getCreatePHP($response, $request) {
$response->redirect('/create', true); $response->redirect('/create', true);
} }

View file

@ -2,8 +2,7 @@
namespace Seria\Torrents; namespace Seria\Torrents;
use RuntimeException; use RuntimeException;
use Index\Routing\Route; use Index\Http\Routing\{HttpGet,HttpMiddleware,HttpPost,RouteHandler};
use Index\Routing\RouteHandler;
use Index\Security\CSRFP; use Index\Security\CSRFP;
use Sasae\SasaeEnvironment; use Sasae\SasaeEnvironment;
use Syokuhou\IConfig; use Syokuhou\IConfig;
@ -22,7 +21,7 @@ class TorrentInfoRouting extends RouteHandler {
private ?SasaeEnvironment $templating private ?SasaeEnvironment $templating
) {} ) {}
#[Route('GET', '/download/:id')] #[HttpGet('/download/([0-9]+)')]
public function getDownload($response, $request, string $torrentId) { public function getDownload($response, $request, string $torrentId) {
try { try {
$torrentInfo = $this->torrentsCtx->getTorrents()->getTorrent($torrentId); $torrentInfo = $this->torrentsCtx->getTorrents()->getTorrent($torrentId);
@ -77,7 +76,7 @@ class TorrentInfoRouting extends RouteHandler {
return 0; return 0;
} }
#[Route('GET', '/info/:id')] #[HttpGet('/info/([0-9]+)')]
public function getInfo($response, $request, string $torrentId) { public function getInfo($response, $request, string $torrentId) {
$error = $this->getTorrentInfo($torrentId); $error = $this->getTorrentInfo($torrentId);
if($error > 0) return $error; if($error > 0) return $error;
@ -105,9 +104,9 @@ class TorrentInfoRouting extends RouteHandler {
]); ]);
} }
#[Route('/info/:id/rehash')] #[HttpMiddleware('/info/([0-9]+)/rehash')]
#[Route('/info/:id/approve')] #[HttpMiddleware('/info/([0-9]+)/approve')]
#[Route('/info/:id/deny')] #[HttpMiddleware('/info/([0-9]+)/deny')]
public function verifyRequest($response, $request, string $torrentId) { public function verifyRequest($response, $request, string $torrentId) {
if(!$this->authInfo->isLoggedIn()) if(!$this->authInfo->isLoggedIn())
return 401; return 401;
@ -123,7 +122,7 @@ class TorrentInfoRouting extends RouteHandler {
if($error > 0) return $error; if($error > 0) return $error;
} }
#[Route('POST', '/info/:id/rehash')] #[HttpPost('/info/([0-9]+)/rehash')]
public function postRehash($response, $request, string $torrentId) { public function postRehash($response, $request, string $torrentId) {
$error = $this->getTorrentInfo($torrentId); $error = $this->getTorrentInfo($torrentId);
if($error > 0) return $error; if($error > 0) return $error;
@ -144,7 +143,7 @@ class TorrentInfoRouting extends RouteHandler {
]; ];
} }
#[Route('POST', '/info/:id/approve')] #[HttpPost('/info/([0-9]+)/approve')]
public function postApprove($response, $request, string $torrentId) { public function postApprove($response, $request, string $torrentId) {
$error = $this->getTorrentInfo($torrentId); $error = $this->getTorrentInfo($torrentId);
if($error > 0) return $error; if($error > 0) return $error;
@ -157,7 +156,7 @@ class TorrentInfoRouting extends RouteHandler {
return 204; return 204;
} }
#[Route('POST', '/info/:id/deny')] #[HttpPost('/info/([0-9]+)/deny')]
public function postDeny($response, $request, string $torrentId) { public function postDeny($response, $request, string $torrentId) {
$error = $this->getTorrentInfo($torrentId); $error = $this->getTorrentInfo($torrentId);
if($error > 0) return $error; if($error > 0) return $error;
@ -170,7 +169,7 @@ class TorrentInfoRouting extends RouteHandler {
return 204; return 204;
} }
#[Route('GET', '/info.php')] #[HttpGet('/info.php')]
public function getInfoPHP($response, $request) { public function getInfoPHP($response, $request) {
$torrentId = (int)$request->getParam('id', FILTER_SANITIZE_NUMBER_INT); $torrentId = (int)$request->getParam('id', FILTER_SANITIZE_NUMBER_INT);
if($torrentId < 1) if($torrentId < 1)
@ -179,7 +178,7 @@ class TorrentInfoRouting extends RouteHandler {
$response->redirect(sprintf('/info/%d', $torrentId), true); $response->redirect(sprintf('/info/%d', $torrentId), true);
} }
#[Route('GET', '/download.php')] #[HttpGet('/download.php')]
public function getDownloadPHP($response, $request) { public function getDownloadPHP($response, $request) {
$torrentId = (int)$request->getParam('id', FILTER_SANITIZE_NUMBER_INT); $torrentId = (int)$request->getParam('id', FILTER_SANITIZE_NUMBER_INT);
if($torrentId < 1) if($torrentId < 1)

View file

@ -2,8 +2,7 @@
namespace Seria\Torrents; namespace Seria\Torrents;
use RuntimeException; use RuntimeException;
use Index\Routing\Route; use Index\Http\Routing\{HttpGet,RouteHandler};
use Index\Routing\RouteHandler;
use Sasae\SasaeEnvironment; use Sasae\SasaeEnvironment;
use Seria\Auth\AuthInfo; use Seria\Auth\AuthInfo;
use Seria\Users\UsersContext; use Seria\Users\UsersContext;
@ -16,7 +15,7 @@ class TorrentListRouting extends RouteHandler {
private ?SasaeEnvironment $templating private ?SasaeEnvironment $templating
) {} ) {}
#[Route('GET', '/available')] #[HttpGet('/available')]
public function getAvailable($response, $request) { public function getAvailable($response, $request) {
$users = $this->usersCtx->getUsers(); $users = $this->usersCtx->getUsers();
$peers = $this->torrentsCtx->getPeers(); $peers = $this->torrentsCtx->getPeers();
@ -64,7 +63,7 @@ class TorrentListRouting extends RouteHandler {
]); ]);
} }
#[Route('GET', '/pending')] #[HttpGet('/pending')]
public function getPending($response, $request) { public function getPending($response, $request) {
if(!$this->authInfo->isLoggedIn()) if(!$this->authInfo->isLoggedIn())
return 403; return 403;
@ -101,7 +100,7 @@ class TorrentListRouting extends RouteHandler {
]); ]);
} }
#[Route('GET', '/available.php')] #[HttpGet('/available.php')]
public function getAvailablePHP($response, $request): void { public function getAvailablePHP($response, $request): void {
$query = []; $query = [];
@ -119,7 +118,7 @@ class TorrentListRouting extends RouteHandler {
$response->redirect($url, true); $response->redirect($url, true);
} }
#[Route('GET', '/pending.php')] #[HttpGet('/pending.php')]
public function getPendingPHP($response, $request): void { public function getPendingPHP($response, $request): void {
$query = []; $query = [];

View file

@ -2,13 +2,10 @@
namespace Seria\Users; namespace Seria\Users;
use RuntimeException; use RuntimeException;
use Index\Routing\Route; use Index\Http\Routing\{HttpGet,RouteHandler};
use Index\Routing\RouteHandler;
use Sasae\SasaeEnvironment; use Sasae\SasaeEnvironment;
use Seria\Auth\AuthInfo; use Seria\Auth\AuthInfo;
use Seria\Torrents\TorrentsContext; use Seria\Torrents\{TorrentsContext,TorrentInfo,TorrentPeerInfo};
use Seria\Torrents\TorrentInfo;
use Seria\Torrents\TorrentPeerInfo;
class ProfileRoutes extends RouteHandler { class ProfileRoutes extends RouteHandler {
public function __construct( public function __construct(
@ -18,7 +15,7 @@ class ProfileRoutes extends RouteHandler {
private ?SasaeEnvironment $templating private ?SasaeEnvironment $templating
) {} ) {}
#[Route('GET', '/profile/:name')] #[HttpGet('/profile/([a-zA-Z0-9\-_]+)')]
public function getProfile($response, $request, string $name) { public function getProfile($response, $request, string $name) {
if(!$this->authInfo->isLoggedIn()) if(!$this->authInfo->isLoggedIn())
return 403; return 403;
@ -54,7 +51,7 @@ class ProfileRoutes extends RouteHandler {
]); ]);
} }
#[Route('GET', '/profile/:name/history')] #[HttpGet('/profile/([a-zA-Z0-9\-_]+)/history')]
public function getHistory($response, $request, string $name) { public function getHistory($response, $request, string $name) {
if(!$this->authInfo->isLoggedIn()) if(!$this->authInfo->isLoggedIn())
return 403; return 403;
@ -72,12 +69,12 @@ class ProfileRoutes extends RouteHandler {
]); ]);
} }
#[Route('GET', '/profile.php')] #[HttpGet('/profile.php')]
public function getProfilePHP($response, $request): void { public function getProfilePHP($response, $request): void {
$response->redirect(sprintf('/profile/%s', (string)$request->getParam('name')), true); $response->redirect(sprintf('/profile/%s', (string)$request->getParam('name')), true);
} }
#[Route('GET', '/history.php')] #[HttpGet('/history.php')]
public function getHistoryPHP($response, $request) { public function getHistoryPHP($response, $request) {
$userName = (string)$request->getParam('name'); $userName = (string)$request->getParam('name');
if($userName === '' && $this->authInfo->isLoggedIn()) if($userName === '' && $this->authInfo->isLoggedIn())

View file

@ -1,8 +1,7 @@
<?php <?php
namespace Seria\Users; namespace Seria\Users;
use Index\Routing\Route; use Index\Http\Routing\{HttpGet,HttpMiddleware,HttpPost,RouteHandler};
use Index\Routing\RouteHandler;
use Index\Security\CSRFP; use Index\Security\CSRFP;
use Sasae\SasaeEnvironment; use Sasae\SasaeEnvironment;
use Seria\Auth\AuthInfo; use Seria\Auth\AuthInfo;
@ -16,7 +15,7 @@ class SettingsRoutes extends RouteHandler {
private ?SasaeEnvironment $templating private ?SasaeEnvironment $templating
) {} ) {}
#[Route('/settings')] #[HttpMiddleware('/settings')]
public function checkLogin($response, $request) { public function checkLogin($response, $request) {
if(!$this->authInfo->isLoggedIn()) if(!$this->authInfo->isLoggedIn())
return 403; return 403;
@ -31,18 +30,18 @@ class SettingsRoutes extends RouteHandler {
} }
} }
#[Route('GET', '/settings')] #[HttpGet('/settings')]
public function getIndex($response) { public function getIndex($response) {
return $this->templating->render('settings'); return $this->templating->render('settings');
} }
#[Route('POST', '/settings/passkey')] #[HttpPost('/settings/passkey')]
public function postPasskey($response) { public function postPasskey($response) {
$this->usersCtx->getUsers()->updatePassKey($this->authInfo->getUserInfo()); $this->usersCtx->getUsers()->updatePassKey($this->authInfo->getUserInfo());
$response->redirect('/settings'); $response->redirect('/settings');
} }
#[Route('GET', '/settings.php')] #[HttpGet('/settings.php')]
public function getSettingsPHP($response): void { public function getSettingsPHP($response): void {
$response->redirect('/settings', true); $response->redirect('/settings', true);
} }