Ejemplo n.º 1
0
 /**
  * 获取Service配置
  *
  * @param string $key 支持使用“::”分隔的关键词,最多支持4级(e.g. http::exes::Payment_Balance::path)
  * @param bool $includeDefault
  *
  * @return array|bool|null
  *
  * @throws Exception
  */
 public static function get($key, $includeDefault = true)
 {
     // 初始化配置信息
     if (is_null(self::$config)) {
         $config = APF::get_instance()->get_config(null, 'service');
         self::$config = $config ? $config : array();
     }
     // 获取配置信息
     if (strpos($key, '::') === false) {
         return isset(self::$config[$key]) ? self::$config[$key] : array();
     } else {
         $parts = explode('::', $key);
         switch (count($parts)) {
             case 2:
                 $config = isset(self::$config[$parts[0]][$parts[1]]) ? self::$config[$parts[0]][$parts[1]] : array();
                 // xxx::yyy
                 // 默认配置
                 if ($includeDefault) {
                     if ($parts[1] != 'default') {
                         $rawConfigs[] = isset(self::$config[$parts[0]]['default']) ? self::$config[$parts[0]]['default'] : array();
                         // xxx::default
                     }
                     $rawConfigs[] = self::get('default', $includeDefault);
                     // default
                     // 拼装配置
                     foreach ($rawConfigs as $rawConfig) {
                         if (!is_null($rawConfig)) {
                             $config = array_merge($rawConfig, $config);
                         }
                     }
                 }
                 return $config;
                 break;
             case 3:
                 $config = isset(self::$config[$parts[0]][$parts[1]][$parts[2]]) ? self::$config[$parts[0]][$parts[1]][$parts[2]] : array();
                 // xxx::yyy::zzz
                 // 默认配置
                 if ($includeDefault) {
                     if ($parts[2] != 'default') {
                         $rawConfigs[] = isset(self::$config[$parts[0]][$parts[1]]['default']) ? self::$config[$parts[0]][$parts[1]]['default'] : array();
                         // xxx::yyy::default
                     }
                     $rawConfigs[] = self::get($parts[0] . self::SEPARATOR . 'default', $includeDefault);
                     // xxx::default
                     // 拼装配置
                     foreach ($rawConfigs as $rawConfig) {
                         $config = array_merge($rawConfig, $config);
                     }
                 }
                 return $config;
                 break;
             case 4:
                 $suffixKey = array_pop($parts);
                 $config = self::get(implode('::', $parts), $includeDefault);
                 // xxx:yyy:zzz
                 return isset($config[$suffixKey]) ? $config[$suffixKey] : null;
                 break;
             default:
                 throw new Exception('不合法的Key');
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * 获取配置
  *
  * @return array|bool|null
  */
 public function getConfig($includeDefault = false)
 {
     $config = Bll_Service_Config::get($this->getConfigKey(), $includeDefault);
     if (!$config) {
         $config = array();
     }
     return $config;
 }