Use SharpConfig format for the pre-database config.

This commit is contained in:
flash 2023-10-21 23:45:40 +00:00
parent c2836719c7
commit 5f57e3fdf4
6 changed files with 72 additions and 69 deletions

2
.gitignore vendored
View file

@ -11,6 +11,8 @@
/composer.local.json /composer.local.json
# Configuration # Configuration
/config/config.cfg
/config/github.cfg
/config/config.ini /config/config.ini
/config/github.ini /config/github.ini
/.debug /.debug

91
composer.lock generated
View file

@ -293,16 +293,16 @@
}, },
{ {
"name": "egulias/email-validator", "name": "egulias/email-validator",
"version": "4.0.1", "version": "4.0.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/egulias/EmailValidator.git", "url": "https://github.com/egulias/EmailValidator.git",
"reference": "3a85486b709bc384dae8eb78fb2eec649bdb64ff" "reference": "ebaaf5be6c0286928352e054f2d5125608e5405e"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/egulias/EmailValidator/zipball/3a85486b709bc384dae8eb78fb2eec649bdb64ff", "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/ebaaf5be6c0286928352e054f2d5125608e5405e",
"reference": "3a85486b709bc384dae8eb78fb2eec649bdb64ff", "reference": "ebaaf5be6c0286928352e054f2d5125608e5405e",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -311,8 +311,8 @@
"symfony/polyfill-intl-idn": "^1.26" "symfony/polyfill-intl-idn": "^1.26"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^9.5.27", "phpunit/phpunit": "^10.2",
"vimeo/psalm": "^4.30" "vimeo/psalm": "^5.12"
}, },
"suggest": { "suggest": {
"ext-intl": "PHP Internationalization Libraries are required to use the SpoofChecking validation" "ext-intl": "PHP Internationalization Libraries are required to use the SpoofChecking validation"
@ -348,7 +348,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/egulias/EmailValidator/issues", "issues": "https://github.com/egulias/EmailValidator/issues",
"source": "https://github.com/egulias/EmailValidator/tree/4.0.1" "source": "https://github.com/egulias/EmailValidator/tree/4.0.2"
}, },
"funding": [ "funding": [
{ {
@ -356,7 +356,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2023-01-14T14:17:03+00:00" "time": "2023-10-06T06:47:41+00:00"
}, },
{ {
"name": "erusev/parsedown", "name": "erusev/parsedown",
@ -414,7 +414,7 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://git.flash.moe/flash/index.git", "url": "https://git.flash.moe/flash/index.git",
"reference": "f71f3fcf9eb916420f3e8217f99e616149aedc76" "reference": "82a350a5c719cc83aa22382201683a68a2629f2a"
}, },
"require": { "require": {
"ext-mbstring": "*", "ext-mbstring": "*",
@ -452,7 +452,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-09-11T20:34:16+00:00" "time": "2023-09-15T22:44:36+00:00"
}, },
{ {
"name": "flashwave/sasae", "name": "flashwave/sasae",
@ -852,16 +852,16 @@
}, },
{ {
"name": "matomo/device-detector", "name": "matomo/device-detector",
"version": "6.1.5", "version": "6.1.6",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/matomo-org/device-detector.git", "url": "https://github.com/matomo-org/device-detector.git",
"reference": "40ca2990dba2c1719e5c62168e822e0b86c167d4" "reference": "5cbea85106e561c7138d03603eb6e05128480409"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/matomo-org/device-detector/zipball/40ca2990dba2c1719e5c62168e822e0b86c167d4", "url": "https://api.github.com/repos/matomo-org/device-detector/zipball/5cbea85106e561c7138d03603eb6e05128480409",
"reference": "40ca2990dba2c1719e5c62168e822e0b86c167d4", "reference": "5cbea85106e561c7138d03603eb6e05128480409",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -917,7 +917,7 @@
"source": "https://github.com/matomo-org/matomo", "source": "https://github.com/matomo-org/matomo",
"wiki": "https://dev.matomo.org/" "wiki": "https://dev.matomo.org/"
}, },
"time": "2023-08-17T16:17:41+00:00" "time": "2023-10-02T10:01:54+00:00"
}, },
{ {
"name": "mustangostang/spyc", "name": "mustangostang/spyc",
@ -1459,16 +1459,16 @@
}, },
{ {
"name": "psr/http-client", "name": "psr/http-client",
"version": "1.0.2", "version": "1.0.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/php-fig/http-client.git", "url": "https://github.com/php-fig/http-client.git",
"reference": "0955afe48220520692d2d09f7ab7e0f93ffd6a31" "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/php-fig/http-client/zipball/0955afe48220520692d2d09f7ab7e0f93ffd6a31", "url": "https://api.github.com/repos/php-fig/http-client/zipball/bb5906edc1c324c9a05aa0873d40117941e5fa90",
"reference": "0955afe48220520692d2d09f7ab7e0f93ffd6a31", "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1505,9 +1505,9 @@
"psr-18" "psr-18"
], ],
"support": { "support": {
"source": "https://github.com/php-fig/http-client/tree/1.0.2" "source": "https://github.com/php-fig/http-client"
}, },
"time": "2023-04-10T20:12:12+00:00" "time": "2023-09-23T14:17:50+00:00"
}, },
{ {
"name": "psr/http-factory", "name": "psr/http-factory",
@ -2093,16 +2093,16 @@
}, },
{ {
"name": "symfony/http-client", "name": "symfony/http-client",
"version": "v6.3.2", "version": "v6.3.6",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/http-client.git", "url": "https://github.com/symfony/http-client.git",
"reference": "15f9f4bad62bfcbe48b5dedd866f04a08fc7ff00" "reference": "ab8446f997efb9913627e9da10fa784d2182fe92"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/http-client/zipball/15f9f4bad62bfcbe48b5dedd866f04a08fc7ff00", "url": "https://api.github.com/repos/symfony/http-client/zipball/ab8446f997efb9913627e9da10fa784d2182fe92",
"reference": "15f9f4bad62bfcbe48b5dedd866f04a08fc7ff00", "reference": "ab8446f997efb9913627e9da10fa784d2182fe92",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2165,7 +2165,7 @@
"http" "http"
], ],
"support": { "support": {
"source": "https://github.com/symfony/http-client/tree/v6.3.2" "source": "https://github.com/symfony/http-client/tree/v6.3.6"
}, },
"funding": [ "funding": [
{ {
@ -2181,7 +2181,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-07-05T08:41:27+00:00" "time": "2023-10-06T10:08:56+00:00"
}, },
{ {
"name": "symfony/http-client-contracts", "name": "symfony/http-client-contracts",
@ -2263,16 +2263,16 @@
}, },
{ {
"name": "symfony/mailer", "name": "symfony/mailer",
"version": "v6.3.0", "version": "v6.3.5",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/mailer.git", "url": "https://github.com/symfony/mailer.git",
"reference": "7b03d9be1dea29bfec0a6c7b603f5072a4c97435" "reference": "d89611a7830d51b5e118bca38e390dea92f9ea06"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/mailer/zipball/7b03d9be1dea29bfec0a6c7b603f5072a4c97435", "url": "https://api.github.com/repos/symfony/mailer/zipball/d89611a7830d51b5e118bca38e390dea92f9ea06",
"reference": "7b03d9be1dea29bfec0a6c7b603f5072a4c97435", "reference": "d89611a7830d51b5e118bca38e390dea92f9ea06",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2323,7 +2323,7 @@
"description": "Helps sending emails", "description": "Helps sending emails",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"support": { "support": {
"source": "https://github.com/symfony/mailer/tree/v6.3.0" "source": "https://github.com/symfony/mailer/tree/v6.3.5"
}, },
"funding": [ "funding": [
{ {
@ -2339,20 +2339,20 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-05-29T12:49:39+00:00" "time": "2023-09-06T09:47:15+00:00"
}, },
{ {
"name": "symfony/mime", "name": "symfony/mime",
"version": "v6.3.3", "version": "v6.3.5",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/mime.git", "url": "https://github.com/symfony/mime.git",
"reference": "9a0cbd52baa5ba5a5b1f0cacc59466f194730f98" "reference": "d5179eedf1cb2946dbd760475ebf05c251ef6a6e"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/mime/zipball/9a0cbd52baa5ba5a5b1f0cacc59466f194730f98", "url": "https://api.github.com/repos/symfony/mime/zipball/d5179eedf1cb2946dbd760475ebf05c251ef6a6e",
"reference": "9a0cbd52baa5ba5a5b1f0cacc59466f194730f98", "reference": "d5179eedf1cb2946dbd760475ebf05c251ef6a6e",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2407,7 +2407,7 @@
"mime-type" "mime-type"
], ],
"support": { "support": {
"source": "https://github.com/symfony/mime/tree/v6.3.3" "source": "https://github.com/symfony/mime/tree/v6.3.5"
}, },
"funding": [ "funding": [
{ {
@ -2423,7 +2423,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-07-31T07:08:24+00:00" "time": "2023-09-29T06:59:36+00:00"
}, },
{ {
"name": "symfony/options-resolver", "name": "symfony/options-resolver",
@ -3208,16 +3208,16 @@
"packages-dev": [ "packages-dev": [
{ {
"name": "phpstan/phpstan", "name": "phpstan/phpstan",
"version": "1.10.33", "version": "1.10.39",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpstan/phpstan.git", "url": "https://github.com/phpstan/phpstan.git",
"reference": "03b1cf9f814ba0863c4e9affea49a4d1ed9a2ed1" "reference": "d9dedb0413f678b4d03cbc2279a48f91592c97c4"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/03b1cf9f814ba0863c4e9affea49a4d1ed9a2ed1", "url": "https://api.github.com/repos/phpstan/phpstan/zipball/d9dedb0413f678b4d03cbc2279a48f91592c97c4",
"reference": "03b1cf9f814ba0863c4e9affea49a4d1ed9a2ed1", "reference": "d9dedb0413f678b4d03cbc2279a48f91592c97c4",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -3266,14 +3266,15 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-09-04T12:20:53+00:00" "time": "2023-10-17T15:46:26+00:00"
} }
], ],
"aliases": [], "aliases": [],
"minimum-stability": "dev", "minimum-stability": "dev",
"stability-flags": { "stability-flags": {
"flashwave/index": 20, "flashwave/index": 20,
"flashwave/sasae": 20 "flashwave/sasae": 20,
"flashwave/syokuhou": 20
}, },
"prefer-stable": true, "prefer-stable": true,
"prefer-lowest": false, "prefer-lowest": false,

View file

@ -0,0 +1,8 @@
# Example configuration for Misuzu
# and ; can be used at the start of a line for comments.
database:dsn mariadb://<user>:<pass>@<host>/<name>?charset=utf8mb4
;sentry:dsn https://sentry dsn here
;sentry:tracesRate 1.0
;sentry:profilesRate 1.0

View file

@ -1,10 +0,0 @@
; Example configuration for Misuzu
[Database]
driver = mysql
host = localhost
port = 3306
username = username
password = password
dbname = database
charset = utf8mb4

View file

@ -4,6 +4,7 @@ namespace Misuzu;
use Index\Environment; use Index\Environment;
use Index\Data\DbTools; use Index\Data\DbTools;
use Syokuhou\DbConfig; use Syokuhou\DbConfig;
use Syokuhou\SharpConfig;
define('MSZ_STARTUP', microtime(true)); define('MSZ_STARTUP', microtime(true));
define('MSZ_ROOT', __DIR__); define('MSZ_ROOT', __DIR__);
@ -22,21 +23,22 @@ Environment::setDebug(MSZ_DEBUG);
mb_internal_encoding('utf-8'); mb_internal_encoding('utf-8');
date_default_timezone_set('utc'); date_default_timezone_set('utc');
$cfg = parse_ini_file(MSZ_CONFIG . '/config.ini', true, INI_SCANNER_TYPED); $cfg = SharpConfig::fromFile(MSZ_CONFIG . '/config.cfg');
if(!empty($cfg['sentry-dsn'])) { if($cfg->hasValues('sentry:dsn'))
\Sentry\init([ (function($cfg) {
'dsn' => $cfg['sentry-dsn'], \Sentry\init([
'traces_sample_rate' => $cfg['sentry-traces-rate'] ?? 0.2, 'dsn' => $cfg->getString('dsn'),
'profiles_sample_rate' => $cfg['sentry-profiles-rate'] ?? 0.2, 'traces_sample_rate' => $cfg->getFloat('tracesRate', 0.2),
]); 'profiles_sample_rate' => $cfg->getFloat('profilesRate', 0.2),
]);
set_exception_handler(function(\Throwable $ex) { set_exception_handler(function(\Throwable $ex) {
\Sentry\captureException($ex); \Sentry\captureException($ex);
}); });
} })($cfg->scopeTo('sentry'));
$db = DbTools::create($cfg['dsn'] ?? 'null:'); $db = DbTools::create($cfg->getString('database:dsn', 'null:'));
$db->execute('SET SESSION time_zone = \'+00:00\', sql_mode = \'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION\';'); $db->execute('SET SESSION time_zone = \'+00:00\', sql_mode = \'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION\';');
$cfg = new DbConfig($db, 'msz_config'); $cfg = new DbConfig($db, 'msz_config');

View file

@ -43,11 +43,11 @@ header('Content-Type: text/plain; charset=utf-8');
if($_SERVER['REQUEST_METHOD'] !== 'POST') if($_SERVER['REQUEST_METHOD'] !== 'POST')
die('no'); die('no');
$config = MSZ_ROOT . '/config/github.ini'; $config = MSZ_CONFIG . '/github.ini';
if(!is_file($config)) if(!is_file($config))
die('config missing'); die('config missing');
$config = parse_ini_file(MSZ_ROOT . '/config/github.ini', true); $config = parse_ini_file($config, true);
if(empty($config['tokens']['token'])) if(empty($config['tokens']['token']))
die('config invalid'); die('config invalid');