diff --git a/src/app/config/ProfileManager.php b/src/app/config/ProfileManager.php index e479334..b30d71e 100644 --- a/src/app/config/ProfileManager.php +++ b/src/app/config/ProfileManager.php @@ -1,31 +1,49 @@ true, "test" => true, ]; + + /** + * @var array mapping profil d'application --> profil effectif + * + * ce mapping est utilisé quand il faut calculer le profil courant s'il n'a + * pas été spécifié par l'utilisateur. il permet de faire correspondre le + * profil courant de l'application avec le profil effectif à sélectionner + */ const PROFILE_MAP = null; function __construct(?array $params=null) { + $this->isAppProfile = $params["app"] ?? false; $this->profiles = static::PROFILES; - $this->production_modes = static::PRODUCTION_MODES; - $appProfile = $params["app"] ?? false; + $this->productionModes = static::PRODUCTION_MODES; + $this->profileMap = static::PROFILE_MAP; $name = $params["name"] ?? static::NAME; $configKey = "${name}_profile"; $envKey = strtoupper($configKey); - if ($appProfile) { + if ($this->isAppProfile) { $this->envKeys = [$envKey, "APP_PROFILE"]; } else { $this->configKey = $configKey; @@ -33,21 +51,26 @@ class ProfileManager { } } + /** + * @var bool cet objet est-il utilisé pour gérer le profil de l'application? + */ + protected bool $isAppProfile; + protected ?array $profiles; protected ?array $productionModes; - function mapProfile(?string $profile): ?string { - return static::PROFILE_MAP[$profile] ?? $profile; + protected ?array $profileMap; + + protected function mapProfile(?string $profile): ?string { + return $this->profileMap[$profile] ?? $profile; } protected ?string $configKey = null; function getConfigProfile(): ?string { if ($this->configKey === null) return null; - $profile = config::k($this->configKey); - $profile = $this->mapProfile($profile); - return $profile; + return config::k($this->configKey); } protected array $envKeys = []; @@ -78,7 +101,11 @@ class ProfileManager { $profile ??= $this->getenvProfile(); $profile ??= $this->getConfigProfile(); $profile ??= $this->getDefaultProfile(); - $profile ??= $this->profiles[0] ?? "prod"; + if ($this->isAppProfile) { + $profile ??= $this->profiles[0] ?? "prod"; + } else { + $profile ??= $this->mapProfile(app::get_profile()); + } $this->profile = $profile; $this->productionMode = $this->productionModes[$profile] ?? false; }