Enable Discovery debug logging for production troubleshooting

- Add DISCOVERY_LOG_LEVEL=debug
- Add DISCOVERY_SHOW_PROGRESS=true
- Temporary changes for debugging InitializerProcessor fixes on production
This commit is contained in:
2025-08-11 20:13:26 +02:00
parent 59fd3dd3b1
commit 55a330b223
3683 changed files with 2956207 additions and 16948 deletions

View File

@@ -0,0 +1,122 @@
<?php
declare(strict_types=1);
namespace App\Framework\Config;
/**
* Lightweight boot-time configuration validator.
*
* Non-invasive: reports issues via error_log and returns a list of problems
* without throwing, so existing environments are not broken inadvertently.
*/
final readonly class ConfigValidator
{
public function __construct(private Environment $env)
{
}
/**
* Validate selected environment variables and return a list of issues.
* Each issue contains: key, issue, severity, recommendation.
*/
public function validate(): array
{
$issues = [];
// APP_ENV validation
$allowedEnvs = ['development', 'testing', 'production'];
$appEnv = $this->env->getString(EnvKey::APP_ENV, 'production');
if (!in_array($appEnv, $allowedEnvs, true)) {
$issues[] = [
'key' => 'APP_ENV',
'issue' => 'invalid_value',
'severity' => 'medium',
'recommendation' => 'Setze APP_ENV auf einen der Werte: development | testing | production',
];
}
// APP_DEBUG should be boolean-like if present
if ($this->env->has(EnvKey::APP_DEBUG)) {
$raw = $this->env->get(EnvKey::APP_DEBUG);
if (!is_bool($raw) && !is_string($raw)) {
$issues[] = [
'key' => 'APP_DEBUG',
'issue' => 'invalid_type',
'severity' => 'low',
'recommendation' => 'APP_DEBUG sollte true/false (oder "true"/"false") sein.',
];
}
}
// APP_PORT if present should be a valid TCP port
if ($this->env->has('APP_PORT')) {
$port = (int) $this->env->get('APP_PORT');
if ($port < 1 || $port > 65535) {
$issues[] = [
'key' => 'APP_PORT',
'issue' => 'out_of_range',
'severity' => 'medium',
'recommendation' => 'APP_PORT muss zwischen 1 und 65535 liegen.',
];
}
}
// Redis port if present
if ($this->env->has('REDIS_PORT')) {
$redisPort = (int) $this->env->get('REDIS_PORT');
if ($redisPort < 1 || $redisPort > 65535) {
$issues[] = [
'key' => 'REDIS_PORT',
'issue' => 'out_of_range',
'severity' => 'low',
'recommendation' => 'REDIS_PORT muss zwischen 1 und 65535 liegen.',
];
}
}
// Rate limit values if present: must be non-negative
foreach ([
'RATE_LIMIT_DEFAULT',
'RATE_LIMIT_WINDOW',
'RATE_LIMIT_AUTH',
'RATE_LIMIT_AUTH_WINDOW',
'RATE_LIMIT_API',
'RATE_LIMIT_API_WINDOW',
] as $rateKey) {
if ($this->env->has($rateKey)) {
$value = (int) $this->env->get($rateKey);
if ($value < 0) {
$issues[] = [
'key' => $rateKey,
'issue' => 'negative_value',
'severity' => 'low',
'recommendation' => $rateKey . ' sollte eine nicht-negative Ganzzahl sein.',
];
}
}
}
return $issues;
}
/**
* Validate and log issues. Returns the list of issues for optional handling.
*/
public function validateAndReport(): array
{
$issues = $this->validate();
foreach ($issues as $issue) {
$msg = sprintf(
'[CONFIG] key=%s issue=%s severity=%s recommendation=%s',
$issue['key'],
$issue['issue'],
$issue['severity'],
$issue['recommendation']
);
error_log($msg);
}
return $issues;
}
}