@@ -4,8 +4,8 @@ discard block |
||
4 | 4 | * 文件操作类 |
5 | 5 | * logFilePath: /storage/tinymeng/log/ |
6 | 6 | */ |
7 | -define('logFilePath',dirname(dirname(dirname(dirname(__DIR__)))).DIRECTORY_SEPARATOR.'storage'.DIRECTORY_SEPARATOR.'tinymeng'.DIRECTORY_SEPARATOR.'log'.DIRECTORY_SEPARATOR); |
|
8 | -class File{ |
|
7 | +define('logFilePath', dirname(dirname(dirname(dirname(__DIR__)))).DIRECTORY_SEPARATOR.'storage'.DIRECTORY_SEPARATOR.'tinymeng'.DIRECTORY_SEPARATOR.'log'.DIRECTORY_SEPARATOR); |
|
8 | +class File { |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Name: writeLog |
@@ -16,26 +16,26 @@ discard block |
||
16 | 16 | * @param \Exception|null $exception |
17 | 17 | * @return bool |
18 | 18 | */ |
19 | - static public function writeLog($message, $file_name='error',bool $echo = false,\Exception $exception = null){ |
|
20 | - if(!is_string($message)){ |
|
19 | + static public function writeLog($message, $file_name = 'error', bool $echo = false, \Exception $exception = null) { |
|
20 | + if (!is_string($message)) { |
|
21 | 21 | $message = json_encode($message); |
22 | 22 | } |
23 | 23 | $message = date('Y-m-d H:i:s').' : '.$message.PHP_EOL; |
24 | - if($exception && $exception instanceof \Exception){ |
|
24 | + if ($exception && $exception instanceof \Exception) { |
|
25 | 25 | $message .= ' File: '.$exception->getFile().' ,Line: '.$exception->getLine().' ,Message: '.$exception->getMessage(); |
26 | 26 | } |
27 | - if($echo){ |
|
27 | + if ($echo) { |
|
28 | 28 | echo $message; |
29 | 29 | } |
30 | 30 | $path = logFilePath; |
31 | 31 | if (!is_dir($path)) { |
32 | - if(!mkdir($path, 0755, true)){ |
|
32 | + if (!mkdir($path, 0755, true)) { |
|
33 | 33 | die('创建缓存文件夹"'.$path.'"失败!'); |
34 | 34 | } |
35 | 35 | } |
36 | 36 | |
37 | 37 | $file_name = $path.$file_name; |
38 | - self::filePutContents($file_name."-".date('Ymd',time()).".log",$message,true); |
|
38 | + self::filePutContents($file_name."-".date('Ymd', time()).".log", $message, true); |
|
39 | 39 | return true; |
40 | 40 | } |
41 | 41 | |
@@ -48,10 +48,10 @@ discard block |
||
48 | 48 | * file_put_contents和fopen,fwrite,fclose三个组合的区别 |
49 | 49 | * http://blog.majiameng.com/article/2724.html |
50 | 50 | */ |
51 | - static public function filePutContents(string $file_name,string $content,bool $file_append = false){ |
|
52 | - if(strrpos($file_name,'/')){ |
|
51 | + static public function filePutContents(string $file_name, string $content, bool $file_append = false) { |
|
52 | + if (strrpos($file_name, '/')) { |
|
53 | 53 | //获取文件夹路径 |
54 | - $dir_name = substr($file_name,0,strrpos($file_name,'/')); |
|
54 | + $dir_name = substr($file_name, 0, strrpos($file_name, '/')); |
|
55 | 55 | //创建文件夹 |
56 | 56 | self::mkdir($dir_name); |
57 | 57 | } |
@@ -60,10 +60,10 @@ discard block |
||
60 | 60 | self::chmod($file_name); |
61 | 61 | |
62 | 62 | //内容写入文件 |
63 | - if($file_append === false){ |
|
64 | - file_put_contents($file_name,$content); |
|
65 | - }else{ |
|
66 | - file_put_contents($file_name,$content,FILE_APPEND); |
|
63 | + if ($file_append === false) { |
|
64 | + file_put_contents($file_name, $content); |
|
65 | + } else { |
|
66 | + file_put_contents($file_name, $content, FILE_APPEND); |
|
67 | 67 | } |
68 | 68 | } |
69 | 69 | |
@@ -76,10 +76,10 @@ discard block |
||
76 | 76 | * file_put_contents和fopen,fwrite,fclose三个组合的区别 |
77 | 77 | * http://blog.majiameng.com/article/2724.html |
78 | 78 | */ |
79 | - static public function fWrite(string $file_name,string $content,bool $file_append = false){ |
|
80 | - if(strrpos($file_name,'/')){ |
|
79 | + static public function fWrite(string $file_name, string $content, bool $file_append = false) { |
|
80 | + if (strrpos($file_name, '/')) { |
|
81 | 81 | //获取文件夹路径 |
82 | - $dir_name = substr($file_name,0,strrpos($file_name,'/')); |
|
82 | + $dir_name = substr($file_name, 0, strrpos($file_name, '/')); |
|
83 | 83 | //创建文件夹 |
84 | 84 | self::mkdir($dir_name); |
85 | 85 | } |
@@ -88,11 +88,11 @@ discard block |
||
88 | 88 | self::chmod($file_name); |
89 | 89 | |
90 | 90 | //内容写入文件 |
91 | - if($file_append === false){ |
|
91 | + if ($file_append === false) { |
|
92 | 92 | $handle = fopen($file_name, 'w'); |
93 | 93 | fwrite($handle, $content); |
94 | 94 | fclose($handle); |
95 | - }else{ |
|
95 | + } else { |
|
96 | 96 | $handle = fopen($file_name, 'a'); |
97 | 97 | fwrite($handle, $content); |
98 | 98 | fclose($handle); |
@@ -106,9 +106,9 @@ discard block |
||
106 | 106 | * @param $dir_name |
107 | 107 | * @return bool |
108 | 108 | */ |
109 | - static public function mkdir(string $dir_name){ |
|
109 | + static public function mkdir(string $dir_name) { |
|
110 | 110 | if (!is_dir($dir_name)) { |
111 | - if(!mkdir($dir_name, 0755, true)){ |
|
111 | + if (!mkdir($dir_name, 0755, true)) { |
|
112 | 112 | die('创建缓存文件夹"'.$dir_name.'"失败!'); |
113 | 113 | } |
114 | 114 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | * @return bool |
123 | 123 | */ |
124 | 124 | static public function delDir(string $dir) { |
125 | - if(!file_exists($dir)){//文件不存在 |
|
125 | + if (!file_exists($dir)) {//文件不存在 |
|
126 | 126 | return true; |
127 | 127 | } |
128 | 128 | if (!is_dir($dir)) { |
@@ -133,9 +133,9 @@ discard block |
||
133 | 133 | //先删除目录下的文件 |
134 | 134 | $dh = opendir($dir); |
135 | 135 | while ($file = readdir($dh)) { |
136 | - if($file != "." && $file!="..") { |
|
136 | + if ($file != "." && $file != "..") { |
|
137 | 137 | $full_path = $dir."/".$file; |
138 | - if(!is_dir($full_path)) { |
|
138 | + if (!is_dir($full_path)) { |
|
139 | 139 | unlink($full_path); |
140 | 140 | } else { |
141 | 141 | self::delDir($full_path); |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | closedir($dh); |
146 | 146 | |
147 | 147 | //删除当前文件夹: |
148 | - if(rmdir($dir)) { |
|
148 | + if (rmdir($dir)) { |
|
149 | 149 | return true; |
150 | 150 | } else { |
151 | 151 | return false; |
@@ -158,9 +158,9 @@ discard block |
||
158 | 158 | * @param $file_name |
159 | 159 | * @param int $mode |
160 | 160 | */ |
161 | - static public function chmod($file_name,$mode = 0755){ |
|
162 | - if (file_exists($file_name)){ |
|
163 | - @chmod($file_name,$mode); |
|
161 | + static public function chmod($file_name, $mode = 0755) { |
|
162 | + if (file_exists($file_name)) { |
|
163 | + @chmod($file_name, $mode); |
|
164 | 164 | } |
165 | 165 | } |
166 | 166 | |
@@ -174,14 +174,14 @@ discard block |
||
174 | 174 | static public function move(string $file, string $new_file): bool |
175 | 175 | { |
176 | 176 | //文件是否存在 |
177 | - if(!file_exists($file)){ |
|
177 | + if (!file_exists($file)) { |
|
178 | 178 | return false; |
179 | 179 | } |
180 | 180 | |
181 | 181 | //新文件目录 |
182 | - if(strrpos($new_file,'/')){ |
|
182 | + if (strrpos($new_file, '/')) { |
|
183 | 183 | //获取文件夹路径 |
184 | - $dir_name = substr($new_file,0,strrpos($new_file,'/')); |
|
184 | + $dir_name = substr($new_file, 0, strrpos($new_file, '/')); |
|
185 | 185 | //创建文件夹 |
186 | 186 | self::mkdir($dir_name); |
187 | 187 | } |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | //添加文件权限 |
190 | 190 | self::chmod($dir_name); |
191 | 191 | |
192 | - copy($file,$new_file); //拷贝到新目录 |
|
192 | + copy($file, $new_file); //拷贝到新目录 |
|
193 | 193 | unlink($file); //删除旧目录下的文件 |
194 | 194 | |
195 | 195 | return true; |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | //内容写入文件 |
63 | 63 | if($file_append === false){ |
64 | 64 | file_put_contents($file_name,$content); |
65 | - }else{ |
|
65 | + } else{ |
|
66 | 66 | file_put_contents($file_name,$content,FILE_APPEND); |
67 | 67 | } |
68 | 68 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | $handle = fopen($file_name, 'w'); |
93 | 93 | fwrite($handle, $content); |
94 | 94 | fclose($handle); |
95 | - }else{ |
|
95 | + } else{ |
|
96 | 96 | $handle = fopen($file_name, 'a'); |
97 | 97 | fwrite($handle, $content); |
98 | 98 | fclose($handle); |
@@ -110,7 +110,7 @@ |
||
110 | 110 | if ($len <= $split_len) { |
111 | 111 | return array($str); |
112 | 112 | } |
113 | - preg_match_all('/.{' . $split_len . '}|[^\x00]{1,' . $split_len . '}$/us', $str, $ar); |
|
113 | + preg_match_all('/.{'.$split_len.'}|[^\x00]{1,'.$split_len.'}$/us', $str, $ar); |
|
114 | 114 | |
115 | 115 | return $ar[0]; |
116 | 116 | } |
@@ -40,16 +40,16 @@ discard block |
||
40 | 40 | static public function createChannelId($namespace = ''):string { |
41 | 41 | static $guid = ''; |
42 | 42 | $uid = uniqid("", true); |
43 | - $data = $namespace. md5(time() . mt_rand(1,1000000)).uniqid(); |
|
44 | - $hash = strtoupper(hash('ripemd128', $uid . $guid . md5($data))); |
|
45 | - $guid = substr($hash, 0, 8) . |
|
46 | - '-' . |
|
47 | - substr($hash, 8, 4) . |
|
48 | - '-' . |
|
49 | - substr($hash, 12, 4) . |
|
50 | - '-' . |
|
51 | - substr($hash, 16, 4) . |
|
52 | - '-' . |
|
43 | + $data = $namespace.md5(time().mt_rand(1, 1000000)).uniqid(); |
|
44 | + $hash = strtoupper(hash('ripemd128', $uid.$guid.md5($data))); |
|
45 | + $guid = substr($hash, 0, 8). |
|
46 | + '-'. |
|
47 | + substr($hash, 8, 4). |
|
48 | + '-'. |
|
49 | + substr($hash, 12, 4). |
|
50 | + '-'. |
|
51 | + substr($hash, 16, 4). |
|
52 | + '-'. |
|
53 | 53 | substr($hash, 20, 12); |
54 | 54 | return $guid; |
55 | 55 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * @return string |
63 | 63 | */ |
64 | 64 | static public function md5Bit16($str):string { |
65 | - return strtoupper(substr(md5($str),8,16)); |
|
65 | + return strtoupper(substr(md5($str), 8, 16)); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -72,13 +72,13 @@ discard block |
||
72 | 72 | * @return int |
73 | 73 | */ |
74 | 74 | static public function millisecond($time = null) :int{ |
75 | - if(empty($time)){ |
|
75 | + if (empty($time)) { |
|
76 | 76 | list($msec, $sec) = explode(' ', microtime()); |
77 | - $millisecond = (int)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); |
|
78 | - }else{ |
|
77 | + $millisecond = (int) sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); |
|
78 | + } else { |
|
79 | 79 | $millisecond = strtotime($time)."000"; |
80 | 80 | } |
81 | - return (int)$millisecond; |
|
81 | + return (int) $millisecond; |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | * @param string $string |
88 | 88 | * @return bool |
89 | 89 | */ |
90 | - public static function isContainChinese($string=''):bool { |
|
90 | + public static function isContainChinese($string = ''):bool { |
|
91 | 91 | $result = preg_match('/[\x{4e00}-\x{9fa5}]/u', $string); |
92 | 92 | return $result == 0 ? false : true; |
93 | 93 | } |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * @param string $string |
99 | 99 | * @return bool |
100 | 100 | */ |
101 | - public static function isAllChinese($string=''):bool { |
|
101 | + public static function isAllChinese($string = ''):bool { |
|
102 | 102 | $result = preg_match('/^[\x{4e00}-\x{9fa5}]+$/u', $string); |
103 | 103 | return $result == 0 ? false : true; |
104 | 104 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * @param string $string |
111 | 111 | * @return bool |
112 | 112 | */ |
113 | - public static function isMobile($string=''):bool { |
|
113 | + public static function isMobile($string = ''):bool { |
|
114 | 114 | if (!preg_match("/(^1[3|4|5|7|8][0-9]{9}$)/", $string)) { |
115 | 115 | return false; |
116 | 116 | } |
@@ -125,9 +125,9 @@ discard block |
||
125 | 125 | * @param int $double 小数点保留位数 默认3位 |
126 | 126 | * @return string |
127 | 127 | */ |
128 | - public static function sctonum($num, $double = 3){ |
|
129 | - if(false !== stripos($num, "e")){ |
|
130 | - $a = explode("e",strtolower($num)); |
|
128 | + public static function sctonum($num, $double = 3) { |
|
129 | + if (false !== stripos($num, "e")) { |
|
130 | + $a = explode("e", strtolower($num)); |
|
131 | 131 | return bcmul($a[0], bcpow(10, $a[1], $double), $double); |
132 | 132 | } |
133 | 133 | return $num; |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | * @param string $to |
142 | 142 | * @return array|false|string|string[]|null |
143 | 143 | */ |
144 | - public static function autoCharset($string, $from='gbk', $to='utf-8') { |
|
144 | + public static function autoCharset($string, $from = 'gbk', $to = 'utf-8') { |
|
145 | 145 | $from = strtoupper($from) == 'UTF8' ? 'utf-8' : $from; |
146 | 146 | $to = strtoupper($to) == 'UTF8' ? 'utf-8' : $to; |
147 | 147 | if (strtoupper($from) === strtoupper($to) || empty($string) || (is_scalar($string) && !is_string($string))) { |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | * @param $html |
178 | 178 | * @return string |
179 | 179 | */ |
180 | - public static function filterATag($html=''):string { |
|
180 | + public static function filterATag($html = ''):string { |
|
181 | 181 | return preg_replace("#<a[^>]*>(.*?)</a>#is", "$1", $html); |
182 | 182 | } |
183 | 183 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * @param $html |
189 | 189 | * @return string |
190 | 190 | */ |
191 | - public static function deleteATag($html=''):string { |
|
191 | + public static function deleteATag($html = ''):string { |
|
192 | 192 | return preg_replace("#<a[^>]*>(.*?)</a>#is", "", $html); |
193 | 193 | } |
194 | 194 | |
@@ -200,36 +200,36 @@ discard block |
||
200 | 200 | * @param bool $is_timestamp 是否是时间戳 |
201 | 201 | * @return string |
202 | 202 | */ |
203 | - public static function getTime($date,$is_timestamp=false):string { |
|
204 | - if($is_timestamp == true){ |
|
203 | + public static function getTime($date, $is_timestamp = false):string { |
|
204 | + if ($is_timestamp == true) { |
|
205 | 205 | $time = $date; |
206 | - }else{ |
|
207 | - $time = strtotime($date);//时间转换为时间戳 |
|
206 | + } else { |
|
207 | + $time = strtotime($date); //时间转换为时间戳 |
|
208 | 208 | } |
209 | 209 | |
210 | - if($time >= time()){ |
|
210 | + if ($time >= time()) { |
|
211 | 211 | return '刚刚'; |
212 | 212 | } |
213 | 213 | $seconds = time() - $time; |
214 | - if($seconds <= 60){ |
|
214 | + if ($seconds <= 60) { |
|
215 | 215 | return '刚刚'; |
216 | 216 | } |
217 | 217 | $minutes = intval($seconds / 60); |
218 | - if($minutes <= 60){ |
|
218 | + if ($minutes <= 60) { |
|
219 | 219 | return $minutes.'分钟前'; |
220 | 220 | } |
221 | 221 | $hours = intval($minutes / 60); |
222 | - if($hours <= 24){ |
|
222 | + if ($hours <= 24) { |
|
223 | 223 | return $hours.'小时前'; |
224 | 224 | } |
225 | 225 | $days = intval($hours / 24); |
226 | - if($days <= 3){ |
|
226 | + if ($days <= 3) { |
|
227 | 227 | return $days.'天前'; |
228 | 228 | } |
229 | - if($days <= 365){ |
|
230 | - return date('m-d',$time); |
|
229 | + if ($days <= 365) { |
|
230 | + return date('m-d', $time); |
|
231 | 231 | } |
232 | - return date('Y-m-d',$time); |
|
232 | + return date('Y-m-d', $time); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | /** |
@@ -243,11 +243,11 @@ discard block |
||
243 | 243 | $compress = ''; |
244 | 244 | foreach ($chunks as $c) { |
245 | 245 | if (strtolower(substr($c, 0, 19)) == '<!--<nocompress>-->') { |
246 | - $c = substr($c, 19, strlen($c) - 19 - 20); |
|
246 | + $c = substr($c, 19, strlen($c) - 19 - 20); |
|
247 | 247 | $compress .= $c; |
248 | 248 | continue; |
249 | 249 | } elseif (strtolower(substr($c, 0, 12)) == '<nocompress>') { |
250 | - $c = substr($c, 12, strlen($c) - 12 - 13); |
|
250 | + $c = substr($c, 12, strlen($c) - 12 - 13); |
|
251 | 251 | $compress .= $c; |
252 | 252 | continue; |
253 | 253 | } elseif (strtolower(substr($c, 0, 4)) == '<pre' || strtolower(substr($c, 0, 9)) == '<textarea') { |
@@ -295,14 +295,14 @@ discard block |
||
295 | 295 | * @return mixed |
296 | 296 | */ |
297 | 297 | static public function htmlReplaceXcx(string $content):string { |
298 | - $content = str_replace("\r\n","",$content);//出除回车和换行符 |
|
299 | - $content = preg_replace("/style=\".*?\"/si",'',$content);//style样式 |
|
300 | - $content = preg_replace(["/<strong.*?>/si", "/<\/strong>/si"],['<text class="wx-strong">','</text>'],$content);//strong |
|
301 | - $content = preg_replace(["/<p.*?>/si", "/<\/p>/si"],['<view class="wx-p">','</view>'],$content);//p |
|
302 | - $content = preg_replace(["/<a.*?>/si", "/<\/a>/si"],['<text class="wx-a">','</text>'],$content);//a |
|
303 | - $content = preg_replace(["/<span.*?>/si", "/<\/span>/si"],['<text class="wx-span">','</text>'],$content);//span |
|
304 | - $content = preg_replace(["/<h[1-6].*?>/si", "/<\/h[1-6]>/si"],['<view class="wx-h">','</view>'],$content);//h |
|
305 | - $content = preg_replace("/<img.*?/si",'<image class="wx-img"',$content);//img |
|
298 | + $content = str_replace("\r\n", "", $content); //出除回车和换行符 |
|
299 | + $content = preg_replace("/style=\".*?\"/si", '', $content); //style样式 |
|
300 | + $content = preg_replace(["/<strong.*?>/si", "/<\/strong>/si"], ['<text class="wx-strong">', '</text>'], $content); //strong |
|
301 | + $content = preg_replace(["/<p.*?>/si", "/<\/p>/si"], ['<view class="wx-p">', '</view>'], $content); //p |
|
302 | + $content = preg_replace(["/<a.*?>/si", "/<\/a>/si"], ['<text class="wx-a">', '</text>'], $content); //a |
|
303 | + $content = preg_replace(["/<span.*?>/si", "/<\/span>/si"], ['<text class="wx-span">', '</text>'], $content); //span |
|
304 | + $content = preg_replace(["/<h[1-6].*?>/si", "/<\/h[1-6]>/si"], ['<view class="wx-h">', '</view>'], $content); //h |
|
305 | + $content = preg_replace("/<img.*?/si", '<image class="wx-img"', $content); //img |
|
306 | 306 | return $content; |
307 | 307 | } |
308 | 308 | |
@@ -314,8 +314,8 @@ discard block |
||
314 | 314 | * @return string |
315 | 315 | */ |
316 | 316 | static public function pReplaceSpan(string $content):string { |
317 | - $content = str_replace(["\r","\n","\t"],'',$content); |
|
318 | - $content = preg_replace(["/<p/si", "/<\/p>/si"],['<span','</span><br>'],$content);//p |
|
317 | + $content = str_replace(["\r", "\n", "\t"], '', $content); |
|
318 | + $content = preg_replace(["/<p/si", "/<\/p>/si"], ['<span', '</span><br>'], $content); //p |
|
319 | 319 | return $content; |
320 | 320 | } |
321 | 321 | |
@@ -326,10 +326,10 @@ discard block |
||
326 | 326 | * @param string $keyword |
327 | 327 | * @return string |
328 | 328 | */ |
329 | - static public function filterPunctuation($keyword){ |
|
330 | - $keyword = str_replace(["\r\n", "\r", "\n"," "," "], "", trim($keyword));//删除空格 |
|
331 | - $keyword = preg_replace('# #','',$keyword); |
|
332 | - $keyword = preg_replace("/[ '.,:;*?~`!@#$%^&+=)(<>{}]|\]|\[|\/|\\\|\"|\|/",'',$keyword); |
|
329 | + static public function filterPunctuation($keyword) { |
|
330 | + $keyword = str_replace(["\r\n", "\r", "\n", " ", " "], "", trim($keyword)); //删除空格 |
|
331 | + $keyword = preg_replace('# #', '', $keyword); |
|
332 | + $keyword = preg_replace("/[ '.,:;*?~`!@#$%^&+=)(<>{}]|\]|\[|\/|\\\|\"|\|/", '', $keyword); |
|
333 | 333 | return $keyword; |
334 | 334 | } |
335 | 335 | |
@@ -341,9 +341,9 @@ discard block |
||
341 | 341 | * @param string $allowable_tags |
342 | 342 | * @return string |
343 | 343 | */ |
344 | - static public function stripTags($content,$allowable_tags = '<font>'){ |
|
345 | - $content = strip_tags($content,$allowable_tags);//替换标签 |
|
346 | - $content = str_replace(["\r\n", "\r", "\n"," "], "", trim($content));//删除空格 |
|
344 | + static public function stripTags($content, $allowable_tags = '<font>') { |
|
345 | + $content = strip_tags($content, $allowable_tags); //替换标签 |
|
346 | + $content = str_replace(["\r\n", "\r", "\n", " "], "", trim($content)); //删除空格 |
|
347 | 347 | return $content; |
348 | 348 | } |
349 | 349 |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | if(empty($time)){ |
76 | 76 | list($msec, $sec) = explode(' ', microtime()); |
77 | 77 | $millisecond = (int)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); |
78 | - }else{ |
|
78 | + } else{ |
|
79 | 79 | $millisecond = strtotime($time)."000"; |
80 | 80 | } |
81 | 81 | return (int)$millisecond; |
@@ -160,12 +160,12 @@ discard block |
||
160 | 160 | foreach ($string as $key => $val) { |
161 | 161 | $_key = self::autoCharset($key, $from, $to); |
162 | 162 | $string[$_key] = self::autoCharset($val, $from, $to); |
163 | - if ($key != $_key) |
|
164 | - unset($string[$key]); |
|
163 | + if ($key != $_key) { |
|
164 | + unset($string[$key]); |
|
165 | + } |
|
165 | 166 | } |
166 | 167 | return $string; |
167 | - } |
|
168 | - else { |
|
168 | + } else { |
|
169 | 169 | return $string; |
170 | 170 | } |
171 | 171 | } |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | public static function getTime($date,$is_timestamp=false):string { |
204 | 204 | if($is_timestamp == true){ |
205 | 205 | $time = $date; |
206 | - }else{ |
|
206 | + } else{ |
|
207 | 207 | $time = strtotime($date);//时间转换为时间戳 |
208 | 208 | } |
209 | 209 |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * Description: Tool.php. |
9 | 9 | */ |
10 | 10 | |
11 | -class Tool{ |
|
11 | +class Tool { |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * Description: 对象到数组转换 |
@@ -17,12 +17,12 @@ discard block |
||
17 | 17 | * @param $obj |
18 | 18 | * @return array |
19 | 19 | */ |
20 | - private function objectToArray($obj){ |
|
21 | - if(!is_object($obj) && !is_array($obj)) { |
|
20 | + private function objectToArray($obj) { |
|
21 | + if (!is_object($obj) && !is_array($obj)) { |
|
22 | 22 | return $obj; |
23 | 23 | } |
24 | 24 | $arr = array(); |
25 | - foreach($obj as $k => $v){ |
|
25 | + foreach ($obj as $k => $v) { |
|
26 | 26 | $arr[$k] = $this->objectToArray($v); |
27 | 27 | } |
28 | 28 | return $arr; |
@@ -34,14 +34,14 @@ discard block |
||
34 | 34 | * Updater: |
35 | 35 | * @return string |
36 | 36 | */ |
37 | - public static function getIp(){ |
|
38 | - if(!empty($_SERVER["HTTP_CLIENT_IP"])){ |
|
37 | + public static function getIp() { |
|
38 | + if (!empty($_SERVER["HTTP_CLIENT_IP"])) { |
|
39 | 39 | $cip = $_SERVER["HTTP_CLIENT_IP"]; |
40 | - }else if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){ |
|
40 | + } else if (!empty($_SERVER["HTTP_X_FORWARDED_FOR"])) { |
|
41 | 41 | $cip = $_SERVER["HTTP_X_FORWARDED_FOR"]; |
42 | - }else if(!empty($_SERVER["REMOTE_ADDR"])){ |
|
42 | + } else if (!empty($_SERVER["REMOTE_ADDR"])) { |
|
43 | 43 | $cip = $_SERVER["REMOTE_ADDR"]; |
44 | - }else{ |
|
44 | + } else { |
|
45 | 45 | $cip = ''; |
46 | 46 | } |
47 | 47 | preg_match("/[\d\.]{7,15}/", $cip, $cips); |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | 'mobile' |
107 | 107 | ); |
108 | 108 | // 从HTTP_USER_AGENT中查找手机浏览器的关键字 |
109 | - if (preg_match("/(" . implode('|', $clientKeyWords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) { |
|
109 | + if (preg_match("/(".implode('|', $clientKeyWords).")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) { |
|
110 | 110 | return true; |
111 | 111 | } |
112 | 112 | } |
@@ -144,13 +144,13 @@ discard block |
||
144 | 144 | * @param int $parent_id 父id值 |
145 | 145 | * @return array |
146 | 146 | */ |
147 | - public static function getTreeStructure($list,$filed='id',$parent_filed='pid',$parent_id=0){ |
|
147 | + public static function getTreeStructure($list, $filed = 'id', $parent_filed = 'pid', $parent_id = 0) { |
|
148 | 148 | $result = array(); |
149 | - if(!empty($list)){ |
|
150 | - foreach($list as $key=>$val){ |
|
151 | - if($val[$parent_filed] == $parent_id){ |
|
152 | - $val['child'] = self::getTreeStructure($list,$filed,$parent_filed,$val[$filed]); |
|
153 | - if(empty($val['child'])){ |
|
149 | + if (!empty($list)) { |
|
150 | + foreach ($list as $key=>$val) { |
|
151 | + if ($val[$parent_filed] == $parent_id) { |
|
152 | + $val['child'] = self::getTreeStructure($list, $filed, $parent_filed, $val[$filed]); |
|
153 | + if (empty($val['child'])) { |
|
154 | 154 | unset($val['child']); |
155 | 155 | } |
156 | 156 | $result[] = $val; |
@@ -166,12 +166,12 @@ discard block |
||
166 | 166 | * @Author: TinyMeng <[email protected]> |
167 | 167 | * @param $data |
168 | 168 | */ |
169 | - static public function nullArrayToObject(&$data){ |
|
170 | - foreach ($data as $key=>&$val){ |
|
171 | - if(is_array($val)){ |
|
172 | - if(empty($val)){ |
|
173 | - settype($val,'object'); |
|
174 | - }else{ |
|
169 | + static public function nullArrayToObject(&$data) { |
|
170 | + foreach ($data as $key=>&$val) { |
|
171 | + if (is_array($val)) { |
|
172 | + if (empty($val)) { |
|
173 | + settype($val, 'object'); |
|
174 | + } else { |
|
175 | 175 | self::nullArrayToObject($val); |
176 | 176 | } |
177 | 177 | } |
@@ -37,11 +37,11 @@ discard block |
||
37 | 37 | public static function getIp(){ |
38 | 38 | if(!empty($_SERVER["HTTP_CLIENT_IP"])){ |
39 | 39 | $cip = $_SERVER["HTTP_CLIENT_IP"]; |
40 | - }else if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){ |
|
40 | + } else if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){ |
|
41 | 41 | $cip = $_SERVER["HTTP_X_FORWARDED_FOR"]; |
42 | - }else if(!empty($_SERVER["REMOTE_ADDR"])){ |
|
42 | + } else if(!empty($_SERVER["REMOTE_ADDR"])){ |
|
43 | 43 | $cip = $_SERVER["REMOTE_ADDR"]; |
44 | - }else{ |
|
44 | + } else{ |
|
45 | 45 | $cip = ''; |
46 | 46 | } |
47 | 47 | preg_match("/[\d\.]{7,15}/", $cip, $cips); |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | if(is_array($val)){ |
172 | 172 | if(empty($val)){ |
173 | 173 | settype($val,'object'); |
174 | - }else{ |
|
174 | + } else{ |
|
175 | 175 | self::nullArrayToObject($val); |
176 | 176 | } |
177 | 177 | } |
@@ -18,10 +18,10 @@ |
||
18 | 18 | |
19 | 19 | public function __construct(int $statusCode, string $message = '', Exception $previous = null, array $headers = [], $code = 0) |
20 | 20 | { |
21 | - $this->headers = $headers; |
|
21 | + $this->headers = $headers; |
|
22 | 22 | |
23 | 23 | /** message */ |
24 | - if(empty($message)) $message = isset(StatusCode::$status_code[$statusCode]) ? StatusCode::$status_code[$statusCode] :StatusCode::$status_code[StatusCode::COMMON_UNKNOWN]; |
|
24 | + if (empty($message)) $message = isset(StatusCode::$status_code[$statusCode]) ? StatusCode::$status_code[$statusCode] : StatusCode::$status_code[StatusCode::COMMON_UNKNOWN]; |
|
25 | 25 | parent::__construct('ERROR_TINYMENG_TOOL: '.$message, $code, $previous); |
26 | 26 | } |
27 | 27 |
@@ -21,7 +21,9 @@ |
||
21 | 21 | $this->headers = $headers; |
22 | 22 | |
23 | 23 | /** message */ |
24 | - if(empty($message)) $message = isset(StatusCode::$status_code[$statusCode]) ? StatusCode::$status_code[$statusCode] :StatusCode::$status_code[StatusCode::COMMON_UNKNOWN]; |
|
24 | + if(empty($message)) { |
|
25 | + $message = isset(StatusCode::$status_code[$statusCode]) ? StatusCode::$status_code[$statusCode] :StatusCode::$status_code[StatusCode::COMMON_UNKNOWN]; |
|
26 | + } |
|
25 | 27 | parent::__construct('ERROR_TINYMENG_TOOL: '.$message, $code, $previous); |
26 | 28 | } |
27 | 29 |
@@ -12,43 +12,43 @@ |
||
12 | 12 | /** |
13 | 13 | * 公共状态码 |
14 | 14 | */ |
15 | - const COMMON_SUCCESS = 200;//成功 |
|
16 | - const COMMON_UNKNOWN = 400;//未知错误 |
|
17 | - const COMMON_REQUEST_METHOD = 401;//错误请求(请求方式错误) |
|
18 | - const COMMON_HEADER_MISS_PARAM = 402;//缺失头信息 |
|
19 | - const COMMON_ACCESS_BARRED = 403;//禁止访问 |
|
20 | - const COMMON_NOT_REQUEST = 404;//请求不存在 |
|
21 | - const COMMON_TINYMENG_REQUEST_METHOD = 405;//站外链接请求错误 |
|
15 | + const COMMON_SUCCESS = 200; //成功 |
|
16 | + const COMMON_UNKNOWN = 400; //未知错误 |
|
17 | + const COMMON_REQUEST_METHOD = 401; //错误请求(请求方式错误) |
|
18 | + const COMMON_HEADER_MISS_PARAM = 402; //缺失头信息 |
|
19 | + const COMMON_ACCESS_BARRED = 403; //禁止访问 |
|
20 | + const COMMON_NOT_REQUEST = 404; //请求不存在 |
|
21 | + const COMMON_TINYMENG_REQUEST_METHOD = 405; //站外链接请求错误 |
|
22 | 22 | |
23 | 23 | /** |
24 | 24 | * 未授权 420 |
25 | 25 | */ |
26 | - const COMMON_TOKEN_INVALID = 421;//token无效 |
|
27 | - const COMMON_SIGN_ERROR = 422;//签名错误 |
|
28 | - const COMMON_NO_ACCESS = 423;//没有权限 |
|
26 | + const COMMON_TOKEN_INVALID = 421; //token无效 |
|
27 | + const COMMON_SIGN_ERROR = 422; //签名错误 |
|
28 | + const COMMON_NO_ACCESS = 423; //没有权限 |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * 数据错误 430 |
32 | 32 | */ |
33 | - const COMMON_PARAM_INVALID = 431;//参数无效 |
|
34 | - const COMMON_PARAM_MISS = 432;//参数缺失 |
|
35 | - const COMMON_PARAMS_VERIFY_ERROR = 433;//字段验证失败 |
|
36 | - const COMMON_CAPTCHA_INVALID = 434;//验证码错误 |
|
37 | - const COMMON_NO_DATA_EXIST = 435;//数据不存在 |
|
38 | - const COMMON_DATA_EXIST = 436;//数据已存在 |
|
39 | - const COMMON_SAVE_FAILURE = 437;//存储失败 |
|
33 | + const COMMON_PARAM_INVALID = 431; //参数无效 |
|
34 | + const COMMON_PARAM_MISS = 432; //参数缺失 |
|
35 | + const COMMON_PARAMS_VERIFY_ERROR = 433; //字段验证失败 |
|
36 | + const COMMON_CAPTCHA_INVALID = 434; //验证码错误 |
|
37 | + const COMMON_NO_DATA_EXIST = 435; //数据不存在 |
|
38 | + const COMMON_DATA_EXIST = 436; //数据已存在 |
|
39 | + const COMMON_SAVE_FAILURE = 437; //存储失败 |
|
40 | 40 | |
41 | 41 | /** |
42 | 42 | * 用户错误码 440 |
43 | 43 | */ |
44 | - const COMMON_NOT_ENTERED_PASSWORD = 440;//未输入密码 |
|
45 | - const COMMON_PASSWORD_INVALID = 441;//密码错误 |
|
44 | + const COMMON_NOT_ENTERED_PASSWORD = 440; //未输入密码 |
|
45 | + const COMMON_PASSWORD_INVALID = 441; //密码错误 |
|
46 | 46 | |
47 | 47 | /** |
48 | 48 | * 系统状态码 300000 |
49 | 49 | */ |
50 | - const USER_STOP_USE = 300105;//用户停止使用 |
|
51 | - const USER_SYSTEM_UPDATE = 300109;//系统升级 |
|
50 | + const USER_STOP_USE = 300105; //用户停止使用 |
|
51 | + const USER_SYSTEM_UPDATE = 300109; //系统升级 |
|
52 | 52 | |
53 | 53 | public static $status_code = [ |
54 | 54 | //公共错误码 |
@@ -33,19 +33,19 @@ discard block |
||
33 | 33 | * @return mixed |
34 | 34 | * @throws \Exception |
35 | 35 | */ |
36 | - static public function httpPost($url, $param = array(), $httpHeaders = array(),$proxy='', $http_code = 200) |
|
36 | + static public function httpPost($url, $param = array(), $httpHeaders = array(), $proxy = '', $http_code = 200) |
|
37 | 37 | { |
38 | 38 | /** 参数检测,object或者array进行http_build_query */ |
39 | - if(!empty($param) && is_array($param)){ |
|
39 | + if (!empty($param) && is_array($param)) { |
|
40 | 40 | $flag = false; |
41 | - foreach ($param as $value){ |
|
41 | + foreach ($param as $value) { |
|
42 | 42 | //判断参数是否是一个对象 或者 是一个数组 |
43 | - if(is_array($value) || (is_string($value) && is_object($value))){ |
|
43 | + if (is_array($value) || (is_string($value) && is_object($value))) { |
|
44 | 44 | $flag = true; |
45 | 45 | break; |
46 | 46 | } |
47 | 47 | } |
48 | - if($flag == true){ |
|
48 | + if ($flag == true) { |
|
49 | 49 | $param = http_build_query($param); |
50 | 50 | } |
51 | 51 | } |
@@ -62,12 +62,12 @@ discard block |
||
62 | 62 | curl_setopt($curl, CURLOPT_POSTFIELDS, $param); |
63 | 63 | |
64 | 64 | /** 设置请求headers */ |
65 | - if(empty($httpHeaders)){ |
|
65 | + if (empty($httpHeaders)) { |
|
66 | 66 | $httpHeaders = array( |
67 | 67 | "user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36" |
68 | 68 | ); |
69 | 69 | } |
70 | - if (is_array($httpHeaders)){ |
|
70 | + if (is_array($httpHeaders)) { |
|
71 | 71 | curl_setopt($curl, CURLOPT_HTTPHEADER, $httpHeaders); |
72 | 72 | } |
73 | 73 | /** gzip压缩 */ |
@@ -81,11 +81,11 @@ discard block |
||
81 | 81 | } |
82 | 82 | |
83 | 83 | /** http代理 */ |
84 | - if(!empty($proxy)){ |
|
85 | - $proxy = explode(':',$proxy); |
|
84 | + if (!empty($proxy)) { |
|
85 | + $proxy = explode(':', $proxy); |
|
86 | 86 | curl_setopt($curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); //代理认证模式 |
87 | 87 | curl_setopt($curl, CURLOPT_PROXY, "$proxy[0]"); //代理服务器地址 |
88 | - curl_setopt($curl, CURLOPT_PROXYPORT,$proxy[1]); //代理服务器端口 |
|
88 | + curl_setopt($curl, CURLOPT_PROXYPORT, $proxy[1]); //代理服务器端口 |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** 请求 */ |
@@ -98,11 +98,11 @@ discard block |
||
98 | 98 | /** 验证网络请求状态 */ |
99 | 99 | if (intval($info["http_code"]) === 0) { |
100 | 100 | throw new TinymengException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD, |
101 | - '[httpPost]: POST request was aborted ! Request url :' . $url . ' , post request data : ' . var_export($param,true) |
|
101 | + '[httpPost]: POST request was aborted ! Request url :'.$url.' , post request data : '.var_export($param, true) |
|
102 | 102 | ); |
103 | - }elseif(intval($info["http_code"]) != $http_code){ |
|
103 | + }elseif (intval($info["http_code"]) != $http_code) { |
|
104 | 104 | throw new TinymengException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD, |
105 | - '[httpPost]: POST request was aborted ! Request url :' . $url . ' , post request data : ' . var_export($param,true).' ,return code : '.$info["http_code"] .' ,return content : '.$content |
|
105 | + '[httpPost]: POST request was aborted ! Request url :'.$url.' , post request data : '.var_export($param, true).' ,return code : '.$info["http_code"].' ,return content : '.$content |
|
106 | 106 | ); |
107 | 107 | } else { |
108 | 108 | return $content; |
@@ -121,13 +121,13 @@ discard block |
||
121 | 121 | * @return mixed |
122 | 122 | * @throws \Exception |
123 | 123 | */ |
124 | - static public function httpGet($url, $param = array(), $httpHeaders = array(),$proxy= '', $http_code = 200) |
|
124 | + static public function httpGet($url, $param = array(), $httpHeaders = array(), $proxy = '', $http_code = 200) |
|
125 | 125 | { |
126 | 126 | $curl = curl_init(); |
127 | 127 | |
128 | 128 | /** 设置请求参数 */ |
129 | 129 | if (!empty($param)) { |
130 | - $url = $url . '?' . http_build_query($param); |
|
130 | + $url = $url.'?'.http_build_query($param); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** 设置请求链接 */ |
@@ -143,20 +143,20 @@ discard block |
||
143 | 143 | } |
144 | 144 | |
145 | 145 | /** http代理 */ |
146 | - if(!empty($proxy)){ |
|
147 | - $proxy = explode(':',$proxy); |
|
146 | + if (!empty($proxy)) { |
|
147 | + $proxy = explode(':', $proxy); |
|
148 | 148 | curl_setopt($curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); //代理认证模式 |
149 | 149 | curl_setopt($curl, CURLOPT_PROXY, "$proxy[0]"); //代理服务器地址 |
150 | - curl_setopt($curl, CURLOPT_PROXYPORT,$proxy[1]); //代理服务器端口 |
|
150 | + curl_setopt($curl, CURLOPT_PROXYPORT, $proxy[1]); //代理服务器端口 |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** 设置请求headers */ |
154 | - if(empty($httpHeaders)){ |
|
154 | + if (empty($httpHeaders)) { |
|
155 | 155 | $httpHeaders = array( |
156 | 156 | "user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36" |
157 | 157 | ); |
158 | 158 | } |
159 | - if (is_array($httpHeaders)){ |
|
159 | + if (is_array($httpHeaders)) { |
|
160 | 160 | curl_setopt($curl, CURLOPT_HTTPHEADER, $httpHeaders); |
161 | 161 | } |
162 | 162 | /** gzip压缩 */ |
@@ -172,11 +172,11 @@ discard block |
||
172 | 172 | /** 验证网络请求状态 */ |
173 | 173 | if (intval($info["http_code"]) === 0) { |
174 | 174 | throw new TinymengException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD, |
175 | - '[httpGet]: GET request was aborted ! Request url :' . $url |
|
175 | + '[httpGet]: GET request was aborted ! Request url :'.$url |
|
176 | 176 | ); |
177 | - }elseif(intval($info["http_code"]) != $http_code){ |
|
177 | + }elseif (intval($info["http_code"]) != $http_code) { |
|
178 | 178 | throw new TinymengException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD, |
179 | - '[httpGet]: GET request was aborted ! Request url :' . $url .' ,return code : '.$info["http_code"] .' ,return content : '.$content |
|
179 | + '[httpGet]: GET request was aborted ! Request url :'.$url.' ,return code : '.$info["http_code"].' ,return content : '.$content |
|
180 | 180 | ); |
181 | 181 | } else { |
182 | 182 | return $content; |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | throw new TinymengException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD, |
101 | 101 | '[httpPost]: POST request was aborted ! Request url :' . $url . ' , post request data : ' . var_export($param,true) |
102 | 102 | ); |
103 | - }elseif(intval($info["http_code"]) != $http_code){ |
|
103 | + } elseif(intval($info["http_code"]) != $http_code){ |
|
104 | 104 | throw new TinymengException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD, |
105 | 105 | '[httpPost]: POST request was aborted ! Request url :' . $url . ' , post request data : ' . var_export($param,true).' ,return code : '.$info["http_code"] .' ,return content : '.$content |
106 | 106 | ); |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | throw new TinymengException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD, |
175 | 175 | '[httpGet]: GET request was aborted ! Request url :' . $url |
176 | 176 | ); |
177 | - }elseif(intval($info["http_code"]) != $http_code){ |
|
177 | + } elseif(intval($info["http_code"]) != $http_code){ |
|
178 | 178 | throw new TinymengException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD, |
179 | 179 | '[httpGet]: GET request was aborted ! Request url :' . $url .' ,return code : '.$info["http_code"] .' ,return content : '.$content |
180 | 180 | ); |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | class Rsa |
11 | 11 | { |
12 | 12 | |
13 | - private $rsaPath = './';//公钥证书路径 |
|
13 | + private $rsaPath = './'; //公钥证书路径 |
|
14 | 14 | |
15 | 15 | /** |
16 | 16 | * Author: JiaMeng <[email protected]> |
@@ -62,11 +62,11 @@ discard block |
||
62 | 62 | // 生成私钥 |
63 | 63 | $rsa = openssl_pkey_new($config); |
64 | 64 | openssl_pkey_export($rsa, $privKey, $this->privkeypass, $config); |
65 | - file_put_contents($this->rsaPath . DIRECTORY_SEPARATOR . 'priv.key', $privKey); |
|
65 | + file_put_contents($this->rsaPath.DIRECTORY_SEPARATOR.'priv.key', $privKey); |
|
66 | 66 | // 生成公钥 |
67 | 67 | $rsaPri = openssl_pkey_get_details($rsa); |
68 | 68 | $pubKey = $rsaPri['key']; |
69 | - file_put_contents($this->rsaPath . DIRECTORY_SEPARATOR . 'pub.key', $pubKey); |
|
69 | + file_put_contents($this->rsaPath.DIRECTORY_SEPARATOR.'pub.key', $pubKey); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | */ |
76 | 76 | public function setupPrivKey() |
77 | 77 | { |
78 | - $file = $this->rsaPath . DIRECTORY_SEPARATOR . 'priv.key'; |
|
78 | + $file = $this->rsaPath.DIRECTORY_SEPARATOR.'priv.key'; |
|
79 | 79 | $privKey = file_get_contents($file); |
80 | 80 | $this->_privKey = openssl_pkey_get_private($privKey, $this->privkeypass); |
81 | 81 | return true; |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | */ |
88 | 88 | public function setupPubKey() |
89 | 89 | { |
90 | - $file = $this->rsaPath . DIRECTORY_SEPARATOR . 'pub.key'; |
|
90 | + $file = $this->rsaPath.DIRECTORY_SEPARATOR.'pub.key'; |
|
91 | 91 | $pubKey = file_get_contents($file); |
92 | 92 | $this->_pubKey = openssl_pkey_get_public($pubKey); |
93 | 93 | return true; |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace tinymeng\tools\async; |
3 | 3 | |
4 | -class AsyncHook{ |
|
4 | +class AsyncHook { |
|
5 | 5 | |
6 | 6 | /** |
7 | 7 | * @var array |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | */ |
21 | 21 | public static function hook(callable $callback, $params) { |
22 | 22 | self::$hook_list[] = array('callback' => $callback, 'params' => $params); |
23 | - if(self::$hooked == false) { |
|
23 | + if (self::$hooked == false) { |
|
24 | 24 | self::$hooked = true; |
25 | 25 | //注册一个callback当前在脚本执行完后执行 |
26 | 26 | register_shutdown_function(array(__CLASS__, '__run')); |
@@ -33,10 +33,10 @@ discard block |
||
33 | 33 | */ |
34 | 34 | private static function __run() { |
35 | 35 | fastcgi_finish_request(); |
36 | - if(empty(self::$hook_list)) { |
|
36 | + if (empty(self::$hook_list)) { |
|
37 | 37 | return; |
38 | 38 | } |
39 | - foreach(self::$hook_list as $hook) { |
|
39 | + foreach (self::$hook_list as $hook) { |
|
40 | 40 | $callback = $hook['callback']; |
41 | 41 | $params = $hook['params']; |
42 | 42 | call_user_func_array($callback, $params); |