Initial implementation of the dependency injector thingy.
This commit is contained in:
parent
d462ee0594
commit
9e5945cbd4
3 changed files with 62 additions and 130 deletions
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
namespace Misuzu;
|
||||
|
||||
use Index\Dependencies;
|
||||
use Index\Config\Config;
|
||||
use Index\Db\DbConnection;
|
||||
use Index\Db\Migration\{DbMigrationManager,DbMigrationRepo,FsDbMigrationRepo};
|
||||
|
@ -32,6 +33,8 @@ use RPCii\Server\HttpRpcServer;
|
|||
// dunno if i want null checks some maybe some kind of init func should be called first like is the case
|
||||
// with the http shit
|
||||
class MisuzuContext {
|
||||
public private(set) Dependencies $deps;
|
||||
|
||||
private TplEnvironment $templating;
|
||||
|
||||
public private(set) AuditLogData $auditLog;
|
||||
|
@ -62,23 +65,29 @@ class MisuzuContext {
|
|||
public private(set) Config $config,
|
||||
public private(set) Config $env
|
||||
) {
|
||||
$this->perms = new PermissionsData($dbConn);
|
||||
$this->authInfo = new AuthInfo($this->perms);
|
||||
$this->siteInfo = new SiteInfo($config->scopeTo('site'));
|
||||
$this->deps = new Dependencies;
|
||||
$this->deps->register($this->deps);
|
||||
$this->deps->register($this->dbConn);
|
||||
$this->deps->register($this->config);
|
||||
$this->deps->register($this->env);
|
||||
|
||||
$this->authCtx = new AuthContext($dbConn, $config->scopeTo('auth'));
|
||||
$this->forumCtx = new ForumContext($dbConn);
|
||||
$this->messagesCtx = new MessagesContext($dbConn);
|
||||
$this->usersCtx = new UsersContext($dbConn);
|
||||
$this->redirectsCtx = new RedirectsContext($dbConn, $config->scopeTo('redirects'));
|
||||
$this->deps->register($this->perms = new PermissionsData($dbConn));
|
||||
$this->deps->register($this->authInfo = $this->deps->constructLazy(AuthInfo::class));
|
||||
$this->deps->register($this->siteInfo = $this->deps->constructLazy(SiteInfo::class, config: $config->scopeTo('site')));
|
||||
|
||||
$this->auditLog = new AuditLogData($dbConn);
|
||||
$this->changelog = new ChangelogData($dbConn);
|
||||
$this->comments = new CommentsData($dbConn);
|
||||
$this->counters = new CountersData($dbConn);
|
||||
$this->emotes = new EmotesData($dbConn);
|
||||
$this->news = new NewsData($dbConn);
|
||||
$this->profileFields = new ProfileFieldsData($dbConn);
|
||||
$this->deps->register($this->authCtx = $this->deps->constructLazy(AuthContext::class, config: $config->scopeTo('auth')));
|
||||
$this->deps->register($this->forumCtx = $this->deps->constructLazy(ForumContext::class));
|
||||
$this->deps->register($this->messagesCtx = $this->deps->constructLazy(MessagesContext::class));
|
||||
$this->deps->register($this->usersCtx = $this->deps->constructLazy(UsersContext::class));
|
||||
$this->deps->register($this->redirectsCtx = $this->deps->constructLazy(RedirectsContext::class, config: $config->scopeTo('redirects')));
|
||||
|
||||
$this->deps->register($this->auditLog = $this->deps->constructLazy(AuditLogData::class));
|
||||
$this->deps->register($this->changelog = $this->deps->constructLazy(ChangelogData::class));
|
||||
$this->deps->register($this->comments = $this->deps->constructLazy(CommentsData::class));
|
||||
$this->deps->register($this->counters = $this->deps->constructLazy(CountersData::class));
|
||||
$this->deps->register($this->emotes = $this->deps->constructLazy(EmotesData::class));
|
||||
$this->deps->register($this->news = $this->deps->constructLazy(NewsData::class));
|
||||
$this->deps->register($this->profileFields = $this->deps->constructLazy(ProfileFieldsData::class));
|
||||
}
|
||||
|
||||
public function getDbQueryCount(): int {
|
||||
|
@ -156,7 +165,7 @@ class MisuzuContext {
|
|||
$purposes = $this->env->getArray($prefix);
|
||||
|
||||
$routingCtx = new BackedRoutingContext;
|
||||
$this->urls = $routingCtx->urls;
|
||||
$this->deps->register($this->urls = $routingCtx->urls);
|
||||
|
||||
if(in_array('main', $purposes)) {
|
||||
$scopedInfo = $hostInfo->scopeTo('main');
|
||||
|
@ -165,126 +174,49 @@ class MisuzuContext {
|
|||
$scopedInfo->getString('path')
|
||||
);
|
||||
|
||||
$scopedCtx->register(new \Misuzu\Home\HomeRoutes(
|
||||
$this->config,
|
||||
$this->dbConn,
|
||||
$this->siteInfo,
|
||||
$this->authInfo,
|
||||
$this->changelog,
|
||||
$this->comments,
|
||||
$this->counters,
|
||||
$this->news,
|
||||
$this->usersCtx
|
||||
$scopedCtx->register($this->deps->constructLazy(Home\HomeRoutes::class));
|
||||
$scopedCtx->register($this->deps->constructLazy(Users\Assets\AssetsRoutes::class));
|
||||
$scopedCtx->register($this->deps->constructLazy(Info\InfoRoutes::class));
|
||||
$scopedCtx->register($this->deps->constructLazy(News\NewsRoutes::class));
|
||||
$scopedCtx->register($this->deps->constructLazy(
|
||||
Messages\MessagesRoutes::class,
|
||||
config: $this->config->scopeTo('messages')
|
||||
));
|
||||
|
||||
$scopedCtx->register(new \Misuzu\Users\Assets\AssetsRoutes(
|
||||
$this->authInfo,
|
||||
$this->urls,
|
||||
$this->usersCtx
|
||||
$scopedCtx->register($this->deps->constructLazy(Forum\ForumCategoriesRoutes::class));
|
||||
$scopedCtx->register($this->deps->constructLazy(Forum\ForumTopicsRoutes::class));
|
||||
$scopedCtx->register($this->deps->constructLazy(Forum\ForumPostsRoutes::class));
|
||||
$scopedCtx->register($this->deps->constructLazy(Changelog\ChangelogRoutes::class));
|
||||
$scopedCtx->register($this->deps->constructLazy(
|
||||
SharpChat\SharpChatRoutes::class,
|
||||
config: $this->config->scopeTo('sockChat'),
|
||||
impersonateConfig: $this->config->scopeTo('impersonate')
|
||||
));
|
||||
|
||||
$scopedCtx->register(new \Misuzu\Info\InfoRoutes);
|
||||
|
||||
$scopedCtx->register(new \Misuzu\News\NewsRoutes(
|
||||
$this->siteInfo,
|
||||
$this->authInfo,
|
||||
$this->urls,
|
||||
$this->news,
|
||||
$this->usersCtx,
|
||||
$this->comments
|
||||
$scopedCtx->register($this->deps->constructLazy(
|
||||
Satori\SatoriRoutes::class,
|
||||
config: $this->config->scopeTo('satori')
|
||||
));
|
||||
|
||||
$scopedCtx->register(new \Misuzu\Messages\MessagesRoutes(
|
||||
$this->config->scopeTo('messages'),
|
||||
$this->urls,
|
||||
$this->authInfo,
|
||||
$this->messagesCtx,
|
||||
$this->usersCtx,
|
||||
$this->perms
|
||||
));
|
||||
|
||||
$scopedCtx->register(new \Misuzu\Forum\ForumCategoriesRoutes(
|
||||
$this->forumCtx,
|
||||
$this->usersCtx,
|
||||
$this->authInfo,
|
||||
));
|
||||
$scopedCtx->register(new \Misuzu\Forum\ForumTopicsRoutes(
|
||||
$this->forumCtx,
|
||||
$this->usersCtx,
|
||||
$this->auditLog,
|
||||
$this->authInfo,
|
||||
));
|
||||
$scopedCtx->register(new \Misuzu\Forum\ForumPostsRoutes(
|
||||
$this->urls,
|
||||
$this->forumCtx,
|
||||
$this->usersCtx,
|
||||
$this->auditLog,
|
||||
$this->authInfo,
|
||||
));
|
||||
|
||||
$scopedCtx->register(new \Misuzu\Changelog\ChangelogRoutes(
|
||||
$this->siteInfo,
|
||||
$this->urls,
|
||||
$this->changelog,
|
||||
$this->usersCtx,
|
||||
$this->authInfo,
|
||||
$this->comments
|
||||
));
|
||||
|
||||
$scopedCtx->register(new \Misuzu\SharpChat\SharpChatRoutes(
|
||||
$this->config->scopeTo('sockChat'),
|
||||
$this->config->scopeTo('impersonate'),
|
||||
$this->urls,
|
||||
$this->usersCtx,
|
||||
$this->authCtx,
|
||||
$this->emotes,
|
||||
$this->perms,
|
||||
$this->authInfo,
|
||||
$this->counters
|
||||
));
|
||||
|
||||
$scopedCtx->register(new \Misuzu\Satori\SatoriRoutes(
|
||||
$this->config->scopeTo('satori'),
|
||||
$this->usersCtx,
|
||||
$this->forumCtx,
|
||||
$this->profileFields
|
||||
));
|
||||
|
||||
$routingCtx->register(new LegacyRoutes($this->urls));
|
||||
$scopedCtx->register($this->deps->constructLazy(LegacyRoutes::class));
|
||||
|
||||
$rpcServer = new HttpRpcServer;
|
||||
$scopedCtx->register($rpcServer->createRouteHandler(
|
||||
new HmacVerificationProvider(fn() => $this->config->getString('aleister.secret'))
|
||||
));
|
||||
|
||||
$rpcServer->register(new Auth\AuthRpcHandler(
|
||||
$this->config->scopeTo('impersonate'),
|
||||
$this->usersCtx,
|
||||
$this->authCtx
|
||||
$rpcServer->register($this->deps->constructLazy(
|
||||
Auth\AuthRpcHandler::class,
|
||||
impersonateConfig: $this->config->scopeTo('impersonate')
|
||||
));
|
||||
$rpcServer->register($this->deps->constructLazy(Emoticons\EmotesRpcHandler::class));
|
||||
$rpcServer->register($this->deps->constructLazy(Users\UsersRpcHandler::class));
|
||||
|
||||
$rpcServer->register(new Emoticons\EmotesRpcHandler(
|
||||
$this->emotes
|
||||
));
|
||||
|
||||
$rpcServer->register(new Users\UsersRpcHandler(
|
||||
$this->siteInfo,
|
||||
$this->urls,
|
||||
$this->usersCtx
|
||||
));
|
||||
|
||||
// This RPC server will eventually despawn when Hanyuu fully owns auth
|
||||
$hanyuuRpcServer = new HttpRpcServer;
|
||||
$scopedCtx->scopeTo('', '/_hanyuu')->register($hanyuuRpcServer->createRouteHandler(
|
||||
new HmacVerificationProvider(fn() => $this->config->getString('hanyuu.secret'))
|
||||
));
|
||||
|
||||
$hanyuuRpcServer->register(new Hanyuu\HanyuuRpcHandler(
|
||||
fn() => $this->config->getString('hanyuu.endpoint'),
|
||||
$this->config->scopeTo('impersonate'),
|
||||
$this->urls,
|
||||
$this->usersCtx,
|
||||
$this->authCtx
|
||||
$hanyuuRpcServer->register($this->deps->constructLazy(
|
||||
Hanyuu\HanyuuRpcHandler::class,
|
||||
getBaseUrl: fn() => $this->config->getString('hanyuu.endpoint'),
|
||||
impersonateConfig: $this->config->scopeTo('impersonate')
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -295,14 +227,14 @@ class MisuzuContext {
|
|||
$scopedInfo->getString('path')
|
||||
);
|
||||
|
||||
$scopedCtx->register(new Redirects\LandingRedirectsRoutes);
|
||||
$scopedCtx->register(new Redirects\AliasRedirectsRoutes($this->redirectsCtx));
|
||||
$scopedCtx->register(new Redirects\IncrementalRedirectsRoutes($this->redirectsCtx));
|
||||
$scopedCtx->register(new Redirects\SocialRedirectsRoutes(
|
||||
$this->redirectsCtx,
|
||||
$this->getWebAssetInfo(...)
|
||||
$scopedCtx->register($this->deps->constructLazy(Redirects\LandingRedirectsRoutes::class));
|
||||
$scopedCtx->register($this->deps->constructLazy(Redirects\AliasRedirectsRoutes::class));
|
||||
$scopedCtx->register($this->deps->constructLazy(Redirects\IncrementalRedirectsRoutes::class));
|
||||
$scopedCtx->register($this->deps->constructLazy(
|
||||
Redirects\SocialRedirectsRoutes::class,
|
||||
getWebAssetInfo: $this->getWebAssetInfo(...)
|
||||
));
|
||||
$scopedCtx->register(new Redirects\NamedRedirectsRoutes($this->redirectsCtx));
|
||||
$scopedCtx->register($this->deps->constructLazy(Redirects\NamedRedirectsRoutes::class));
|
||||
}
|
||||
|
||||
return $routingCtx;
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
<label class="form__label">
|
||||
<div class="form__label__text">Inherit Colour</div>
|
||||
<div class="form__label__input">
|
||||
{{ input_checkbox('ur_col_inherit', '', role_ur_col_inherit is defined ? role_ur_col_inherit : (role_info is not null and role_info.hasColour ? role_info.colour.shouldInherit : true)) }}
|
||||
{{ input_checkbox('ur_col_inherit', '', role_ur_col_inherit is defined ? role_ur_col_inherit : (role_info is not null and role_info.hasColour ? role_info.colour.inherits : true)) }}
|
||||
</div>
|
||||
</label>
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@
|
|||
<label class="form__label">
|
||||
<div class="form__label__text">Custom Colour</div>
|
||||
<div class="form__label__input">
|
||||
{{ input_checkbox('colour[enable]', '', not user_info.colour.shouldInherit, '', '', false, null, not can_edit_user) }}
|
||||
{{ input_checkbox('colour[enable]', '', not user_info.colour.inherits, '', '', false, null, not can_edit_user) }}
|
||||
</div>
|
||||
</label>
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue