diff --git a/src/Constant/Env.php b/src/Constant/Env.php index 235517b..1bf1ed6 100644 --- a/src/Constant/Env.php +++ b/src/Constant/Env.php @@ -12,6 +12,21 @@ class Env const APOLLO_META_SERVER = 'APOLLO_METASERVER'; - const APOLLO_FILE = '/tmp/apollo_all.yaml'; + const APOLLO_FILE_CLOUD = '/tmp/apollo_all.yaml'; + const APOLLO_FILE_LOCAL = '/env.local.yaml'; + + + public static function getApolloFile(): string + { + if (isset($_SERVER['YOUZAN_ENV']) && !empty($_SERVER['YOUZAN_ENV'])) { + return self::APOLLO_FILE_CLOUD; + } + + if (defined('YZCLOUD_BOOT_APP_DIR') && file_exists(YZCLOUD_BOOT_APP_DIR . self::APOLLO_FILE_LOCAL)) { + return YZCLOUD_BOOT_APP_DIR . self::APOLLO_FILE_LOCAL; + } + + return self::APOLLO_FILE_CLOUD; + } } \ No newline at end of file diff --git a/src/Util/ApolloUtil.php b/src/Util/ApolloUtil.php index 6e5d535..8f2874e 100644 --- a/src/Util/ApolloUtil.php +++ b/src/Util/ApolloUtil.php @@ -32,7 +32,7 @@ public function writeToFile($reties = 3) } // write to file - $res = file_put_contents(Env::APOLLO_FILE, Yaml::dump($configAll)); + $res = file_put_contents(Env::getApolloFile(), Yaml::dump($configAll)); if (false === $res) { LogFacade::warn("Apollo writeToFile. write return false"); return $this->writeToFile(--$reties); diff --git a/src/Util/EnvUtil.php b/src/Util/EnvUtil.php index 1f281ea..6cb0a23 100644 --- a/src/Util/EnvUtil.php +++ b/src/Util/EnvUtil.php @@ -32,9 +32,9 @@ public function get(string $varName): ?string private function getFromApollo(string $varName): ?string { - if (empty($this->apolloConfig) && file_exists(Env::APOLLO_FILE)) { + if (empty($this->apolloConfig) && file_exists(Env::getApolloFile())) { try { - $this->apolloConfig = Yaml::parseFile(Env::APOLLO_FILE); + $this->apolloConfig = Yaml::parseFile(Env::getApolloFile()); } catch (\Exception $e) { }