Commit 34e5a12c by 王召彬

Merge branch 'fixbug-cfgcenter' into test

parents 89bfbccb c8d90818
...@@ -7,7 +7,7 @@ class CfgCenter ...@@ -7,7 +7,7 @@ class CfgCenter
{ {
/** /**
* 读取指定的配置项 * 读取指定的配置项 - 返回对象格式
* (所有配置项,需预先添加到数据库中) * (所有配置项,需预先添加到数据库中)
* 方法一: * 方法一:
* $value = CfgCenter::get('qCloud>Weapp>Region'); * $value = CfgCenter::get('qCloud>Weapp>Region');
...@@ -18,20 +18,39 @@ class CfgCenter ...@@ -18,20 +18,39 @@ class CfgCenter
* *
* @param string $keyStr * @param string $keyStr
* @param string $default 默认返回值 * @param string $default 默认返回值
* @param int $retype retype==1返回对象,retype==2返回数组
* @return mixed * @return mixed
*/ */
public static function get($keyStr, $default='', $retype=1) public static function get($keyStr, $default='')
{ {
$data = self::_get($keyStr); $data = self::_get($keyStr);
if($data == '') { if($data == '') {
return $default; return $default;
} }
if($retype != 1) { // retype==1返回对象,retype==2返回数组 return $data;
$dataArr = json_decode($data, true); }
if(is_array($dataArr)) {
return $dataArr; /**
* 读取指定的配置项 - 返回数组格式
* (所有配置项,需预先添加到数据库中)
* 方法一:
* $value = CfgCenter::get('qCloud>Weapp>Region');
* var_dump($value); // 输出:ap-shanghai
* 方法二:
* $cfgdata = CfgCenter::get('qCloud');
* var_dump($cfgdata['Weapp']['Region']); // 输出:ap-shanghai
*
* @param string $keyStr
* @param string $default 默认返回值
* @return mixed
*/
public static function getArray($keyStr, $default='')
{
$data = self::_get($keyStr);
if($data == '') {
return $default;
} }
if(is_object($data)) {
return json_decode(json_encode($data), true);
} }
return $data; return $data;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment