diff --git a/misuzu.php b/misuzu.php index e560aa5..265984c 100644 --- a/misuzu.php +++ b/misuzu.php @@ -5,7 +5,7 @@ use Index\Autoloader; use Index\Environment; use Index\Data\ConnectionFailedException; use Index\Data\DbTools; -use Misuzu\Config\CfgType; +use Misuzu\Config\IConfig; use Misuzu\Config\DbConfig; use Misuzu\Net\IPAddress; use Misuzu\Users\User; @@ -87,18 +87,18 @@ $cfg->reload(); Config::init($cfg); -Mailer::init($cfg->getValue('mail.method', CfgType::T_STR), [ - 'host' => $cfg->getValue('mail.host', CfgType::T_STR), - 'port' => $cfg->getValue('mail.port', CfgType::T_INT, 25), - 'username' => $cfg->getValue('mail.username', CfgType::T_STR), - 'password' => $cfg->getValue('mail.password', CfgType::T_STR), - 'encryption' => $cfg->getValue('mail.encryption', CfgType::T_STR), - 'sender_name' => $cfg->getValue('mail.sender.name', CfgType::T_STR), - 'sender_addr' => $cfg->getValue('mail.sender.address', CfgType::T_STR), +Mailer::init($cfg->getValue('mail.method', IConfig::T_STR), [ + 'host' => $cfg->getValue('mail.host', IConfig::T_STR), + 'port' => $cfg->getValue('mail.port', IConfig::T_INT, 25), + 'username' => $cfg->getValue('mail.username', IConfig::T_STR), + 'password' => $cfg->getValue('mail.password', IConfig::T_STR), + 'encryption' => $cfg->getValue('mail.encryption', IConfig::T_STR), + 'sender_name' => $cfg->getValue('mail.sender.name', IConfig::T_STR), + 'sender_addr' => $cfg->getValue('mail.sender.address', IConfig::T_STR), ]); // 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)) mkdir(MSZ_STORAGE, 0775, true); @@ -148,10 +148,10 @@ if(!MSZ_DEBUG) { Template::init($msz, $twigCache ?? null, MSZ_DEBUG); Template::set('globals', [ - 'site_name' => $cfg->getValue('site.name', CfgType::T_STR, 'Misuzu'), - 'site_description' => $cfg->getValue('site.desc', CfgType::T_STR), - 'site_url' => $cfg->getValue('site.url', CfgType::T_STR), - 'site_twitter' => $cfg->getValue('social.twitter', CfgType::T_STR), + 'site_name' => $cfg->getValue('site.name', IConfig::T_STR, 'Misuzu'), + 'site_description' => $cfg->getValue('site.desc', IConfig::T_STR), + 'site_url' => $cfg->getValue('site.url', IConfig::T_STR), + 'site_twitter' => $cfg->getValue('social.twitter', IConfig::T_STR), ]); 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( UserSession::hasCurrent() ? UserSession::getCurrent()->getToken() @@ -213,15 +213,15 @@ CSRF::setGlobalIdentity( function mszLockdown(): void { 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'); $onPasswordPage = parse_url($_SERVER['PHP_SELF'], PHP_URL_PATH) === url('auth-forgot'); $misuzuBypassLockdown = !empty($misuzuBypassLockdown) || $onLoginPage; if(!$misuzuBypassLockdown) { if(UserSession::hasCurrent()) { - $privatePermCat = $cfg->getValue('private.perm.cat', CfgType::T_STR); - $privatePermVal = $cfg->getValue('private.perm.val', CfgType::T_INT); + $privatePermCat = $cfg->getValue('private.perm.cat', IConfig::T_STR); + $privatePermVal = $cfg->getValue('private.perm.val', IConfig::T_INT); if(!empty($privatePermCat) && $privatePermVal > 0) { if(!perms_check_user($privatePermCat, User::getCurrent()->getId(), $privatePermVal)) { @@ -230,7 +230,7 @@ function mszLockdown(): void { 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'); exit; } diff --git a/public/auth/login.php b/public/auth/login.php index 9160e61..e7e84c1 100644 --- a/public/auth/login.php +++ b/public/auth/login.php @@ -2,7 +2,7 @@ namespace Misuzu; use Misuzu\AuthToken; -use Misuzu\Config\CfgType; +use Misuzu\Config\IConfig; use Misuzu\Users\User; use Misuzu\Users\UserNotFoundException; use Misuzu\Users\UserAuthSession; @@ -42,9 +42,9 @@ if(!empty($_GET['resolve'])) { $notices = []; $ipAddress = $_SERVER['REMOTE_ADDR']; -$siteIsPrivate = $cfg->getValue('private.enable', CfgType::T_BOOL); -$loginPermCat = $siteIsPrivate ? $cfg->getValue('private.perm.cat', CfgType::T_STR) : ''; -$loginPermVal = $siteIsPrivate ? $cfg->getValue('private.perm.val', CfgType::T_INT) : 0; +$siteIsPrivate = $cfg->getValue('private.enable', IConfig::T_BOOL); +$loginPermCat = $siteIsPrivate ? $cfg->getValue('private.perm.cat', IConfig::T_STR) : ''; +$loginPermVal = $siteIsPrivate ? $cfg->getValue('private.perm.val', IConfig::T_INT) : 0; $remainingAttempts = UserLoginAttempt::remaining($ipAddress); 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'] : '' ); $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) : ''; -$canResetPassword = $siteIsPrivate ? $cfg->getValue('private.allow_password_reset', CfgType::T_BOOL, true) : true; +$sitePrivateMessage = $siteIsPrivate ? $cfg->getValue('private.msg', IConfig::T_STR) : ''; +$canResetPassword = $siteIsPrivate ? $cfg->getValue('private.allow_password_reset', IConfig::T_BOOL, true) : true; $canRegisterAccount = !$siteIsPrivate; Template::render('auth.login', [ diff --git a/public/auth/password.php b/public/auth/password.php index 6711d1b..5b1b8de 100644 --- a/public/auth/password.php +++ b/public/auth/password.php @@ -2,7 +2,7 @@ namespace Misuzu; use Misuzu\AuditLog; -use Misuzu\Config\CfgType; +IConfiguse Misuzu\Config\IConfig; use Misuzu\Users\User; use Misuzu\Users\UserNotFoundException; use Misuzu\Users\UserLoginAttempt; @@ -34,8 +34,8 @@ if($userId > 0) $notices = []; $ipAddress = $_SERVER['REMOTE_ADDR']; -$siteIsPrivate = $cfg->getValue('private.enable', CfgType::T_BOOL); -$canResetPassword = $siteIsPrivate ? $cfg->getValue('private.allow_password_reset', CfgType::T_BOOL, true) : true; +$siteIsPrivate = $cfg->getValue('private.enable', IConfig::T_BOOL); +$canResetPassword = $siteIsPrivate ? $cfg->getValue('private.allow_password_reset', IConfig::T_BOOL, true) : true; $remainingAttempts = UserLoginAttempt::remaining($ipAddress); while($canResetPassword) { diff --git a/public/forum/leaderboard.php b/public/forum/leaderboard.php index 98dded7..dc6951f 100644 --- a/public/forum/leaderboard.php +++ b/public/forum/leaderboard.php @@ -1,7 +1,7 @@ getValue('forum_leader.unranked.forum', CfgType::T_ARR); -$unrankedTopics = !empty($_GET['allow_unranked']) ? [] : $cfg->getValue('forum_leader.unranked.topic', 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', IConfig::T_ARR); $leaderboards = forum_leaderboard_categories(); $leaderboard = forum_leaderboard_listing($leaderboardYear, $leaderboardMonth, $unrankedForums, $unrankedTopics); diff --git a/public/manage/general/setting.php b/public/manage/general/setting.php index 6c06037..be1e766 100644 --- a/public/manage/general/setting.php +++ b/public/manage/general/setting.php @@ -3,7 +3,7 @@ namespace Misuzu; use Misuzu\Config; use Misuzu\Config\CfgTools; -use Misuzu\Config\CfgType; +use Misuzu\Config\IConfig; use Misuzu\Users\User; require_once '../../../misuzu.php'; @@ -106,7 +106,7 @@ if($cfg->hasValue($sName)) { $sValue = $cfg->getValue($sName); $sVar['type'] = $sType = CfgTools::type($sValue); - if($sType === CfgType::T_ARR) + if($sType === IConfig::T_ARR) foreach($sValue as $fk => $fv) $sValue[$fk] = ['integer' => 'i', 'string' => 's', 'boolean' => 'b'][gettype($fv)] . ':' . $fv; diff --git a/public/manage/general/settings.php b/public/manage/general/settings.php index 87966e2..50e7a5c 100644 --- a/public/manage/general/settings.php +++ b/public/manage/general/settings.php @@ -3,7 +3,7 @@ namespace Misuzu; use Misuzu\Config; use Misuzu\Config\CfgTools; -use Misuzu\Config\CfgType; +use Misuzu\Config\IConfig; use Misuzu\Users\User; require_once '../../../misuzu.php'; @@ -14,7 +14,7 @@ if(!User::hasCurrent() return; } -$hidden = $cfg->getValue('settings.hidden', CfgType::T_ARR, []); +$hidden = $cfg->getValue('settings.hidden', IConfig::T_ARR, []); $vars = []; foreach($cfg->getNames() as $key) { diff --git a/public/manage/general/twitter.php b/public/manage/general/twitter.php index c3c0b2d..2637af5 100644 --- a/public/manage/general/twitter.php +++ b/public/manage/general/twitter.php @@ -1,7 +1,6 @@ hasTOTP() !== (bool)$_POST['tfa']['enable']) { if((bool)$_POST['tfa']['enable']) { $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([ 'version' => 5, 'outputType' => QRCode::OUTPUT_IMAGE_JPG, diff --git a/src/Config.php b/src/Config.php index 43ad961..1f75986 100644 --- a/src/Config.php +++ b/src/Config.php @@ -2,7 +2,6 @@ namespace Misuzu; use Misuzu\Config\IConfig; -use Misuzu\Config\CfgType; final class Config { private static IConfig $config; @@ -15,7 +14,7 @@ final class Config { 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); } diff --git a/src/Config/CfgTools.php b/src/Config/CfgTools.php index 2562e7b..a84d3f1 100644 --- a/src/Config/CfgTools.php +++ b/src/Config/CfgTools.php @@ -7,10 +7,10 @@ final class CfgTools { } public static function isValidType(string $type): bool { - return $type === CfgType::T_ARR - || $type === CfgType::T_BOOL - || $type === CfgType::T_INT - || $type === CfgType::T_STR; + return $type === IConfig::T_ARR + || $type === IConfig::T_BOOL + || $type === IConfig::T_INT + || $type === IConfig::T_STR; } public static function validateName(string $name): bool { @@ -19,11 +19,11 @@ final class CfgTools { } private const DEFAULTS = [ - CfgType::T_ANY => null, - CfgType::T_STR => '', - CfgType::T_INT => 0, - CfgType::T_BOOL => false, - CfgType::T_ARR => [], + IConfig::T_ANY => null, + IConfig::T_STR => '', + IConfig::T_INT => 0, + IConfig::T_BOOL => false, + IConfig::T_ARR => [], ]; public static function default(string $type) { diff --git a/src/Config/CfgType.php b/src/Config/CfgType.php deleted file mode 100644 index e6407b5..0000000 --- a/src/Config/CfgType.php +++ /dev/null @@ -1,10 +0,0 @@ -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; - if($type !== CfgType::T_ANY && CfgTools::type($value) !== $type) + if($type !== IConfig::T_ANY && CfgTools::type($value) !== $type) $value = null; return $value ?? $default ?? CfgTools::default($type); diff --git a/src/Config/IConfig.php b/src/Config/IConfig.php index 1865686..d175972 100644 --- a/src/Config/IConfig.php +++ b/src/Config/IConfig.php @@ -8,10 +8,16 @@ namespace Misuzu\Config; // bulk operations for setValue and removeValue would also be cool interface IConfig { - function scopeTo(string $prefix): IConfig; - function getNames(): array; - function getValue(string $name, string $type = CfgType::T_ANY, $default = null): mixed; - function hasValue(string $name): bool; - function setValue(string $name, $value, bool $save = true): void; - function removeValue(string $name, bool $save = true): void; + public const T_ANY = ''; + public const T_STR = 'string'; + public const T_INT = 'integer'; + public const T_BOOL = 'boolean'; + public const T_ARR = 'array'; + + 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; } diff --git a/src/Config/ScopedConfig.php b/src/Config/ScopedConfig.php index 5423b9f..99f04f7 100644 --- a/src/Config/ScopedConfig.php +++ b/src/Config/ScopedConfig.php @@ -40,7 +40,7 @@ class ScopedConfig implements IConfig { 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); } diff --git a/src/GeoIP/GeoIPHelper.php b/src/GeoIP/GeoIPHelper.php index 8aecef6..de9a85d 100644 --- a/src/GeoIP/GeoIPHelper.php +++ b/src/GeoIP/GeoIPHelper.php @@ -10,7 +10,6 @@ use GeoIp2\Model\Asn; use GeoIp2\Model\City; use GeoIp2\Model\Country; use Misuzu\Config\IConfig; -use Misuzu\Config\CfgType; class GeoIPHelper { public const ASN = 'asn'; @@ -34,7 +33,7 @@ class GeoIPHelper { $type = 'db.' . $type; if(!$this->config->hasValue($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 { diff --git a/src/Http/Handlers/ChangelogHandler.php b/src/Http/Handlers/ChangelogHandler.php index bdbc70b..103e996 100644 --- a/src/Http/Handlers/ChangelogHandler.php +++ b/src/Http/Handlers/ChangelogHandler.php @@ -3,7 +3,7 @@ namespace Misuzu\Http\Handlers; use ErrorException; use Misuzu\Config; -use Misuzu\Config\CfgType; +use Misuzu\Config\IConfig; use Misuzu\Pagination; use Misuzu\Template; use Misuzu\Changelog\ChangelogChange; @@ -84,8 +84,8 @@ class ChangelogHandler extends Handler { $changes = ChangelogChange::all(new Pagination(10)); $feed = (new Feed) - ->setTitle(Config::get('site.name', CfgType::T_STR, 'Misuzu') . ' » Changelog') - ->setDescription('Live feed of changes to ' . Config::get('site.name', CfgType::T_STR, 'Misuzu') . '.') + ->setTitle(Config::get('site.name', IConfig::T_STR, 'Misuzu') . ' » Changelog') + ->setDescription('Live feed of changes to ' . Config::get('site.name', IConfig::T_STR, 'Misuzu') . '.') ->setContentUrl(url_prefix(false) . url('changelog-index')) ->setFeedUrl(url_prefix(false) . url("changelog-feed-{$feedMode}")); diff --git a/src/Http/Handlers/HomeHandler.php b/src/Http/Handlers/HomeHandler.php index d322ab8..5bd7389 100644 --- a/src/Http/Handlers/HomeHandler.php +++ b/src/Http/Handlers/HomeHandler.php @@ -2,7 +2,7 @@ namespace Misuzu\Http\Handlers; use Misuzu\Config; -use Misuzu\Config\CfgType; +use Misuzu\Config\IConfig; use Misuzu\DB; use Misuzu\Pagination; use Misuzu\Template; @@ -20,12 +20,12 @@ final class HomeHandler extends Handler { } 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'), - 'url' => Config::get('site.url', CfgType::T_STR), - 'logo' => Config::get('site.ext_logo', CfgType::T_STR), - 'same_as' => Config::get('social.linked', CfgType::T_ARR), + 'name' => Config::get('site.name', IConfig::T_STR, 'Misuzu'), + 'url' => Config::get('site.url', IConfig::T_STR), + 'logo' => Config::get('site.ext_logo', IConfig::T_STR), + 'same_as' => Config::get('social.linked', IConfig::T_ARR), ] : null; @@ -52,7 +52,7 @@ final class HomeHandler extends Handler { )->fetchAll(); // 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 = []; $activeTopics = []; diff --git a/src/Http/Handlers/NewsHandler.php b/src/Http/Handlers/NewsHandler.php index f48a1d9..41ca4fe 100644 --- a/src/Http/Handlers/NewsHandler.php +++ b/src/Http/Handlers/NewsHandler.php @@ -2,7 +2,7 @@ namespace Misuzu\Http\Handlers; use Misuzu\Config; -use Misuzu\Config\CfgType; +use Misuzu\Config\IConfig; use Misuzu\DB; use Misuzu\Pagination; use Misuzu\Template; @@ -86,7 +86,7 @@ final class NewsHandler extends Handler { $posts = $hasCategory ? $categoryInfo->posts($pagination) : NewsPost::all($pagination, true); $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.') ->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}"))); diff --git a/src/SharpChat/SharpChatRoutes.php b/src/SharpChat/SharpChatRoutes.php index b36ef84..b5a2dd0 100644 --- a/src/SharpChat/SharpChatRoutes.php +++ b/src/SharpChat/SharpChatRoutes.php @@ -4,7 +4,6 @@ namespace Misuzu\SharpChat; use Index\Colour\Colour; use Index\Routing\IRouter; use Misuzu\Config\IConfig; -use Misuzu\Config\CfgType; // Replace use Misuzu\AuthToken; @@ -22,10 +21,10 @@ final class SharpChatRoutes { public function __construct(IRouter $router, IConfig $config) { $this->config = $config; - $hashKey = $this->config->getValue('hashKey', CfgType::T_STR, ''); + $hashKey = $this->config->getValue('hashKey', IConfig::T_STR, ''); if(empty($hashKey)) { - $hashKeyPath = $this->config->getValue('hashKeyPath', CfgType::T_STR, ''); + $hashKeyPath = $this->config->getValue('hashKeyPath', IConfig::T_STR, ''); if(is_file($hashKeyPath)) $this->hashKey = file_get_contents($hashKeyPath); } else { @@ -74,7 +73,7 @@ final class SharpChatRoutes { public function login($response, $request): void { $currentUser = User::getCurrent(); $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( $currentUser === null @@ -89,7 +88,7 @@ final class SharpChatRoutes { $originHost = strtolower(parse_url($origin, PHP_URL_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)) return 403; diff --git a/src/Twitter/TwitterAccessToken.php b/src/Twitter/TwitterAccessToken.php index f3220dd..919c159 100644 --- a/src/Twitter/TwitterAccessToken.php +++ b/src/Twitter/TwitterAccessToken.php @@ -3,7 +3,6 @@ namespace Misuzu\Twitter; use Stringable; use Misuzu\Config\IConfig; -use Misuzu\Config\CfgType; class TwitterAccessToken implements Stringable { public function __construct( @@ -66,11 +65,11 @@ class TwitterAccessToken implements Stringable { public static function load(IConfig $config): self { return new static( - $config->getValue('type', CfgType::T_STR), - $config->getValue('token', CfgType::T_STR), - $config->getValue('expires', CfgType::T_INT), - $config->getValue('token', CfgType::T_ARR), - $config->getValue('refresh', CfgType::T_STR) + $config->getValue('type', IConfig::T_STR), + $config->getValue('token', IConfig::T_STR), + $config->getValue('expires', IConfig::T_INT), + $config->getValue('token', IConfig::T_ARR), + $config->getValue('refresh', IConfig::T_STR) ); } diff --git a/src/Twitter/TwitterClientId.php b/src/Twitter/TwitterClientId.php index 3ade07e..ca92344 100644 --- a/src/Twitter/TwitterClientId.php +++ b/src/Twitter/TwitterClientId.php @@ -3,7 +3,6 @@ namespace Misuzu\Twitter; use Stringable; use Misuzu\Config\IConfig; -use Misuzu\Config\CfgType; class TwitterClientId implements Stringable { public function __construct( @@ -29,8 +28,8 @@ class TwitterClientId implements Stringable { public static function load(IConfig $config): self { return new static( - $config->getValue('clientId', CfgType::T_STR), - $config->getValue('clientSecret', CfgType::T_STR) + $config->getValue('clientId', IConfig::T_STR), + $config->getValue('clientSecret', IConfig::T_STR) ); } } diff --git a/src/Users/Assets/UserAvatarAsset.php b/src/Users/Assets/UserAvatarAsset.php index 683c610..d52a99c 100644 --- a/src/Users/Assets/UserAvatarAsset.php +++ b/src/Users/Assets/UserAvatarAsset.php @@ -2,7 +2,7 @@ namespace Misuzu\Users\Assets; use Misuzu\Config; -use Misuzu\Config\CfgType; +use Misuzu\Config\IConfig; use Misuzu\Imaging\Image; use Misuzu\Users\User; @@ -20,13 +20,13 @@ class UserAvatarAsset extends UserImageAsset implements UserAssetScalableInterfa private const MAX_BYTES = 1048576; 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 { return $this->getMaxWidth(); } 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 { diff --git a/src/Users/Assets/UserBackgroundAsset.php b/src/Users/Assets/UserBackgroundAsset.php index 06cafe7..786d68f 100644 --- a/src/Users/Assets/UserBackgroundAsset.php +++ b/src/Users/Assets/UserBackgroundAsset.php @@ -3,7 +3,7 @@ namespace Misuzu\Users\Assets; use InvalidArgumentException; use Misuzu\Config; -use Misuzu\Config\CfgType; +use Misuzu\Config\IConfig; use Misuzu\Users\User; // attachment and attributes are to be stored in the same byte @@ -49,13 +49,13 @@ class UserBackgroundAsset extends UserImageAsset { } 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 { - 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 { - 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 { diff --git a/src/Users/Assets/UserImageAsset.php b/src/Users/Assets/UserImageAsset.php index ef5eed5..b8358eb 100644 --- a/src/Users/Assets/UserImageAsset.php +++ b/src/Users/Assets/UserImageAsset.php @@ -3,7 +3,7 @@ namespace Misuzu\Users\Assets; use JsonSerializable; use Misuzu\Config; -use Misuzu\Config\CfgType; +use Misuzu\Config\IConfig; use Misuzu\Users\User; class UserImageAssetFileCreationFailedException extends UserAssetException {} @@ -84,7 +84,7 @@ abstract class UserImageAsset implements JsonSerializable, UserImageAssetInterfa } 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 {