Syntactic sugar for mass route registration.
This commit is contained in:
parent
5c67d49225
commit
7190a5f4df
9 changed files with 52 additions and 38 deletions
14
composer.lock
generated
14
composer.lock
generated
|
@ -348,7 +348,7 @@
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://git.flash.moe/flash/index.git",
|
"url": "https://git.flash.moe/flash/index.git",
|
||||||
"reference": "1172115e699acf44580ffcdcf86c9e3987d2f969"
|
"reference": "2b8b31289d2f4b27c1bc8355348e529cb2177ebc"
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"ext-mbstring": "*",
|
"ext-mbstring": "*",
|
||||||
|
@ -386,7 +386,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-08-28T13:58:51+00:00"
|
"time": "2023-09-06T11:49:54+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "flashwave/sasae",
|
"name": "flashwave/sasae",
|
||||||
|
@ -1721,16 +1721,16 @@
|
||||||
"packages-dev": [
|
"packages-dev": [
|
||||||
{
|
{
|
||||||
"name": "phpstan/phpstan",
|
"name": "phpstan/phpstan",
|
||||||
"version": "1.10.32",
|
"version": "1.10.33",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/phpstan/phpstan.git",
|
"url": "https://github.com/phpstan/phpstan.git",
|
||||||
"reference": "c47e47d3ab03137c0e121e77c4d2cb58672f6d44"
|
"reference": "03b1cf9f814ba0863c4e9affea49a4d1ed9a2ed1"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/c47e47d3ab03137c0e121e77c4d2cb58672f6d44",
|
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/03b1cf9f814ba0863c4e9affea49a4d1ed9a2ed1",
|
||||||
"reference": "c47e47d3ab03137c0e121e77c4d2cb58672f6d44",
|
"reference": "03b1cf9f814ba0863c4e9affea49a4d1ed9a2ed1",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -1779,7 +1779,7 @@
|
||||||
"type": "tidelift"
|
"type": "tidelift"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2023-08-24T21:54:50+00:00"
|
"time": "2023-09-04T12:20:53+00:00"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"aliases": [],
|
"aliases": [],
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace Misuzu\Changelog;
|
||||||
use ErrorException;
|
use ErrorException;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Index\Routing\IRouter;
|
use Index\Routing\IRouter;
|
||||||
|
use Index\Routing\IRouteHandler;
|
||||||
use Misuzu\Pagination;
|
use Misuzu\Pagination;
|
||||||
use Misuzu\Template;
|
use Misuzu\Template;
|
||||||
use Misuzu\Auth\AuthInfo;
|
use Misuzu\Auth\AuthInfo;
|
||||||
|
@ -16,7 +17,7 @@ use Misuzu\Feeds\AtomFeedSerializer;
|
||||||
use Misuzu\Feeds\RssFeedSerializer;
|
use Misuzu\Feeds\RssFeedSerializer;
|
||||||
use Misuzu\Users\Users;
|
use Misuzu\Users\Users;
|
||||||
|
|
||||||
final class ChangelogRoutes {
|
final class ChangelogRoutes implements IRouteHandler {
|
||||||
private IConfig $config;
|
private IConfig $config;
|
||||||
private Changelog $changelog;
|
private Changelog $changelog;
|
||||||
private Users $users;
|
private Users $users;
|
||||||
|
@ -27,7 +28,6 @@ final class ChangelogRoutes {
|
||||||
private array $userColours = [];
|
private array $userColours = [];
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
IRouter $router,
|
|
||||||
IConfig $config,
|
IConfig $config,
|
||||||
Changelog $changelog,
|
Changelog $changelog,
|
||||||
Users $users,
|
Users $users,
|
||||||
|
@ -39,7 +39,9 @@ final class ChangelogRoutes {
|
||||||
$this->users = $users;
|
$this->users = $users;
|
||||||
$this->authInfo = $authInfo;
|
$this->authInfo = $authInfo;
|
||||||
$this->comments = $comments;
|
$this->comments = $comments;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function registerRoutes(IRouter $router): void {
|
||||||
$router->get('/changelog', $this->getIndex(...));
|
$router->get('/changelog', $this->getIndex(...));
|
||||||
$router->get('/changelog.rss', $this->getFeedRSS(...));
|
$router->get('/changelog.rss', $this->getFeedRSS(...));
|
||||||
$router->get('/changelog.atom', $this->getFeedAtom(...));
|
$router->get('/changelog.atom', $this->getFeedAtom(...));
|
||||||
|
|
|
@ -6,6 +6,7 @@ use Index\DateTime;
|
||||||
use Index\Data\DbTools;
|
use Index\Data\DbTools;
|
||||||
use Index\Data\IDbConnection;
|
use Index\Data\IDbConnection;
|
||||||
use Index\Routing\IRouter;
|
use Index\Routing\IRouter;
|
||||||
|
use Index\Routing\IRouteHandler;
|
||||||
use Misuzu\Pagination;
|
use Misuzu\Pagination;
|
||||||
use Misuzu\Template;
|
use Misuzu\Template;
|
||||||
use Misuzu\Auth\AuthInfo;
|
use Misuzu\Auth\AuthInfo;
|
||||||
|
@ -16,7 +17,7 @@ use Misuzu\Counters\Counters;
|
||||||
use Misuzu\News\News;
|
use Misuzu\News\News;
|
||||||
use Misuzu\Users\Users;
|
use Misuzu\Users\Users;
|
||||||
|
|
||||||
class HomeRoutes {
|
class HomeRoutes implements IRouteHandler {
|
||||||
private IConfig $config;
|
private IConfig $config;
|
||||||
private IDbConnection $dbConn;
|
private IDbConnection $dbConn;
|
||||||
private AuthInfo $authInfo;
|
private AuthInfo $authInfo;
|
||||||
|
@ -27,7 +28,6 @@ class HomeRoutes {
|
||||||
private Users $users;
|
private Users $users;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
IRouter $router,
|
|
||||||
IConfig $config,
|
IConfig $config,
|
||||||
IDbConnection $dbConn,
|
IDbConnection $dbConn,
|
||||||
AuthInfo $authInfo,
|
AuthInfo $authInfo,
|
||||||
|
@ -45,7 +45,9 @@ class HomeRoutes {
|
||||||
$this->counters = $counters;
|
$this->counters = $counters;
|
||||||
$this->news = $news;
|
$this->news = $news;
|
||||||
$this->users = $users;
|
$this->users = $users;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function registerRoutes(IRouter $router): void {
|
||||||
$router->get('/', $this->getIndex(...));
|
$router->get('/', $this->getIndex(...));
|
||||||
|
|
||||||
if(MSZ_DEBUG)
|
if(MSZ_DEBUG)
|
||||||
|
|
|
@ -2,10 +2,11 @@
|
||||||
namespace Misuzu\Info;
|
namespace Misuzu\Info;
|
||||||
|
|
||||||
use Index\Routing\IRouter;
|
use Index\Routing\IRouter;
|
||||||
|
use Index\Routing\IRouteHandler;
|
||||||
use Misuzu\Template;
|
use Misuzu\Template;
|
||||||
use Misuzu\Parsers\Parser;
|
use Misuzu\Parsers\Parser;
|
||||||
|
|
||||||
class InfoRoutes {
|
class InfoRoutes implements IRouteHandler {
|
||||||
private const DOCS_PATH = MSZ_ROOT . '/docs';
|
private const DOCS_PATH = MSZ_ROOT . '/docs';
|
||||||
private const PROJECT_PATHS = [
|
private const PROJECT_PATHS = [
|
||||||
'misuzu' => MSZ_ROOT,
|
'misuzu' => MSZ_ROOT,
|
||||||
|
@ -16,7 +17,7 @@ class InfoRoutes {
|
||||||
'index' => 'Index Project » %s',
|
'index' => 'Index Project » %s',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function __construct(IRouter $router) {
|
public function registerRoutes(IRouter $router): void {
|
||||||
$router->get('/info', $this->getIndex(...));
|
$router->get('/info', $this->getIndex(...));
|
||||||
$router->get('/info/:name', $this->getDocsPage(...));
|
$router->get('/info/:name', $this->getDocsPage(...));
|
||||||
$router->get('/info/:project/:name', $this->getProjectPage(...));
|
$router->get('/info/:project/:name', $this->getProjectPage(...));
|
||||||
|
|
|
@ -320,37 +320,37 @@ class MisuzuContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function registerHttpRoutes(): void {
|
private function registerHttpRoutes(): void {
|
||||||
new HomeRoutes(
|
$this->router->register(new HomeRoutes(
|
||||||
$this->router, $this->config, $this->dbConn, $this->authInfo,
|
$this->config, $this->dbConn, $this->authInfo,
|
||||||
$this->changelog, $this->comments, $this->counters, $this->news,
|
$this->changelog, $this->comments, $this->counters, $this->news,
|
||||||
$this->users
|
$this->users
|
||||||
);
|
));
|
||||||
|
|
||||||
new AssetsRoutes($this->router, $this->authInfo, $this->bans, $this->users);
|
$this->router->register(new AssetsRoutes($this->authInfo, $this->bans, $this->users));
|
||||||
|
|
||||||
new InfoRoutes($this->router);
|
$this->router->register(new InfoRoutes);
|
||||||
|
|
||||||
new NewsRoutes(
|
$this->router->register(new NewsRoutes(
|
||||||
$this->router, $this->config, $this->authInfo,
|
$this->config, $this->authInfo,
|
||||||
$this->news, $this->users, $this->comments
|
$this->news, $this->users, $this->comments
|
||||||
);
|
));
|
||||||
|
|
||||||
new ChangelogRoutes(
|
$this->router->register(new ChangelogRoutes(
|
||||||
$this->router, $this->config, $this->changelog,
|
$this->config, $this->changelog,
|
||||||
$this->users, $this->authInfo, $this->comments
|
$this->users, $this->authInfo, $this->comments
|
||||||
);
|
));
|
||||||
|
|
||||||
new SharpChatRoutes(
|
$this->router->register(new SharpChatRoutes(
|
||||||
$this->router, $this->config->scopeTo('sockChat'),
|
$this->config->scopeTo('sockChat'),
|
||||||
$this->bans, $this->emotes, $this->users,
|
$this->bans, $this->emotes, $this->users,
|
||||||
$this->sessions, $this->perms, $this->authInfo,
|
$this->sessions, $this->perms, $this->authInfo,
|
||||||
$this->createAuthTokenPacker(...)
|
$this->createAuthTokenPacker(...)
|
||||||
);
|
));
|
||||||
|
|
||||||
new SatoriRoutes(
|
$this->router->register(new SatoriRoutes(
|
||||||
$this->dbConn, $this->config->scopeTo('satori'),
|
$this->dbConn, $this->config->scopeTo('satori'),
|
||||||
$this->router, $this->users, $this->profileFields
|
$this->users, $this->profileFields
|
||||||
);
|
));
|
||||||
|
|
||||||
// below is still only otherwise available as stinky php files
|
// below is still only otherwise available as stinky php files
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ use Index\DateTime;
|
||||||
use Index\Data\DbTools;
|
use Index\Data\DbTools;
|
||||||
use Index\Data\IDbConnection;
|
use Index\Data\IDbConnection;
|
||||||
use Index\Routing\IRouter;
|
use Index\Routing\IRouter;
|
||||||
|
use Index\Routing\IRouteHandler;
|
||||||
use Misuzu\Pagination;
|
use Misuzu\Pagination;
|
||||||
use Misuzu\Template;
|
use Misuzu\Template;
|
||||||
use Misuzu\Auth\AuthInfo;
|
use Misuzu\Auth\AuthInfo;
|
||||||
|
@ -22,7 +23,7 @@ use Misuzu\News\NewsCategoryInfo;
|
||||||
use Misuzu\Users\Users;
|
use Misuzu\Users\Users;
|
||||||
use Misuzu\Parsers\Parser;
|
use Misuzu\Parsers\Parser;
|
||||||
|
|
||||||
class NewsRoutes {
|
class NewsRoutes implements IRouteHandler {
|
||||||
private IConfig $config;
|
private IConfig $config;
|
||||||
private AuthInfo $authInfo;
|
private AuthInfo $authInfo;
|
||||||
private News $news;
|
private News $news;
|
||||||
|
@ -30,7 +31,6 @@ class NewsRoutes {
|
||||||
private Comments $comments;
|
private Comments $comments;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
IRouter $router,
|
|
||||||
IConfig $config,
|
IConfig $config,
|
||||||
AuthInfo $authInfo,
|
AuthInfo $authInfo,
|
||||||
News $news,
|
News $news,
|
||||||
|
@ -42,7 +42,9 @@ class NewsRoutes {
|
||||||
$this->news = $news;
|
$this->news = $news;
|
||||||
$this->users = $users;
|
$this->users = $users;
|
||||||
$this->comments = $comments;
|
$this->comments = $comments;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function registerRoutes(IRouter $router): void {
|
||||||
$router->get('/news', $this->getIndex(...));
|
$router->get('/news', $this->getIndex(...));
|
||||||
$router->get('/news.rss', $this->getFeedRss(...));
|
$router->get('/news.rss', $this->getFeedRss(...));
|
||||||
$router->get('/news.atom', $this->getFeedAtom(...));
|
$router->get('/news.atom', $this->getFeedAtom(...));
|
||||||
|
|
|
@ -6,12 +6,13 @@ use Index\Data\DbTools;
|
||||||
use Index\Data\IDbConnection;
|
use Index\Data\IDbConnection;
|
||||||
use Index\Http\HttpFx;
|
use Index\Http\HttpFx;
|
||||||
use Index\Routing\IRouter;
|
use Index\Routing\IRouter;
|
||||||
|
use Index\Routing\IRouteHandler;
|
||||||
use Misuzu\Pagination;
|
use Misuzu\Pagination;
|
||||||
use Misuzu\Config\IConfig;
|
use Misuzu\Config\IConfig;
|
||||||
use Misuzu\Profile\ProfileFields;
|
use Misuzu\Profile\ProfileFields;
|
||||||
use Misuzu\Users\Users;
|
use Misuzu\Users\Users;
|
||||||
|
|
||||||
final class SatoriRoutes {
|
final class SatoriRoutes implements IRouteHandler {
|
||||||
private IDbConnection $dbConn;
|
private IDbConnection $dbConn;
|
||||||
private IConfig $config;
|
private IConfig $config;
|
||||||
private Users $users;
|
private Users $users;
|
||||||
|
@ -20,7 +21,6 @@ final class SatoriRoutes {
|
||||||
public function __construct(
|
public function __construct(
|
||||||
IDbConnection $dbConn,
|
IDbConnection $dbConn,
|
||||||
IConfig $config,
|
IConfig $config,
|
||||||
IRouter $router,
|
|
||||||
Users $users,
|
Users $users,
|
||||||
ProfileFields $profileFields
|
ProfileFields $profileFields
|
||||||
) {
|
) {
|
||||||
|
@ -28,7 +28,9 @@ final class SatoriRoutes {
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->users = $users;
|
$this->users = $users;
|
||||||
$this->profileFields = $profileFields;
|
$this->profileFields = $profileFields;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function registerRoutes(IRouter $router): void {
|
||||||
// Simplify default error pages
|
// Simplify default error pages
|
||||||
if($router instanceof HttpFx)
|
if($router instanceof HttpFx)
|
||||||
$router->use('/_satori', function() use($router) {
|
$router->use('/_satori', function() use($router) {
|
||||||
|
|
|
@ -5,6 +5,7 @@ use Closure;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Index\Colour\Colour;
|
use Index\Colour\Colour;
|
||||||
use Index\Routing\IRouter;
|
use Index\Routing\IRouter;
|
||||||
|
use Index\Routing\IRouteHandler;
|
||||||
use Index\Http\HttpFx;
|
use Index\Http\HttpFx;
|
||||||
use Misuzu\Auth\AuthInfo;
|
use Misuzu\Auth\AuthInfo;
|
||||||
use Misuzu\Auth\Sessions;
|
use Misuzu\Auth\Sessions;
|
||||||
|
@ -14,7 +15,7 @@ use Misuzu\Perms\Permissions;
|
||||||
use Misuzu\Users\Bans;
|
use Misuzu\Users\Bans;
|
||||||
use Misuzu\Users\Users;
|
use Misuzu\Users\Users;
|
||||||
|
|
||||||
final class SharpChatRoutes {
|
final class SharpChatRoutes implements IRouteHandler {
|
||||||
private IConfig $config;
|
private IConfig $config;
|
||||||
private Bans $bans;
|
private Bans $bans;
|
||||||
private Emotes $emotes;
|
private Emotes $emotes;
|
||||||
|
@ -26,7 +27,6 @@ final class SharpChatRoutes {
|
||||||
private string $hashKey;
|
private string $hashKey;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
IRouter $router,
|
|
||||||
IConfig $config,
|
IConfig $config,
|
||||||
Bans $bans,
|
Bans $bans,
|
||||||
Emotes $emotes,
|
Emotes $emotes,
|
||||||
|
@ -45,7 +45,9 @@ final class SharpChatRoutes {
|
||||||
$this->authInfo = $authInfo;
|
$this->authInfo = $authInfo;
|
||||||
$this->createAuthTokenPacker = $createAuthTokenPacker;
|
$this->createAuthTokenPacker = $createAuthTokenPacker;
|
||||||
$this->hashKey = $this->config->getString('hashKey', 'woomy');
|
$this->hashKey = $this->config->getString('hashKey', 'woomy');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function registerRoutes(IRouter $router): void {
|
||||||
// Simplify default error pages
|
// Simplify default error pages
|
||||||
if($router instanceof HttpFx)
|
if($router instanceof HttpFx)
|
||||||
$router->use('/_sockchat', function() use($router) {
|
$router->use('/_sockchat', function() use($router) {
|
||||||
|
|
|
@ -4,22 +4,25 @@ namespace Misuzu\Users\Assets;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Index\Routing\IRouter;
|
use Index\Routing\IRouter;
|
||||||
|
use Index\Routing\IRouteHandler;
|
||||||
use Misuzu\Perm;
|
use Misuzu\Perm;
|
||||||
use Misuzu\Auth\AuthInfo;
|
use Misuzu\Auth\AuthInfo;
|
||||||
use Misuzu\Users\Bans;
|
use Misuzu\Users\Bans;
|
||||||
use Misuzu\Users\Users;
|
use Misuzu\Users\Users;
|
||||||
use Misuzu\Users\UserInfo;
|
use Misuzu\Users\UserInfo;
|
||||||
|
|
||||||
class AssetsRoutes {
|
class AssetsRoutes implements IRouteHandler {
|
||||||
private AuthInfo $authInfo;
|
private AuthInfo $authInfo;
|
||||||
private Bans $bans;
|
private Bans $bans;
|
||||||
private Users $users;
|
private Users $users;
|
||||||
|
|
||||||
public function __construct(IRouter $router, AuthInfo $authInfo, Bans $bans, Users $users) {
|
public function __construct(AuthInfo $authInfo, Bans $bans, Users $users) {
|
||||||
$this->authInfo = $authInfo;
|
$this->authInfo = $authInfo;
|
||||||
$this->bans = $bans;
|
$this->bans = $bans;
|
||||||
$this->users = $users;
|
$this->users = $users;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function registerRoutes(IRouter $router): void {
|
||||||
$router->get('/assets/avatar', $this->getAvatar(...));
|
$router->get('/assets/avatar', $this->getAvatar(...));
|
||||||
$router->get('/assets/avatar/:filename', $this->getAvatar(...));
|
$router->get('/assets/avatar/:filename', $this->getAvatar(...));
|
||||||
$router->get('/assets/profile-background', $this->getProfileBackground(...));
|
$router->get('/assets/profile-background', $this->getProfileBackground(...));
|
||||||
|
|
Loading…
Reference in a new issue