feat: Version 3.3.4 - Nouvelle architecture pages, optimisations widgets Flutter et API
- Mise à jour VERSION vers 3.3.4 - Optimisations et révisions architecture API (deploy-api.sh, scripts de migration) - Ajout documentation Stripe Tap to Pay complète - Migration vers polices Inter Variable pour Flutter - Optimisations build Android et nettoyage fichiers temporaires - Amélioration système de déploiement avec gestion backups - Ajout scripts CRON et migrations base de données 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
89
bao/config/database.php
Normal file
89
bao/config/database.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Configuration de la base de données pour BAO
|
||||
* Charge les paramètres depuis le fichier .env
|
||||
*/
|
||||
class DatabaseConfig {
|
||||
private static ?self $instance = null;
|
||||
private array $config;
|
||||
|
||||
private function __construct() {
|
||||
$this->loadEnv();
|
||||
}
|
||||
|
||||
public static function getInstance(): self {
|
||||
if (self::$instance === null) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
private function loadEnv(): void {
|
||||
$envPath = __DIR__ . '/.env';
|
||||
|
||||
if (!file_exists($envPath)) {
|
||||
throw new RuntimeException("Fichier .env introuvable. Copiez .env.example vers .env et configurez-le.");
|
||||
}
|
||||
|
||||
$lines = file($envPath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
foreach ($lines as $line) {
|
||||
// Ignorer les commentaires
|
||||
if (strpos(trim($line), '#') === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Parser les variables
|
||||
if (strpos($line, '=') !== false) {
|
||||
list($key, $value) = explode('=', $line, 2);
|
||||
$key = trim($key);
|
||||
$value = trim($value);
|
||||
$this->config[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function get(string $key, $default = null) {
|
||||
return $this->config[$key] ?? $default;
|
||||
}
|
||||
|
||||
public function getEncryptionKey(): string {
|
||||
$key = $this->get('ENCRYPTION_KEY');
|
||||
if (empty($key)) {
|
||||
throw new RuntimeException("ENCRYPTION_KEY manquante dans .env");
|
||||
}
|
||||
return $key;
|
||||
}
|
||||
|
||||
public function getEnvironmentConfig(string $env): array {
|
||||
$env = strtoupper($env);
|
||||
|
||||
$enabled = $this->get("{$env}_ENABLED", 'false');
|
||||
if ($enabled !== 'true') {
|
||||
throw new RuntimeException("Environnement {$env} désactivé dans .env");
|
||||
}
|
||||
|
||||
return [
|
||||
'use_vpn' => $this->get("{$env}_USE_VPN", 'false') === 'true',
|
||||
'ssh_host' => $this->get("{$env}_SSH_HOST"),
|
||||
'ssh_port_local' => (int)$this->get("{$env}_SSH_PORT_LOCAL"),
|
||||
'host' => $this->get("{$env}_DB_HOST"),
|
||||
'port' => (int)$this->get("{$env}_DB_PORT"),
|
||||
'name' => $this->get("{$env}_DB_NAME"),
|
||||
'user' => $this->get("{$env}_DB_USER"),
|
||||
'pass' => $this->get("{$env}_DB_PASS"),
|
||||
];
|
||||
}
|
||||
|
||||
public function getAvailableEnvironments(): array {
|
||||
$envs = [];
|
||||
foreach (['DEV', 'REC', 'PROD'] as $env) {
|
||||
if ($this->get("{$env}_ENABLED") === 'true') {
|
||||
$envs[] = $env;
|
||||
}
|
||||
}
|
||||
return $envs;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user