Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
services
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tencent
services
Commits
017a99d2
Commit
017a99d2
authored
Jul 13, 2019
by
王召彬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
配置中心读取配置支持默认值和返回类型
parent
f6b4cf0b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
2 deletions
+21
-2
src/Common/Config/CfgCenter.php
+21
-2
No files found.
src/Common/Config/CfgCenter.php
View file @
017a99d2
...
...
@@ -17,9 +17,26 @@ class CfgCenter
* var_dump($cfgdata->Weapp->Region); // 输出:ap-shanghai
*
* @param string $keyStr
* @param string $default 默认返回值
* @param int $retype retype==1返回对象,retype==2返回数组
* @return mixed
*/
public
static
function
get
(
$keyStr
)
public
static
function
get
(
$keyStr
,
$default
=
''
,
$retype
=
1
)
{
$data
=
self
::
_get
(
$keyStr
);
if
(
$data
==
''
)
{
return
$default
;
}
if
(
$retype
!=
1
)
{
// retype==1返回对象,retype==2返回数组
$dataArr
=
json_decode
(
$data
,
true
);
if
(
is_array
(
$dataArr
))
{
return
$dataArr
;
}
}
return
$data
;
}
private
static
function
_get
(
$keyStr
)
{
$keyArr
=
self
::
parseKeyStr
(
$keyStr
);
$rkey
=
implode
(
":"
,
$keyArr
);
...
...
@@ -48,7 +65,9 @@ class CfgCenter
{
$keyArr
=
self
::
parseKeyStr
(
$keyStr
);
$name
=
array_shift
(
$keyArr
);
$result
=
self
::
dbConnect
()
->
select
(
"config"
,
[
'name'
,
'value'
],
[
'name'
=>
$name
]);
$dbConn
=
self
::
dbConnect
();
$result
=
$dbConn
->
select
(
"config"
,
[
'name'
,
'value'
],
[
'name'
=>
$name
]);
$dbConn
->
action
(
function
(
$dbConn
){});
if
(
!
isset
(
$result
[
0
][
'value'
]))
{
return
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment