1
0
Files
breadcrumb-the-shire/config/config.php

99 lines
3.2 KiB
PHP
Raw Normal View History

2026-02-04 23:31:53 +01:00
<?php
2026-03-04 15:56:58 +01:00
use MintyPHP\App\Bootstrap\EnvValidator;
feat(console): add db:migrate CLI for idempotent core schema updates Existing systems used to have no automatic mechanism for the db/updates/*.sql idempotent updates after `git pull` — devs had to remember which files were already applied and run new ones manually with `mariadb < ...`. Mirror module:migrate to fix this: - New `bin/console db:migrate` walks db/updates/*.sql in alphabetical order, skipping anything already recorded in the new core_migrations tracking table. Each file runs in its own transaction; failure rolls back so the file is retried on the next run. - New `db:migrate --status` lists applied vs. pending files without running anything. Useful for ops debugging "schema seems stale" symptoms. - module:sync now runs db:migrate as its first step, so the standard post-pull command stays a single invocation. README's 3-step setup is unchanged — module:sync now also covers core schema updates. CoreMigrationRepository owns its own mysqli connection (using the same DB credentials as MintyPHP\DB) and runs raw `$mysqli->query()` instead of going through DB::query's prepared statement path — MariaDB rejects some DDL (e.g. ALTER TABLE … ADD CONSTRAINT CHECK) in the prepared protocol, which the existing 18 db/updates files trip on. ModuleMigrationRepository is left untouched (no module migration uses such DDL today and changing the vendor pattern is out of scope). End-to-end verified: against an existing DB the first run applies all 19 idempotent files as no-ops and records them, second run reports "all updates already applied". Against a freshly init'd DB the same thing happens — no double work, no surprises. All encrypted seed secrets keep decrypting because APP_CRYPTO_KEY is unchanged. Tests: tests/Console/CoreCommandsTest covers success/failure/status output shapes against a FakeModuleRunner (mirror of the existing ModuleCommandsTest pattern). 5 stale baseline entries in phpstan-baseline removed (covered by the new @api annotation on the test fixture class). Docs: CLAUDE.md and docs/reference-cli-commands.md document the new command + --status flag; docs/howto-fehlerbehebung.md gains a "schema seems stale after git pull" section pointing at db:migrate --status. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 08:59:57 +02:00
use MintyPHP\Auth;
2026-02-04 23:31:53 +01:00
use MintyPHP\Cache;
use MintyPHP\DB;
use MintyPHP\Debugger;
use MintyPHP\Firewall;
use MintyPHP\I18n;
use MintyPHP\Router;
use MintyPHP\Session;
2026-03-04 15:56:58 +01:00
EnvValidator::validate();
$envString = static function (string $key, string $default): string {
$value = getenv($key);
if ($value === false || $value === '') {
return $default;
}
return (string) $value;
};
$envInt = static function (string $key, int $default): int {
$value = getenv($key);
if ($value === false || $value === '') {
return $default;
}
$parsed = filter_var($value, FILTER_VALIDATE_INT);
return $parsed !== false ? (int) $parsed : $default;
};
$envFloat = static function (string $key, float $default): float {
$value = getenv($key);
if ($value === false || $value === '') {
return $default;
}
$parsed = filter_var($value, FILTER_VALIDATE_FLOAT);
return $parsed !== false ? (float) $parsed : $default;
};
$envBool = static function (string $key, bool $default): bool {
$value = getenv($key);
if ($value === false || $value === '') {
return $default;
}
$parsed = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
return $parsed ?? $default;
};
$envList = static function (string $key, array $default): array {
$value = getenv($key);
if ($value === false || $value === '') {
return $default;
}
return array_values(array_filter(array_map('trim', explode(',', (string) $value))));
};
define('APP_NAME', $envString('APP_NAME', 'CoreCore'));
define('APP_TIMEZONE', $envString('APP_TIMEZONE', 'Europe/Berlin'));
define('APP_STORAGE_PATH', $envString('APP_STORAGE_PATH', __DIR__ . '/../storage'));
define('APP_CRYPTO_KEY', $envString('APP_CRYPTO_KEY', ''));
define('TENANT_SCOPE_STRICT', $envBool('TENANT_SCOPE_STRICT', true));
2026-02-04 23:31:53 +01:00
if (!defined('APP_LOCALES')) {
define('APP_LOCALES', $envList('APP_LOCALES', ['de', 'en']));
}
2026-02-04 23:31:53 +01:00
date_default_timezone_set(APP_TIMEZONE);
Router::$baseUrl = '/'; // default: '/'
Router::$pageRoot = 'pages/'; // default: 'pages/'
Router::$templateRoot = 'templates/'; // default: 'templates/'
Session::$sessionName = $envString('SESSION_NAME', 'MintyPHP');
2026-02-04 23:31:53 +01:00
Firewall::$concurrency = $envInt('FIREWALL_CONCURRENCY', 10);
Firewall::$spinLockSeconds = $envFloat('FIREWALL_SPINLOCK_SECONDS', 0.15);
Firewall::$intervalSeconds = $envInt('FIREWALL_INTERVAL_SECONDS', 300);
Firewall::$cachePrefix = $envString('FIREWALL_CACHE_PREFIX', 'fw_concurrency_');
Firewall::$reverseProxy = $envBool('FIREWALL_REVERSE_PROXY', false);
2026-02-04 23:31:53 +01:00
Cache::$servers = $envString('CACHE_SERVERS', '127.0.0.1');
2026-02-04 23:31:53 +01:00
DB::$host = $envString('DB_HOST', 'db');
DB::$username = $envString('DB_USER', 'mintyphp');
DB::$password = $envString('DB_PASS', 'mintyphp');
DB::$database = $envString('DB_NAME', 'mintyphp');
DB::$port = $envInt('DB_PORT', 3306);
2026-02-04 23:31:53 +01:00
Auth::$usersTable = 'users';
Auth::$usernameField = 'email';
Auth::$passwordField = 'password';
Auth::$createdField = 'created';
Auth::$totpSecretField = 'totp_secret';
Debugger::$enabled = $envBool('APP_DEBUG', true);
2026-02-04 23:31:53 +01:00
I18n::$domain = $envString('APP_I18N_DOMAIN', 'default');
I18n::$locale = $envString('APP_LOCALE', 'de');