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:
@@ -5,16 +5,19 @@ declare(strict_types=1);
|
||||
namespace App\Framework\Config;
|
||||
|
||||
use App\Framework\Config\Exceptions\RequiredEnvironmentVariableException;
|
||||
use App\Framework\Filesystem\FilePath;
|
||||
|
||||
final readonly class Environment
|
||||
{
|
||||
public function __construct(
|
||||
private array $variables = []
|
||||
){}
|
||||
) {
|
||||
}
|
||||
|
||||
public function get(EnvKey|string $key, mixed $default = null): mixed
|
||||
{
|
||||
$key = $this->keyToString($key);
|
||||
|
||||
// Priorität: 1. System ENV, 2. Loaded variables, 3. Default
|
||||
return $_ENV[$key] ?? $_SERVER[$key] ?? getenv($key) ?: $this->variables[$key] ?? $default;
|
||||
}
|
||||
@@ -26,15 +29,24 @@ final readonly class Environment
|
||||
if ($value === null) {
|
||||
throw new RequiredEnvironmentVariableException($key);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function getInt(EnvKey|string $key, int $default = 0): int
|
||||
{
|
||||
$key = $this->keyToString($key);
|
||||
|
||||
return (int) $this->get($key, $default);
|
||||
}
|
||||
|
||||
public function getFloat(EnvKey|string $key, float $default = 0.0): float
|
||||
{
|
||||
$key = $this->keyToString($key);
|
||||
|
||||
return (float) $this->get($key, $default);
|
||||
}
|
||||
|
||||
public function getBool(EnvKey|string $key, bool $default = false): bool
|
||||
{
|
||||
$key = $this->keyToString($key);
|
||||
@@ -46,18 +58,21 @@ final readonly class Environment
|
||||
default => $default
|
||||
};
|
||||
}
|
||||
|
||||
return (bool) $value;
|
||||
}
|
||||
|
||||
public function getString(EnvKey|string $key, string $default = ''): string
|
||||
{
|
||||
$key = $this->keyToString($key);
|
||||
|
||||
return (string) $this->get($key, $default);
|
||||
}
|
||||
|
||||
public function getEnum(EnvKey|string $key, string $enumClass, \BackedEnum $default):object
|
||||
public function getEnum(EnvKey|string $key, string $enumClass, \BackedEnum $default): object
|
||||
{
|
||||
$key = $this->keyToString($key);
|
||||
|
||||
return forward_static_call([$enumClass, 'tryFrom'], $this->get($key, $default));
|
||||
#$enumClass::tryFrom($this->get($key, $default));
|
||||
}
|
||||
@@ -65,6 +80,7 @@ final readonly class Environment
|
||||
public function has(EnvKey|string $key): bool
|
||||
{
|
||||
$key = $this->keyToString($key);
|
||||
|
||||
return $this->get($key) !== null;
|
||||
}
|
||||
|
||||
@@ -80,15 +96,16 @@ final readonly class Environment
|
||||
/**
|
||||
* Factory method für .env file loading
|
||||
*/
|
||||
public static function fromFile(string $envPath): self
|
||||
public static function fromFile(FilePath|string $envPath): self
|
||||
{
|
||||
$variables = [];
|
||||
$filePath = $envPath instanceof FilePath ? $envPath : FilePath::create($envPath);
|
||||
|
||||
if (file_exists($envPath) && is_readable($envPath)) {
|
||||
$lines = file($envPath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
if ($filePath->exists() && $filePath->isReadable()) {
|
||||
$lines = file($filePath->toString(), FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
|
||||
foreach ($lines as $line) {
|
||||
if (str_starts_with(trim($line), '#') || !str_contains($line, '=')) {
|
||||
if (str_starts_with(trim($line), '#') || ! str_contains($line, '=')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -118,11 +135,12 @@ final readonly class Environment
|
||||
};
|
||||
}
|
||||
|
||||
public function keyToString(EnvKey|string $key):string
|
||||
public function keyToString(EnvKey|string $key): string
|
||||
{
|
||||
if(is_string($key)) {
|
||||
if (is_string($key)) {
|
||||
return $key;
|
||||
}
|
||||
|
||||
return $key->value;
|
||||
}
|
||||
|
||||
@@ -133,6 +151,7 @@ final readonly class Environment
|
||||
{
|
||||
$variables = $this->variables;
|
||||
$variables[$key] = $value;
|
||||
|
||||
return new self($variables);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user