From 746f03b97a6e3e91d5cc1b973da39769f48abc85 Mon Sep 17 00:00:00 2001 From: lkeme <1462364497@qq.com> Date: Sun, 22 Aug 2021 21:19:39 +0800 Subject: [PATCH] [fix] Cache fixes #114 --- .gitignore | 2 +- log/.gitkeep | 3 +++ src/core/Cache.php | 31 ++++++++++++++++++++++++------- task/.gitkeep | 3 +++ 4 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 log/.gitkeep diff --git a/.gitignore b/.gitignore index 6a1d449..2187541 100644 --- a/.gitignore +++ b/.gitignore @@ -26,13 +26,13 @@ conf/user1.ini /conf/user.ini /conf/test.ini /conf/test1.ini -/log/ /src/backup/ script.php # ignore all files in lib/ task/* cache/* +log/* # except for .gitkeep !.gitkeep # ignore TODO file in root directory,not subdir/TODO diff --git a/log/.gitkeep b/log/.gitkeep new file mode 100644 index 0000000..a10d4fe --- /dev/null +++ b/log/.gitkeep @@ -0,0 +1,3 @@ +# Ignore everything in this directory +* +# Except this file !.gitkeep \ No newline at end of file diff --git a/src/core/Cache.php b/src/core/Cache.php index 7ce2ebf..27adda0 100644 --- a/src/core/Cache.php +++ b/src/core/Cache.php @@ -36,11 +36,13 @@ class Cache if (!isset($this->caches[$classname])) { // 如果不存在缓存 初始化 "BHP_username_APP.dat" $this->caches[$classname] = new Flintstone( - 'BHP_' . getConf('username', 'login.account') . '_' . $classname, [ - 'dir' => APP_CACHE_PATH, - 'gzip' => true, - 'formatter' => new JsonFormatter() - ]); + $this->removeSpecStr('BHP_' . getConf('username', 'login.account') . '_' . $classname), + [ + 'dir' => APP_CACHE_PATH, + 'gzip' => true, + 'formatter' => new JsonFormatter() + ] + ); } $this->cache = $this->caches[$classname]; return $this; @@ -72,7 +74,6 @@ class Cache return $this->load($classname); } - /** * @use 获取值 * @param string $key @@ -99,4 +100,20 @@ class Cache // $users->set('bob', ['email' => 'bob@site.com', 'password' => '123456']); $this->getClassObj($extra_name)->cache->set($key, $data); } -} \ No newline at end of file + + /** + * @use 去除特殊符号 + * @param string $data + * @return string + */ + private function removeSpecStr(string $data): string + { + $specs = str_split(".,:;'*?~`!@#$%^&+=)(<>{}]|\/、"); + foreach ($specs as $spec) { + $data = str_replace($spec, '', $data); + } + return $data; + } +} + + diff --git a/task/.gitkeep b/task/.gitkeep index e69de29..a10d4fe 100644 --- a/task/.gitkeep +++ b/task/.gitkeep @@ -0,0 +1,3 @@ +# Ignore everything in this directory +* +# Except this file !.gitkeep \ No newline at end of file