server=$mainConfig['params']['apollo']['server']; $this->appId=$mainConfig['params']['apollo']['appId']; $this->cluster=$YII_ENV; //配置中心集群,对应本地环境 //集群 if ($YII_ENV == 'development') { $this->cluster = 'dev'; } //集群 if ($YII_ENV == 'production') { $this->cluster = 'default'; } $this->nameSpaces = $mainConfig['params']['apollo']['nameSpace']; //配置文件存储路径 $configFile=dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'cache'; //公共配置路径 $publicConfigPath = dirname(__FILE__) .'/../config/'; $apollo = new ApolloClient($this->server, $this->appId, $this->nameSpaces,$this->cluster,$configFile,$publicConfigPath); $apollo->start(); } //读取Yaml格式配置 public function actionTask($YII_ENV='development'){ //读取apollo配置 $mainConfig=require dirname(__FILE__) .'/../config/main.'. $YII_ENV .'.php'; $this->server=$mainConfig['params']['apolloYaml']['server']; $this->appId=$mainConfig['params']['apolloYaml']['appId']; $this->cluster=$YII_ENV; //配置中心集群,对应本地环境 //集群 if ($YII_ENV == 'production') { $this->cluster = 'default'; } $this->nameSpaces = $mainConfig['params']['apolloYaml']['nameSpace']; //配置文件存储路径 $configFile=dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'cache'; //公共配置路径 $publicConfigPath = dirname(__FILE__) .'/../config/'; $apollo = new ApolloClient($this->server, $this->appId, $this->nameSpaces,$this->cluster,$configFile,$publicConfigPath); $apollo->start(); } }