feat: CI/CD pipeline setup complete - Ansible playbooks updated, secrets configured, workflow ready
This commit is contained in:
@@ -14,7 +14,8 @@ final readonly class Environment
|
||||
* @param array<string, mixed> $variables
|
||||
*/
|
||||
public function __construct(
|
||||
private array $variables = []
|
||||
private array $variables = [],
|
||||
private DockerSecretsResolver $secretsResolver = new DockerSecretsResolver()
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -22,8 +23,19 @@ final readonly class Environment
|
||||
{
|
||||
$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;
|
||||
// 1. Check if direct env var exists
|
||||
if (isset($this->variables[$key])) {
|
||||
return $this->variables[$key];
|
||||
}
|
||||
|
||||
// 2. Docker Secrets support: Check for *_FILE pattern
|
||||
$secretValue = $this->secretsResolver->resolve($key, $this->variables);
|
||||
if ($secretValue !== null) {
|
||||
return $secretValue;
|
||||
}
|
||||
|
||||
// 3. Return default
|
||||
return $default;
|
||||
}
|
||||
|
||||
public function getRequired(EnvKey|string $key): mixed
|
||||
@@ -74,7 +86,7 @@ final readonly class Environment
|
||||
}
|
||||
|
||||
/** @param class-string<BackedEnum> $enumClass */
|
||||
public function getEnum(EnvKey|string $key, string $enumClass, BackedEnum $default): object
|
||||
public function getEnum(EnvKey|string $key, string $enumClass, BackedEnum $default): BackedEnum
|
||||
{
|
||||
$key = $this->keyToString($key);
|
||||
|
||||
@@ -82,9 +94,13 @@ final readonly class Environment
|
||||
throw new \InvalidArgumentException('Default value must be an instance of the enum class');
|
||||
}
|
||||
|
||||
return forward_static_call([$enumClass, 'tryFrom'], $key) ?? $default;
|
||||
$value = $this->get($key);
|
||||
|
||||
#$enumClass::tryFrom($this->get($key, $default));
|
||||
if ($value === null) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return $enumClass::tryFrom($value) ?? $default;
|
||||
}
|
||||
|
||||
public function has(EnvKey|string $key): bool
|
||||
@@ -100,8 +116,8 @@ final readonly class Environment
|
||||
public function all(): array
|
||||
{
|
||||
return array_merge(
|
||||
$_ENV,
|
||||
$_SERVER,
|
||||
#$_ENV,
|
||||
#$_SERVER,
|
||||
$this->variables
|
||||
);
|
||||
}
|
||||
@@ -111,43 +127,12 @@ final readonly class Environment
|
||||
*/
|
||||
public static function fromFile(FilePath|string $envPath): self
|
||||
{
|
||||
$variables = [];
|
||||
$filePath = $envPath instanceof FilePath ? $envPath : FilePath::create($envPath);
|
||||
|
||||
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, '=')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
[$name, $value] = explode('=', $line, 2);
|
||||
$name = trim($name);
|
||||
$value = trim($value);
|
||||
|
||||
// Remove quotes
|
||||
if (str_starts_with($value, '"') && str_ends_with($value, '"')) {
|
||||
$value = substr($value, 1, -1);
|
||||
}
|
||||
|
||||
$variables[$name] = self::castValue($value);
|
||||
}
|
||||
}
|
||||
$parser = new EnvFileParser();
|
||||
$variables = $parser->parse($envPath);
|
||||
|
||||
return new self($variables);
|
||||
}
|
||||
|
||||
private static function castValue(string $value): mixed
|
||||
{
|
||||
return match (strtolower($value)) {
|
||||
'true' => true,
|
||||
'false' => false,
|
||||
'null' => null,
|
||||
default => is_numeric($value) ? (str_contains($value, '.') ? (float) $value : (int) $value) : $value
|
||||
};
|
||||
}
|
||||
|
||||
public function keyToString(EnvKey|string $key): string
|
||||
{
|
||||
if (is_string($key)) {
|
||||
|
||||
Reference in New Issue
Block a user