CredentialService.php

Code Hygiene Score: 100

Keine Issues gefunden.

Dependencies 1

Klassen 1

Funktionen 9

Verwendet von 8

Versionen 4

Code

<?php

declare(strict_types=1);

namespace Infrastructure\Config;

// @responsibility: Zentrales Credential-Management aus Environment-Variablen

use RuntimeException;

final class CredentialService
{
    /**
     * Gets the MariaDB host.
     */
    public static function getMariaDbHost(): string
    {
        return self::get('MARIADB_HOST', 'localhost');
    }

    /**
     * Gets the MariaDB user.
     */
    public static function getMariaDbUser(): string
    {
        return self::get('MARIADB_USER', 'root');
    }

    /**
     * Gets the MariaDB root password.
     */
    public static function getMariaDbPassword(): string
    {
        return self::getRequired('MARIADB_ROOT_PASSWORD');
    }

    /**
     * Gets the Anthropic API key.
     */
    public static function getAnthropicApiKey(): string
    {
        return self::getRequired('ANTHROPIC_API_KEY');
    }

    /**
     * Gets the Ollama host URL.
     */
    public static function getOllamaHost(): string
    {
        return self::get('OLLAMA_HOST', 'http://localhost:11434');
    }

    /**
     * Gets the Qdrant host URL.
     */
    public static function getQdrantHost(): string
    {
        return self::get('QDRANT_HOST', 'http://localhost:6333');
    }

    /**
     * Gets the credentials file path.
     */
    public static function getCredentialsFilePath(): string
    {
        return self::get('CREDENTIALS_FILE_PATH', '/var/www/docs/credentials/credentials.md');
    }

    /**
     * Gets an environment variable with a default value.
     */
    public static function get(string $key, string $default = ''): string
    {
        return $_ENV[$key] ?? $_SERVER[$key] ?? getenv($key) ?: $default;
    }

    /**
     * Gets a required environment variable.
     *
     * @throws RuntimeException If the variable is not set
     */
    public static function getRequired(string $key): string
    {
        $value = self::get($key);

        if ($value === '') {
            throw new RuntimeException("Required environment variable not set: {$key}");
        }

        return $value;
    }
}
← Übersicht Graph