Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jcy2004x
ShopXO
提交
1d7491b4
ShopXO
项目概览
jcy2004x
/
ShopXO
与 Fork 源项目一致
Fork自
纵之格 / ShopXO
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
ShopXO
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
1d7491b4
编写于
8月 07, 2021
作者:
D
Devil
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
读取配置优化、减少IO读取次数
上级
2318b106
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
65 addition
and
17 deletion
+65
-17
app/common.php
app/common.php
+65
-17
未找到文件。
app/common.php
浏览文件 @
1d7491b4
...
...
@@ -40,6 +40,20 @@ function MySession($name = '', $value = '')
*/
function
MyCache
(
$name
=
null
,
$value
=
''
,
$options
=
null
,
$tag
=
null
)
{
// 静态存储、不用每次都从磁盘读取
static
$object_cache
=
[];
// 读取数据
if
(
$value
===
''
)
{
if
(
!
array_key_exists
(
$name
,
$object_cache
))
{
$object_cache
[
$name
]
=
cache
(
$name
,
$value
,
$options
,
$tag
);
}
return
$object_cache
[
$name
];
}
// 设置数据
return
cache
(
$name
,
$value
,
$options
,
$tag
);
}
...
...
@@ -55,7 +69,13 @@ function MyCache($name = null, $value = '', $options = null, $tag = null)
*/
function
MyEnv
(
$key
,
$val
=
null
)
{
return
env
(
$key
,
$val
);
// 静态存储、不用每次都从磁盘读取
static
$object_env
=
[];
if
(
!
array_key_exists
(
$key
,
$object_env
))
{
$object_env
[
$key
]
=
env
(
$key
,
$val
);
}
return
$object_env
[
$key
];
}
/**
...
...
@@ -69,7 +89,13 @@ function MyEnv($key, $val = null)
*/
function
MyConfig
(
$key
)
{
return
config
(
$key
);
// 静态存储、不用每次都从磁盘读取
static
$object_config
=
[];
if
(
!
array_key_exists
(
$key
,
$object_config
))
{
$object_config
[
$key
]
=
config
(
$key
);
}
return
$object_config
[
$key
];
}
/**
...
...
@@ -151,7 +177,12 @@ function MyView($view = '', $data = [])
*/
function
RequestModule
()
{
return
strtolower
(
app
(
'http'
)
->
getName
());
static
$request_module
=
null
;
if
(
$request_module
===
null
)
{
$request_module
=
strtolower
(
app
(
'http'
)
->
getName
());
}
return
$request_module
;
}
/**
...
...
@@ -164,7 +195,12 @@ function RequestModule()
*/
function
RequestController
()
{
return
strtolower
(
request
()
->
controller
());
static
$request_controller
=
null
;
if
(
$request_controller
===
null
)
{
$request_controller
=
strtolower
(
request
()
->
controller
());
}
return
$request_controller
;
}
/**
...
...
@@ -177,7 +213,12 @@ function RequestController()
*/
function
RequestAction
()
{
return
strtolower
(
request
()
->
action
());
static
$request_action
=
null
;
if
(
$request_action
===
null
)
{
$request_action
=
strtolower
(
request
()
->
action
());
}
return
$request_action
;
}
/**
...
...
@@ -334,7 +375,9 @@ function GetUrlHost($url)
*/
function
MyFileConfig
(
$key
,
$value
=
''
,
$default
=
null
,
$mandatory
=
false
)
{
static
$fileConfigCache
=
[];
// 静态存储、不用每次都从磁盘读取
static
$object_file_cache_config
=
[];
// 目录不存在则创建
$config_dir
=
ROOT
.
'runtime'
.
DS
.
'data'
.
DS
.
'config_data'
.
DS
;
\
base\FileUtil
::
CreateDir
(
$config_dir
);
...
...
@@ -350,23 +393,23 @@ function MyFileConfig($key, $value = '', $default = null, $mandatory = false)
// 读内容
if
(
$value
===
''
)
{
$value
=
$fileConfigCache
[
$file
]
??
''
;
if
(
$value
)
{
return
$value
;
}
$value
=
file_exists
(
$file
)
?
unserialize
(
file_get_contents
(
$file
))
:
$default
;
if
(
$mandatory
===
true
)
if
(
!
array_key_exists
(
$key
,
$object_file_cache_config
))
{
if
(
empty
(
$value
))
$value
=
file_exists
(
$file
)
?
unserialize
(
file_get_contents
(
$file
))
:
$default
;
if
(
$mandatory
===
true
)
{
$value
=
$default
;
if
(
empty
(
$value
))
{
$value
=
$default
;
}
}
$object_file_cache_config
[
$key
]
=
$value
;
}
else
{
$value
=
$object_file_cache_config
[
$key
];
}
$fileConfigCache
[
$file
]
=
$value
;
return
$value
;
// 写内容
}
else
{
$fileConfigCache
[
$file
]
=
$value
;
// 目录是否有可写权限
if
(
!
is_writable
(
$config_dir
))
{
...
...
@@ -380,7 +423,12 @@ function MyFileConfig($key, $value = '', $default = null, $mandatory = false)
}
// 存储内容
return
(
file_put_contents
(
$file
,
serialize
(
$value
))
!==
false
);
if
(
file_put_contents
(
$file
,
serialize
(
$value
))
!==
false
)
{
$object_file_cache_config
[
$key
]
=
$value
;
return
true
;
}
return
false
;
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录