Use interface constants instead of a dedicate enum class for config types.

This commit is contained in:
flash 2023-01-06 20:50:41 +00:00
parent 5a7f4765ab
commit 5a4094867f
25 changed files with 95 additions and 106 deletions

View file

@ -5,7 +5,7 @@ use Index\Autoloader;
use Index\Environment; use Index\Environment;
use Index\Data\ConnectionFailedException; use Index\Data\ConnectionFailedException;
use Index\Data\DbTools; use Index\Data\DbTools;
use Misuzu\Config\CfgType; use Misuzu\Config\IConfig;
use Misuzu\Config\DbConfig; use Misuzu\Config\DbConfig;
use Misuzu\Net\IPAddress; use Misuzu\Net\IPAddress;
use Misuzu\Users\User; use Misuzu\Users\User;
@ -87,18 +87,18 @@ $cfg->reload();
Config::init($cfg); Config::init($cfg);
Mailer::init($cfg->getValue('mail.method', CfgType::T_STR), [ Mailer::init($cfg->getValue('mail.method', IConfig::T_STR), [
'host' => $cfg->getValue('mail.host', CfgType::T_STR), 'host' => $cfg->getValue('mail.host', IConfig::T_STR),
'port' => $cfg->getValue('mail.port', CfgType::T_INT, 25), 'port' => $cfg->getValue('mail.port', IConfig::T_INT, 25),
'username' => $cfg->getValue('mail.username', CfgType::T_STR), 'username' => $cfg->getValue('mail.username', IConfig::T_STR),
'password' => $cfg->getValue('mail.password', CfgType::T_STR), 'password' => $cfg->getValue('mail.password', IConfig::T_STR),
'encryption' => $cfg->getValue('mail.encryption', CfgType::T_STR), 'encryption' => $cfg->getValue('mail.encryption', IConfig::T_STR),
'sender_name' => $cfg->getValue('mail.sender.name', CfgType::T_STR), 'sender_name' => $cfg->getValue('mail.sender.name', IConfig::T_STR),
'sender_addr' => $cfg->getValue('mail.sender.address', CfgType::T_STR), 'sender_addr' => $cfg->getValue('mail.sender.address', IConfig::T_STR),
]); ]);
// replace this with a better storage mechanism // replace this with a better storage mechanism
define('MSZ_STORAGE', $cfg->getValue('storage.path', CfgType::T_STR, MSZ_ROOT . '/store')); define('MSZ_STORAGE', $cfg->getValue('storage.path', IConfig::T_STR, MSZ_ROOT . '/store'));
if(!is_dir(MSZ_STORAGE)) if(!is_dir(MSZ_STORAGE))
mkdir(MSZ_STORAGE, 0775, true); mkdir(MSZ_STORAGE, 0775, true);
@ -148,10 +148,10 @@ if(!MSZ_DEBUG) {
Template::init($msz, $twigCache ?? null, MSZ_DEBUG); Template::init($msz, $twigCache ?? null, MSZ_DEBUG);
Template::set('globals', [ Template::set('globals', [
'site_name' => $cfg->getValue('site.name', CfgType::T_STR, 'Misuzu'), 'site_name' => $cfg->getValue('site.name', IConfig::T_STR, 'Misuzu'),
'site_description' => $cfg->getValue('site.desc', CfgType::T_STR), 'site_description' => $cfg->getValue('site.desc', IConfig::T_STR),
'site_url' => $cfg->getValue('site.url', CfgType::T_STR), 'site_url' => $cfg->getValue('site.url', IConfig::T_STR),
'site_twitter' => $cfg->getValue('social.twitter', CfgType::T_STR), 'site_twitter' => $cfg->getValue('social.twitter', IConfig::T_STR),
]); ]);
Template::addPath(MSZ_TEMPLATES); Template::addPath(MSZ_TEMPLATES);
@ -203,7 +203,7 @@ if($authToken->isValid()) {
} }
} }
CSRF::setGlobalSecretKey($cfg->getValue('csrf.secret', CfgType::T_STR, 'soup')); CSRF::setGlobalSecretKey($cfg->getValue('csrf.secret', IConfig::T_STR, 'soup'));
CSRF::setGlobalIdentity( CSRF::setGlobalIdentity(
UserSession::hasCurrent() UserSession::hasCurrent()
? UserSession::getCurrent()->getToken() ? UserSession::getCurrent()->getToken()
@ -213,15 +213,15 @@ CSRF::setGlobalIdentity(
function mszLockdown(): void { function mszLockdown(): void {
global $misuzuBypassLockdown, $cfg; global $misuzuBypassLockdown, $cfg;
if($cfg->getValue('private.enabled', CfgType::T_BOOL)) { if($cfg->getValue('private.enabled', IConfig::T_BOOL)) {
$onLoginPage = $_SERVER['PHP_SELF'] === url('auth-login'); $onLoginPage = $_SERVER['PHP_SELF'] === url('auth-login');
$onPasswordPage = parse_url($_SERVER['PHP_SELF'], PHP_URL_PATH) === url('auth-forgot'); $onPasswordPage = parse_url($_SERVER['PHP_SELF'], PHP_URL_PATH) === url('auth-forgot');
$misuzuBypassLockdown = !empty($misuzuBypassLockdown) || $onLoginPage; $misuzuBypassLockdown = !empty($misuzuBypassLockdown) || $onLoginPage;
if(!$misuzuBypassLockdown) { if(!$misuzuBypassLockdown) {
if(UserSession::hasCurrent()) { if(UserSession::hasCurrent()) {
$privatePermCat = $cfg->getValue('private.perm.cat', CfgType::T_STR); $privatePermCat = $cfg->getValue('private.perm.cat', IConfig::T_STR);
$privatePermVal = $cfg->getValue('private.perm.val', CfgType::T_INT); $privatePermVal = $cfg->getValue('private.perm.val', IConfig::T_INT);
if(!empty($privatePermCat) && $privatePermVal > 0) { if(!empty($privatePermCat) && $privatePermVal > 0) {
if(!perms_check_user($privatePermCat, User::getCurrent()->getId(), $privatePermVal)) { if(!perms_check_user($privatePermCat, User::getCurrent()->getId(), $privatePermVal)) {
@ -230,7 +230,7 @@ function mszLockdown(): void {
User::unsetCurrent(); User::unsetCurrent();
} }
} }
} elseif(!$onLoginPage && !($onPasswordPage && $cfg->getValue('private.allow_password_reset', CfgType::T_BOOL, true))) { } elseif(!$onLoginPage && !($onPasswordPage && $cfg->getValue('private.allow_password_reset', IConfig::T_BOOL, true))) {
url_redirect('auth-login'); url_redirect('auth-login');
exit; exit;
} }

View file

@ -2,7 +2,7 @@
namespace Misuzu; namespace Misuzu;
use Misuzu\AuthToken; use Misuzu\AuthToken;
use Misuzu\Config\CfgType; use Misuzu\Config\IConfig;
use Misuzu\Users\User; use Misuzu\Users\User;
use Misuzu\Users\UserNotFoundException; use Misuzu\Users\UserNotFoundException;
use Misuzu\Users\UserAuthSession; use Misuzu\Users\UserAuthSession;
@ -42,9 +42,9 @@ if(!empty($_GET['resolve'])) {
$notices = []; $notices = [];
$ipAddress = $_SERVER['REMOTE_ADDR']; $ipAddress = $_SERVER['REMOTE_ADDR'];
$siteIsPrivate = $cfg->getValue('private.enable', CfgType::T_BOOL); $siteIsPrivate = $cfg->getValue('private.enable', IConfig::T_BOOL);
$loginPermCat = $siteIsPrivate ? $cfg->getValue('private.perm.cat', CfgType::T_STR) : ''; $loginPermCat = $siteIsPrivate ? $cfg->getValue('private.perm.cat', IConfig::T_STR) : '';
$loginPermVal = $siteIsPrivate ? $cfg->getValue('private.perm.val', CfgType::T_INT) : 0; $loginPermVal = $siteIsPrivate ? $cfg->getValue('private.perm.val', IConfig::T_INT) : 0;
$remainingAttempts = UserLoginAttempt::remaining($ipAddress); $remainingAttempts = UserLoginAttempt::remaining($ipAddress);
while(!empty($_POST['login']) && is_array($_POST['login'])) { while(!empty($_POST['login']) && is_array($_POST['login'])) {
@ -133,8 +133,8 @@ $loginUsername = !empty($_POST['login']['username']) && is_string($_POST['login'
!empty($_GET['username']) && is_string($_GET['username']) ? $_GET['username'] : '' !empty($_GET['username']) && is_string($_GET['username']) ? $_GET['username'] : ''
); );
$loginRedirect = $welcomeMode ? url('index') : (!empty($_GET['redirect']) && is_string($_GET['redirect']) ? $_GET['redirect'] : null) ?? $_SERVER['HTTP_REFERER'] ?? url('index'); $loginRedirect = $welcomeMode ? url('index') : (!empty($_GET['redirect']) && is_string($_GET['redirect']) ? $_GET['redirect'] : null) ?? $_SERVER['HTTP_REFERER'] ?? url('index');
$sitePrivateMessage = $siteIsPrivate ? $cfg->getValue('private.msg', CfgType::T_STR) : ''; $sitePrivateMessage = $siteIsPrivate ? $cfg->getValue('private.msg', IConfig::T_STR) : '';
$canResetPassword = $siteIsPrivate ? $cfg->getValue('private.allow_password_reset', CfgType::T_BOOL, true) : true; $canResetPassword = $siteIsPrivate ? $cfg->getValue('private.allow_password_reset', IConfig::T_BOOL, true) : true;
$canRegisterAccount = !$siteIsPrivate; $canRegisterAccount = !$siteIsPrivate;
Template::render('auth.login', [ Template::render('auth.login', [

View file

@ -2,7 +2,7 @@
namespace Misuzu; namespace Misuzu;
use Misuzu\AuditLog; use Misuzu\AuditLog;
use Misuzu\Config\CfgType; IConfiguse Misuzu\Config\IConfig;
use Misuzu\Users\User; use Misuzu\Users\User;
use Misuzu\Users\UserNotFoundException; use Misuzu\Users\UserNotFoundException;
use Misuzu\Users\UserLoginAttempt; use Misuzu\Users\UserLoginAttempt;
@ -34,8 +34,8 @@ if($userId > 0)
$notices = []; $notices = [];
$ipAddress = $_SERVER['REMOTE_ADDR']; $ipAddress = $_SERVER['REMOTE_ADDR'];
$siteIsPrivate = $cfg->getValue('private.enable', CfgType::T_BOOL); $siteIsPrivate = $cfg->getValue('private.enable', IConfig::T_BOOL);
$canResetPassword = $siteIsPrivate ? $cfg->getValue('private.allow_password_reset', CfgType::T_BOOL, true) : true; $canResetPassword = $siteIsPrivate ? $cfg->getValue('private.allow_password_reset', IConfig::T_BOOL, true) : true;
$remainingAttempts = UserLoginAttempt::remaining($ipAddress); $remainingAttempts = UserLoginAttempt::remaining($ipAddress);
while($canResetPassword) { while($canResetPassword) {

View file

@ -1,7 +1,7 @@
<?php <?php
namespace Misuzu; namespace Misuzu;
use Misuzu\Config\CfgType; use Misuzu\Config\IConfig;
use Misuzu\Users\User; use Misuzu\Users\User;
require_once '../../misuzu.php'; require_once '../../misuzu.php';
@ -21,8 +21,8 @@ $leaderboardIdLength = strlen($leaderboardId);
$leaderboardYear = $leaderboardIdLength === 4 || $leaderboardIdLength === 6 ? substr($leaderboardId, 0, 4) : null; $leaderboardYear = $leaderboardIdLength === 4 || $leaderboardIdLength === 6 ? substr($leaderboardId, 0, 4) : null;
$leaderboardMonth = $leaderboardIdLength === 6 ? substr($leaderboardId, 4, 2) : null; $leaderboardMonth = $leaderboardIdLength === 6 ? substr($leaderboardId, 4, 2) : null;
$unrankedForums = !empty($_GET['allow_unranked']) ? [] : $cfg->getValue('forum_leader.unranked.forum', CfgType::T_ARR); $unrankedForums = !empty($_GET['allow_unranked']) ? [] : $cfg->getValue('forum_leader.unranked.forum', IConfig::T_ARR);
$unrankedTopics = !empty($_GET['allow_unranked']) ? [] : $cfg->getValue('forum_leader.unranked.topic', CfgType::T_ARR); $unrankedTopics = !empty($_GET['allow_unranked']) ? [] : $cfg->getValue('forum_leader.unranked.topic', IConfig::T_ARR);
$leaderboards = forum_leaderboard_categories(); $leaderboards = forum_leaderboard_categories();
$leaderboard = forum_leaderboard_listing($leaderboardYear, $leaderboardMonth, $unrankedForums, $unrankedTopics); $leaderboard = forum_leaderboard_listing($leaderboardYear, $leaderboardMonth, $unrankedForums, $unrankedTopics);

View file

@ -3,7 +3,7 @@ namespace Misuzu;
use Misuzu\Config; use Misuzu\Config;
use Misuzu\Config\CfgTools; use Misuzu\Config\CfgTools;
use Misuzu\Config\CfgType; use Misuzu\Config\IConfig;
use Misuzu\Users\User; use Misuzu\Users\User;
require_once '../../../misuzu.php'; require_once '../../../misuzu.php';
@ -106,7 +106,7 @@ if($cfg->hasValue($sName)) {
$sValue = $cfg->getValue($sName); $sValue = $cfg->getValue($sName);
$sVar['type'] = $sType = CfgTools::type($sValue); $sVar['type'] = $sType = CfgTools::type($sValue);
if($sType === CfgType::T_ARR) if($sType === IConfig::T_ARR)
foreach($sValue as $fk => $fv) foreach($sValue as $fk => $fv)
$sValue[$fk] = ['integer' => 'i', 'string' => 's', 'boolean' => 'b'][gettype($fv)] . ':' . $fv; $sValue[$fk] = ['integer' => 'i', 'string' => 's', 'boolean' => 'b'][gettype($fv)] . ':' . $fv;

View file

@ -3,7 +3,7 @@ namespace Misuzu;
use Misuzu\Config; use Misuzu\Config;
use Misuzu\Config\CfgTools; use Misuzu\Config\CfgTools;
use Misuzu\Config\CfgType; use Misuzu\Config\IConfig;
use Misuzu\Users\User; use Misuzu\Users\User;
require_once '../../../misuzu.php'; require_once '../../../misuzu.php';
@ -14,7 +14,7 @@ if(!User::hasCurrent()
return; return;
} }
$hidden = $cfg->getValue('settings.hidden', CfgType::T_ARR, []); $hidden = $cfg->getValue('settings.hidden', IConfig::T_ARR, []);
$vars = []; $vars = [];
foreach($cfg->getNames() as $key) { foreach($cfg->getNames() as $key) {

View file

@ -1,7 +1,6 @@
<?php <?php
namespace Misuzu; namespace Misuzu;
use Misuzu\Config\CfgType;
use Misuzu\Users\User; use Misuzu\Users\User;
use Misuzu\Twitter\TwitterAccessToken; use Misuzu\Twitter\TwitterAccessToken;
use Misuzu\Twitter\TwitterClient; use Misuzu\Twitter\TwitterClient;

View file

@ -2,7 +2,6 @@
namespace Misuzu; namespace Misuzu;
use Misuzu\AuditLog; use Misuzu\AuditLog;
use Misuzu\Config\CfgType;
use Misuzu\News\NewsCategory; use Misuzu\News\NewsCategory;
use Misuzu\News\NewsPost; use Misuzu\News\NewsPost;
use Misuzu\News\NewsPostNotFoundException; use Misuzu\News\NewsPostNotFoundException;

View file

@ -3,7 +3,7 @@ namespace Misuzu;
use Misuzu\AuditLog; use Misuzu\AuditLog;
use Misuzu\Config; use Misuzu\Config;
use Misuzu\Config\CfgType; use Misuzu\Config\IConfig;
use Misuzu\Users\User; use Misuzu\Users\User;
use Misuzu\Users\UserRole; use Misuzu\Users\UserRole;
use Misuzu\Users\UserRoleNotFoundException; use Misuzu\Users\UserRoleNotFoundException;
@ -50,7 +50,7 @@ if(!$isRestricted && $isVerifiedRequest && !empty($_POST['role'])) {
if($isVerifiedRequest && isset($_POST['tfa']['enable']) && $currentUser->hasTOTP() !== (bool)$_POST['tfa']['enable']) { if($isVerifiedRequest && isset($_POST['tfa']['enable']) && $currentUser->hasTOTP() !== (bool)$_POST['tfa']['enable']) {
if((bool)$_POST['tfa']['enable']) { if((bool)$_POST['tfa']['enable']) {
$tfaKey = TOTP::generateKey(); $tfaKey = TOTP::generateKey();
$tfaIssuer = $cfg->getValue('site.name', CfgType::T_STR, 'Misuzu'); $tfaIssuer = $cfg->getValue('site.name', IConfig::T_STR, 'Misuzu');
$tfaQrcode = (new QRCode(new QROptions([ $tfaQrcode = (new QRCode(new QROptions([
'version' => 5, 'version' => 5,
'outputType' => QRCode::OUTPUT_IMAGE_JPG, 'outputType' => QRCode::OUTPUT_IMAGE_JPG,

View file

@ -2,7 +2,6 @@
namespace Misuzu; namespace Misuzu;
use Misuzu\Config\IConfig; use Misuzu\Config\IConfig;
use Misuzu\Config\CfgType;
final class Config { final class Config {
private static IConfig $config; private static IConfig $config;
@ -15,7 +14,7 @@ final class Config {
return self::$config->getNames(); return self::$config->getNames();
} }
public static function get(string $key, string $type = CfgType::T_ANY, $default = null): mixed { public static function get(string $key, string $type = IConfig::T_ANY, $default = null): mixed {
return self::$config->getValue($key, $type, $default); return self::$config->getValue($key, $type, $default);
} }

View file

@ -7,10 +7,10 @@ final class CfgTools {
} }
public static function isValidType(string $type): bool { public static function isValidType(string $type): bool {
return $type === CfgType::T_ARR return $type === IConfig::T_ARR
|| $type === CfgType::T_BOOL || $type === IConfig::T_BOOL
|| $type === CfgType::T_INT || $type === IConfig::T_INT
|| $type === CfgType::T_STR; || $type === IConfig::T_STR;
} }
public static function validateName(string $name): bool { public static function validateName(string $name): bool {
@ -19,11 +19,11 @@ final class CfgTools {
} }
private const DEFAULTS = [ private const DEFAULTS = [
CfgType::T_ANY => null, IConfig::T_ANY => null,
CfgType::T_STR => '', IConfig::T_STR => '',
CfgType::T_INT => 0, IConfig::T_INT => 0,
CfgType::T_BOOL => false, IConfig::T_BOOL => false,
CfgType::T_ARR => [], IConfig::T_ARR => [],
]; ];
public static function default(string $type) { public static function default(string $type) {

View file

@ -1,10 +0,0 @@
<?php
namespace Misuzu\Config;
final class CfgType {
public const T_ANY = '';
public const T_STR = 'string';
public const T_INT = 'integer';
public const T_BOOL = 'boolean';
public const T_ARR = 'array';
}

View file

@ -34,10 +34,10 @@ class DbConfig implements IConfig {
return array_keys($this->values); return array_keys($this->values);
} }
public function getValue(string $name, string $type = CfgType::T_ANY, $default = null): mixed { public function getValue(string $name, string $type = IConfig::T_ANY, $default = null): mixed {
$value = $this->values[$name] ?? null; $value = $this->values[$name] ?? null;
if($type !== CfgType::T_ANY && CfgTools::type($value) !== $type) if($type !== IConfig::T_ANY && CfgTools::type($value) !== $type)
$value = null; $value = null;
return $value ?? $default ?? CfgTools::default($type); return $value ?? $default ?? CfgTools::default($type);

View file

@ -8,10 +8,16 @@ namespace Misuzu\Config;
// bulk operations for setValue and removeValue would also be cool // bulk operations for setValue and removeValue would also be cool
interface IConfig { interface IConfig {
function scopeTo(string $prefix): IConfig; public const T_ANY = '';
function getNames(): array; public const T_STR = 'string';
function getValue(string $name, string $type = CfgType::T_ANY, $default = null): mixed; public const T_INT = 'integer';
function hasValue(string $name): bool; public const T_BOOL = 'boolean';
function setValue(string $name, $value, bool $save = true): void; public const T_ARR = 'array';
function removeValue(string $name, bool $save = true): void;
public function scopeTo(string $prefix): IConfig;
public function getNames(): array;
public function getValue(string $name, string $type = IConfig::T_ANY, $default = null): mixed;
public function hasValue(string $name): bool;
public function setValue(string $name, $value, bool $save = true): void;
public function removeValue(string $name, bool $save = true): void;
} }

View file

@ -40,7 +40,7 @@ class ScopedConfig implements IConfig {
return $filter; return $filter;
} }
public function getValue(string $name, string $type = CfgType::T_ANY, $default = null): mixed { public function getValue(string $name, string $type = IConfig::T_ANY, $default = null): mixed {
return $this->config->getValue($this->getName($name), $type, $default); return $this->config->getValue($this->getName($name), $type, $default);
} }

View file

@ -10,7 +10,6 @@ use GeoIp2\Model\Asn;
use GeoIp2\Model\City; use GeoIp2\Model\City;
use GeoIp2\Model\Country; use GeoIp2\Model\Country;
use Misuzu\Config\IConfig; use Misuzu\Config\IConfig;
use Misuzu\Config\CfgType;
class GeoIPHelper { class GeoIPHelper {
public const ASN = 'asn'; public const ASN = 'asn';
@ -34,7 +33,7 @@ class GeoIPHelper {
$type = 'db.' . $type; $type = 'db.' . $type;
if(!$this->config->hasValue($type)) if(!$this->config->hasValue($type))
throw new RuntimeException('Not database path has been configured for $type.'); throw new RuntimeException('Not database path has been configured for $type.');
return $this->config->getValue($type, CfgType::T_STR); return $this->config->getValue($type, IConfig::T_STR);
} }
public function getReader(string $type): Reader { public function getReader(string $type): Reader {

View file

@ -3,7 +3,7 @@ namespace Misuzu\Http\Handlers;
use ErrorException; use ErrorException;
use Misuzu\Config; use Misuzu\Config;
use Misuzu\Config\CfgType; use Misuzu\Config\IConfig;
use Misuzu\Pagination; use Misuzu\Pagination;
use Misuzu\Template; use Misuzu\Template;
use Misuzu\Changelog\ChangelogChange; use Misuzu\Changelog\ChangelogChange;
@ -84,8 +84,8 @@ class ChangelogHandler extends Handler {
$changes = ChangelogChange::all(new Pagination(10)); $changes = ChangelogChange::all(new Pagination(10));
$feed = (new Feed) $feed = (new Feed)
->setTitle(Config::get('site.name', CfgType::T_STR, 'Misuzu') . ' » Changelog') ->setTitle(Config::get('site.name', IConfig::T_STR, 'Misuzu') . ' » Changelog')
->setDescription('Live feed of changes to ' . Config::get('site.name', CfgType::T_STR, 'Misuzu') . '.') ->setDescription('Live feed of changes to ' . Config::get('site.name', IConfig::T_STR, 'Misuzu') . '.')
->setContentUrl(url_prefix(false) . url('changelog-index')) ->setContentUrl(url_prefix(false) . url('changelog-index'))
->setFeedUrl(url_prefix(false) . url("changelog-feed-{$feedMode}")); ->setFeedUrl(url_prefix(false) . url("changelog-feed-{$feedMode}"));

View file

@ -2,7 +2,7 @@
namespace Misuzu\Http\Handlers; namespace Misuzu\Http\Handlers;
use Misuzu\Config; use Misuzu\Config;
use Misuzu\Config\CfgType; use Misuzu\Config\IConfig;
use Misuzu\DB; use Misuzu\DB;
use Misuzu\Pagination; use Misuzu\Pagination;
use Misuzu\Template; use Misuzu\Template;
@ -20,12 +20,12 @@ final class HomeHandler extends Handler {
} }
public function landing($response, $request): void { public function landing($response, $request): void {
$linkedData = Config::get('social.embed_linked', CfgType::T_BOOL) $linkedData = Config::get('social.embed_linked', IConfig::T_BOOL)
? [ ? [
'name' => Config::get('site.name', CfgType::T_STR, 'Misuzu'), 'name' => Config::get('site.name', IConfig::T_STR, 'Misuzu'),
'url' => Config::get('site.url', CfgType::T_STR), 'url' => Config::get('site.url', IConfig::T_STR),
'logo' => Config::get('site.ext_logo', CfgType::T_STR), 'logo' => Config::get('site.ext_logo', IConfig::T_STR),
'same_as' => Config::get('social.linked', CfgType::T_ARR), 'same_as' => Config::get('social.linked', IConfig::T_ARR),
] : null; ] : null;
@ -52,7 +52,7 @@ final class HomeHandler extends Handler {
)->fetchAll(); )->fetchAll();
// TODO: don't hardcode forum ids // TODO: don't hardcode forum ids
$featuredForums = Config::get('landing.forum_categories', CfgType::T_ARR); $featuredForums = Config::get('landing.forum_categories', IConfig::T_ARR);
$popularTopics = []; $popularTopics = [];
$activeTopics = []; $activeTopics = [];

View file

@ -2,7 +2,7 @@
namespace Misuzu\Http\Handlers; namespace Misuzu\Http\Handlers;
use Misuzu\Config; use Misuzu\Config;
use Misuzu\Config\CfgType; use Misuzu\Config\IConfig;
use Misuzu\DB; use Misuzu\DB;
use Misuzu\Pagination; use Misuzu\Pagination;
use Misuzu\Template; use Misuzu\Template;
@ -86,7 +86,7 @@ final class NewsHandler extends Handler {
$posts = $hasCategory ? $categoryInfo->posts($pagination) : NewsPost::all($pagination, true); $posts = $hasCategory ? $categoryInfo->posts($pagination) : NewsPost::all($pagination, true);
$feed = (new Feed) $feed = (new Feed)
->setTitle(Config::get('site.name', CfgType::T_STR, 'Misuzu') . ' » ' . ($hasCategory ? $categoryInfo->getName() : 'Featured News')) ->setTitle(Config::get('site.name', IConfig::T_STR, 'Misuzu') . ' » ' . ($hasCategory ? $categoryInfo->getName() : 'Featured News'))
->setDescription($hasCategory ? $categoryInfo->getDescription() : 'A live featured news feed.') ->setDescription($hasCategory ? $categoryInfo->getDescription() : 'A live featured news feed.')
->setContentUrl(url_prefix(false) . ($hasCategory ? url('news-category', ['category' => $categoryInfo->getId()]) : url('news-index'))) ->setContentUrl(url_prefix(false) . ($hasCategory ? url('news-category', ['category' => $categoryInfo->getId()]) : url('news-index')))
->setFeedUrl(url_prefix(false) . ($hasCategory ? url("news-category-feed-{$feedMode}", ['category' => $categoryInfo->getId()]) : url("news-feed-{$feedMode}"))); ->setFeedUrl(url_prefix(false) . ($hasCategory ? url("news-category-feed-{$feedMode}", ['category' => $categoryInfo->getId()]) : url("news-feed-{$feedMode}")));

View file

@ -4,7 +4,6 @@ namespace Misuzu\SharpChat;
use Index\Colour\Colour; use Index\Colour\Colour;
use Index\Routing\IRouter; use Index\Routing\IRouter;
use Misuzu\Config\IConfig; use Misuzu\Config\IConfig;
use Misuzu\Config\CfgType;
// Replace // Replace
use Misuzu\AuthToken; use Misuzu\AuthToken;
@ -22,10 +21,10 @@ final class SharpChatRoutes {
public function __construct(IRouter $router, IConfig $config) { public function __construct(IRouter $router, IConfig $config) {
$this->config = $config; $this->config = $config;
$hashKey = $this->config->getValue('hashKey', CfgType::T_STR, ''); $hashKey = $this->config->getValue('hashKey', IConfig::T_STR, '');
if(empty($hashKey)) { if(empty($hashKey)) {
$hashKeyPath = $this->config->getValue('hashKeyPath', CfgType::T_STR, ''); $hashKeyPath = $this->config->getValue('hashKeyPath', IConfig::T_STR, '');
if(is_file($hashKeyPath)) if(is_file($hashKeyPath))
$this->hashKey = file_get_contents($hashKeyPath); $this->hashKey = file_get_contents($hashKeyPath);
} else { } else {
@ -74,7 +73,7 @@ final class SharpChatRoutes {
public function login($response, $request): void { public function login($response, $request): void {
$currentUser = User::getCurrent(); $currentUser = User::getCurrent();
$configKey = $request->hasParam('legacy') ? 'chatPath.legacy' : 'chatPath.normal'; $configKey = $request->hasParam('legacy') ? 'chatPath.legacy' : 'chatPath.normal';
$chatPath = $this->config->getValue($configKey, CfgType::T_STR, '/'); $chatPath = $this->config->getValue($configKey, IConfig::T_STR, '/');
$response->redirect( $response->redirect(
$currentUser === null $currentUser === null
@ -89,7 +88,7 @@ final class SharpChatRoutes {
$originHost = strtolower(parse_url($origin, PHP_URL_HOST) ?? ''); $originHost = strtolower(parse_url($origin, PHP_URL_HOST) ?? '');
if(!empty($originHost) && $originHost !== $host) { if(!empty($originHost) && $originHost !== $host) {
$whitelist = $this->config->getValue('origins', CfgType::T_ARR, []); $whitelist = $this->config->getValue('origins', IConfig::T_ARR, []);
if(!in_array($originHost, $whitelist)) if(!in_array($originHost, $whitelist))
return 403; return 403;

View file

@ -3,7 +3,6 @@ namespace Misuzu\Twitter;
use Stringable; use Stringable;
use Misuzu\Config\IConfig; use Misuzu\Config\IConfig;
use Misuzu\Config\CfgType;
class TwitterAccessToken implements Stringable { class TwitterAccessToken implements Stringable {
public function __construct( public function __construct(
@ -66,11 +65,11 @@ class TwitterAccessToken implements Stringable {
public static function load(IConfig $config): self { public static function load(IConfig $config): self {
return new static( return new static(
$config->getValue('type', CfgType::T_STR), $config->getValue('type', IConfig::T_STR),
$config->getValue('token', CfgType::T_STR), $config->getValue('token', IConfig::T_STR),
$config->getValue('expires', CfgType::T_INT), $config->getValue('expires', IConfig::T_INT),
$config->getValue('token', CfgType::T_ARR), $config->getValue('token', IConfig::T_ARR),
$config->getValue('refresh', CfgType::T_STR) $config->getValue('refresh', IConfig::T_STR)
); );
} }

View file

@ -3,7 +3,6 @@ namespace Misuzu\Twitter;
use Stringable; use Stringable;
use Misuzu\Config\IConfig; use Misuzu\Config\IConfig;
use Misuzu\Config\CfgType;
class TwitterClientId implements Stringable { class TwitterClientId implements Stringable {
public function __construct( public function __construct(
@ -29,8 +28,8 @@ class TwitterClientId implements Stringable {
public static function load(IConfig $config): self { public static function load(IConfig $config): self {
return new static( return new static(
$config->getValue('clientId', CfgType::T_STR), $config->getValue('clientId', IConfig::T_STR),
$config->getValue('clientSecret', CfgType::T_STR) $config->getValue('clientSecret', IConfig::T_STR)
); );
} }
} }

View file

@ -2,7 +2,7 @@
namespace Misuzu\Users\Assets; namespace Misuzu\Users\Assets;
use Misuzu\Config; use Misuzu\Config;
use Misuzu\Config\CfgType; use Misuzu\Config\IConfig;
use Misuzu\Imaging\Image; use Misuzu\Imaging\Image;
use Misuzu\Users\User; use Misuzu\Users\User;
@ -20,13 +20,13 @@ class UserAvatarAsset extends UserImageAsset implements UserAssetScalableInterfa
private const MAX_BYTES = 1048576; private const MAX_BYTES = 1048576;
public function getMaxWidth(): int { public function getMaxWidth(): int {
return Config::get('avatar.max_res', CfgType::T_INT, self::MAX_RES); return Config::get('avatar.max_res', IConfig::T_INT, self::MAX_RES);
} }
public function getMaxHeight(): int { public function getMaxHeight(): int {
return $this->getMaxWidth(); return $this->getMaxWidth();
} }
public function getMaxBytes(): int { public function getMaxBytes(): int {
return Config::get('avatar.max_size', CfgType::T_INT, self::MAX_BYTES); return Config::get('avatar.max_size', IConfig::T_INT, self::MAX_BYTES);
} }
public function getUrl(): string { public function getUrl(): string {

View file

@ -3,7 +3,7 @@ namespace Misuzu\Users\Assets;
use InvalidArgumentException; use InvalidArgumentException;
use Misuzu\Config; use Misuzu\Config;
use Misuzu\Config\CfgType; use Misuzu\Config\IConfig;
use Misuzu\Users\User; use Misuzu\Users\User;
// attachment and attributes are to be stored in the same byte // attachment and attributes are to be stored in the same byte
@ -49,13 +49,13 @@ class UserBackgroundAsset extends UserImageAsset {
} }
public function getMaxWidth(): int { public function getMaxWidth(): int {
return Config::get('background.max_width', CfgType::T_INT, self::MAX_WIDTH); return Config::get('background.max_width', IConfig::T_INT, self::MAX_WIDTH);
} }
public function getMaxHeight(): int { public function getMaxHeight(): int {
return Config::get('background.max_height', CfgType::T_INT, self::MAX_HEIGHT); return Config::get('background.max_height', IConfig::T_INT, self::MAX_HEIGHT);
} }
public function getMaxBytes(): int { public function getMaxBytes(): int {
return Config::get('background.max_size', CfgType::T_INT, self::MAX_BYTES); return Config::get('background.max_size', IConfig::T_INT, self::MAX_BYTES);
} }
public function getUrl(): string { public function getUrl(): string {

View file

@ -3,7 +3,7 @@ namespace Misuzu\Users\Assets;
use JsonSerializable; use JsonSerializable;
use Misuzu\Config; use Misuzu\Config;
use Misuzu\Config\CfgType; use Misuzu\Config\IConfig;
use Misuzu\Users\User; use Misuzu\Users\User;
class UserImageAssetFileCreationFailedException extends UserAssetException {} class UserImageAssetFileCreationFailedException extends UserAssetException {}
@ -84,7 +84,7 @@ abstract class UserImageAsset implements JsonSerializable, UserImageAssetInterfa
} }
public function getStoragePath(): string { public function getStoragePath(): string {
return Config::get('storage.path', CfgType::T_STR, MSZ_ROOT . DIRECTORY_SEPARATOR . 'store'); return Config::get('storage.path', IConfig::T_STR, MSZ_ROOT . DIRECTORY_SEPARATOR . 'store');
} }
public function getPath(): string { public function getPath(): string {