@@ -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); |
@@ -13,11 +13,11 @@ discard block |
||
13 | 13 | */ |
14 | 14 | private static $instance = null; |
15 | 15 | |
16 | - public function __construct($config=[]){ |
|
16 | + public function __construct($config = []) { |
|
17 | 17 | $this->config = $config; |
18 | 18 | } |
19 | 19 | |
20 | - private function __clone(){} |
|
20 | + private function __clone() {} |
|
21 | 21 | |
22 | 22 | public function __sleep(): array |
23 | 23 | { |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | return []; |
26 | 26 | } |
27 | 27 | |
28 | - protected static function init($gateway, $config=[]) |
|
28 | + protected static function init($gateway, $config = []) |
|
29 | 29 | { |
30 | 30 | if (!self::$instance instanceof static) { |
31 | 31 | self::$instance = new static($config); |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | *@author: JiaMeng <[email protected]> |
42 | 42 | * Updater: |
43 | 43 | */ |
44 | - public static function __callStatic($gateway, array $config=[]) |
|
44 | + public static function __callStatic($gateway, array $config = []) |
|
45 | 45 | { |
46 | 46 | return self::init($gateway, ...$config); |
47 | 47 | } |
@@ -21,7 +21,7 @@ |
||
21 | 21 | $this->setHeaders($headers); |
22 | 22 | |
23 | 23 | /** message */ |
24 | - if(empty($message)) $message = StatusCode::$status_code[$statusCode] ?? StatusCode::$status_code[StatusCode::COMMON_UNKNOWN]; |
|
24 | + if (empty($message)) $message = StatusCode::$status_code[$statusCode] ?? StatusCode::$status_code[StatusCode::COMMON_UNKNOWN]; |
|
25 | 25 | parent::__construct('ERROR tinymeng tools: '.$message, $code, $previous); |
26 | 26 | } |
27 | 27 |
@@ -37,19 +37,19 @@ discard block |
||
37 | 37 | * @return bool|string |
38 | 38 | * @throws \Exception |
39 | 39 | */ |
40 | - static public function httpPost(string $url, array $param = array(), array $httpHeaders = array(), string $proxy='', int $http_code = 200) |
|
40 | + static public function httpPost(string $url, array $param = array(), array $httpHeaders = array(), string $proxy = '', int $http_code = 200) |
|
41 | 41 | { |
42 | 42 | /** 参数检测,object或者array进行http_build_query */ |
43 | - if(!empty($param) && is_array($param)){ |
|
43 | + if (!empty($param) && is_array($param)) { |
|
44 | 44 | $flag = false; |
45 | - foreach ($param as $value){ |
|
45 | + foreach ($param as $value) { |
|
46 | 46 | //判断参数是否是一个对象 或者 是一个数组 |
47 | - if(is_array($value) || (is_string($value) && is_object($value))){ |
|
47 | + if (is_array($value) || (is_string($value) && is_object($value))) { |
|
48 | 48 | $flag = true; |
49 | 49 | break; |
50 | 50 | } |
51 | 51 | } |
52 | - if($flag){ |
|
52 | + if ($flag) { |
|
53 | 53 | $param = http_build_query($param); |
54 | 54 | } |
55 | 55 | } |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | curl_setopt($curl, CURLOPT_POSTFIELDS, $param); |
67 | 67 | |
68 | 68 | /** 设置请求headers */ |
69 | - if(empty($httpHeaders)) $httpHeaders = self::$httpHeaders; |
|
69 | + if (empty($httpHeaders)) $httpHeaders = self::$httpHeaders; |
|
70 | 70 | curl_setopt($curl, CURLOPT_HTTPHEADER, $httpHeaders); |
71 | 71 | |
72 | 72 | /** gzip压缩 */ |
@@ -80,11 +80,11 @@ discard block |
||
80 | 80 | } |
81 | 81 | |
82 | 82 | /** http代理 */ |
83 | - if(!empty($proxy)){ |
|
84 | - $proxy = explode(':',$proxy); |
|
83 | + if (!empty($proxy)) { |
|
84 | + $proxy = explode(':', $proxy); |
|
85 | 85 | curl_setopt($curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); //代理认证模式 |
86 | 86 | curl_setopt($curl, CURLOPT_PROXY, "$proxy[0]"); //代理服务器地址 |
87 | - curl_setopt($curl, CURLOPT_PROXYPORT,$proxy[1]); //代理服务器端口 |
|
87 | + curl_setopt($curl, CURLOPT_PROXYPORT, $proxy[1]); //代理服务器端口 |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** 请求 */ |
@@ -94,20 +94,20 @@ discard block |
||
94 | 94 | /** 关闭请求资源 */ |
95 | 95 | curl_close($curl); |
96 | 96 | |
97 | - if($http_code !== 0){ |
|
97 | + if ($http_code !== 0) { |
|
98 | 98 | /** 验证网络请求状态 */ |
99 | 99 | if (intval($info["http_code"]) === 0) { |
100 | 100 | throw new TException(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 TException(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; |
109 | 109 | } |
110 | - }else{ |
|
110 | + } else { |
|
111 | 111 | return $content; |
112 | 112 | } |
113 | 113 | } |
@@ -124,13 +124,13 @@ discard block |
||
124 | 124 | * @return bool|string |
125 | 125 | * @throws \Exception |
126 | 126 | */ |
127 | - static public function httpGet(string $url, array $param = array(), array $httpHeaders = array(), string $proxy= '', int $http_code = 200) |
|
127 | + static public function httpGet(string $url, array $param = array(), array $httpHeaders = array(), string $proxy = '', int $http_code = 200) |
|
128 | 128 | { |
129 | 129 | $curl = curl_init(); |
130 | 130 | |
131 | 131 | /** 设置请求参数 */ |
132 | 132 | if (!empty($param)) { |
133 | - $url = $url . '?' . http_build_query($param); |
|
133 | + $url = $url.'?'.http_build_query($param); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** 设置请求链接 */ |
@@ -146,15 +146,15 @@ discard block |
||
146 | 146 | } |
147 | 147 | |
148 | 148 | /** http代理 */ |
149 | - if(!empty($proxy)){ |
|
150 | - $proxy = explode(':',$proxy); |
|
149 | + if (!empty($proxy)) { |
|
150 | + $proxy = explode(':', $proxy); |
|
151 | 151 | curl_setopt($curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); //代理认证模式 |
152 | 152 | curl_setopt($curl, CURLOPT_PROXY, "$proxy[0]"); //代理服务器地址 |
153 | - curl_setopt($curl, CURLOPT_PROXYPORT,$proxy[1]); //代理服务器端口 |
|
153 | + curl_setopt($curl, CURLOPT_PROXYPORT, $proxy[1]); //代理服务器端口 |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** 设置请求headers */ |
157 | - if(empty($httpHeaders)) $httpHeaders = self::$httpHeaders; |
|
157 | + if (empty($httpHeaders)) $httpHeaders = self::$httpHeaders; |
|
158 | 158 | curl_setopt($curl, CURLOPT_HTTPHEADER, $httpHeaders); |
159 | 159 | |
160 | 160 | /** gzip压缩 */ |
@@ -168,19 +168,19 @@ discard block |
||
168 | 168 | curl_close($curl); |
169 | 169 | |
170 | 170 | /** 验证网络请求状态 */ |
171 | - if($http_code !== 0){ |
|
171 | + if ($http_code !== 0) { |
|
172 | 172 | if (intval($info["http_code"]) === 0) { |
173 | 173 | throw new TException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD, |
174 | - '[httpGet]: GET request was aborted ! Request url :' . $url |
|
174 | + '[httpGet]: GET request was aborted ! Request url :'.$url |
|
175 | 175 | ); |
176 | - }elseif(intval($info["http_code"]) != $http_code){ |
|
176 | + }elseif (intval($info["http_code"]) != $http_code) { |
|
177 | 177 | throw new TException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD, |
178 | - '[httpGet]: GET request was aborted ! Request url :' . $url .' ,return code : '.$info["http_code"] .' ,return content : '.$content |
|
178 | + '[httpGet]: GET request was aborted ! Request url :'.$url.' ,return code : '.$info["http_code"].' ,return content : '.$content |
|
179 | 179 | ); |
180 | 180 | } else { |
181 | 181 | return $content; |
182 | 182 | } |
183 | - }else{ |
|
183 | + } else { |
|
184 | 184 | return $content; |
185 | 185 | } |
186 | 186 | } |
@@ -80,22 +80,22 @@ discard block |
||
80 | 80 | $str = ''; |
81 | 81 | switch ($type) { |
82 | 82 | case 0: |
83 | - $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' . $addChars; |
|
83 | + $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.$addChars; |
|
84 | 84 | break; |
85 | 85 | case 1: |
86 | 86 | $chars = str_repeat('0123456789', 3); |
87 | 87 | break; |
88 | 88 | case 2: |
89 | - $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' . $addChars; |
|
89 | + $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.$addChars; |
|
90 | 90 | break; |
91 | 91 | case 3: |
92 | - $chars = 'abcdefghijklmnopqrstuvwxyz' . $addChars; |
|
92 | + $chars = 'abcdefghijklmnopqrstuvwxyz'.$addChars; |
|
93 | 93 | break; |
94 | 94 | case 4: |
95 | - $chars = "们以我到他会作时要动国产的一是工就年阶义发成部民可出能方进在了不和有大这主中人上为来分生对于学下级地个用同行面说种过命度革而多子后自社加小机也经力线本电高量长党得实家定深法表着水理化争现所二起政三好十战无农使性前等反体合斗路图把结第里正新开论之物从当两些还天资事队批点育重其思与间内去因件日利相由压员气业代全组数果期导平各基或月毛然如应形想制心样干都向变关问比展那它最及外没看治提五解系林者米群头意只明四道马认次文通但条较克又公孔领军流入接席位情运器并飞原油放立题质指建区验活众很教决特此常石强极土少已根共直团统式转别造切九你取西持总料连任志观调七么山程百报更见必真保热委手改管处己将修支识病象几先老光专什六型具示复安带每东增则完风回南广劳轮科北打积车计给节做务被整联步类集号列温装即毫知轴研单色坚据速防史拉世设达尔场织历花受求传口断况采精金界品判参层止边清至万确究书" . $addChars; |
|
95 | + $chars = "们以我到他会作时要动国产的一是工就年阶义发成部民可出能方进在了不和有大这主中人上为来分生对于学下级地个用同行面说种过命度革而多子后自社加小机也经力线本电高量长党得实家定深法表着水理化争现所二起政三好十战无农使性前等反体合斗路图把结第里正新开论之物从当两些还天资事队批点育重其思与间内去因件日利相由压员气业代全组数果期导平各基或月毛然如应形想制心样干都向变关问比展那它最及外没看治提五解系林者米群头意只明四道马认次文通但条较克又公孔领军流入接席位情运器并飞原油放立题质指建区验活众很教决特此常石强极土少已根共直团统式转别造切九你取西持总料连任志观调七么山程百报更见必真保热委手改管处己将修支识病象几先老光专什六型具示复安带每东增则完风回南广劳轮科北打积车计给节做务被整联步类集号列温装即毫知轴研单色坚据速防史拉世设达尔场织历花受求传口断况采精金界品判参层止边清至万确究书".$addChars; |
|
96 | 96 | break; |
97 | 97 | default: |
98 | - $chars = 'ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789' . $addChars; |
|
98 | + $chars = 'ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789'.$addChars; |
|
99 | 99 | break; |
100 | 100 | } |
101 | 101 | if ($length > 10) { |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | if (!ctype_lower($value)) { |
177 | 177 | $value = preg_replace('/\s+/u', '', ucwords($value)); |
178 | 178 | |
179 | - $value = static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1' . $delimiter, $value)); |
|
179 | + $value = static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1'.$delimiter, $value)); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | return static::$snakeCache[$key][$delimiter] = $value; |
@@ -259,16 +259,16 @@ discard block |
||
259 | 259 | static public function createChannelId($namespace = ''):string { |
260 | 260 | static $guid = ''; |
261 | 261 | $uid = uniqid("", true); |
262 | - $data = $namespace. md5(time() . mt_rand(1,1000000)).uniqid(); |
|
263 | - $hash = strtoupper(hash('ripemd128', $uid . $guid . md5($data))); |
|
264 | - $guid = substr($hash, 0, 8) . |
|
265 | - '-' . |
|
266 | - substr($hash, 8, 4) . |
|
267 | - '-' . |
|
268 | - substr($hash, 12, 4) . |
|
269 | - '-' . |
|
270 | - substr($hash, 16, 4) . |
|
271 | - '-' . |
|
262 | + $data = $namespace.md5(time().mt_rand(1, 1000000)).uniqid(); |
|
263 | + $hash = strtoupper(hash('ripemd128', $uid.$guid.md5($data))); |
|
264 | + $guid = substr($hash, 0, 8). |
|
265 | + '-'. |
|
266 | + substr($hash, 8, 4). |
|
267 | + '-'. |
|
268 | + substr($hash, 12, 4). |
|
269 | + '-'. |
|
270 | + substr($hash, 16, 4). |
|
271 | + '-'. |
|
272 | 272 | substr($hash, 20, 12); |
273 | 273 | return $guid; |
274 | 274 | } |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | * @return string |
282 | 282 | */ |
283 | 283 | static public function md5Bit16($str):string { |
284 | - return strtoupper(substr(md5($str),8,16)); |
|
284 | + return strtoupper(substr(md5($str), 8, 16)); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | /** |
@@ -291,15 +291,15 @@ discard block |
||
291 | 291 | * @return int |
292 | 292 | */ |
293 | 293 | static public function millisecond($time = null) :int{ |
294 | - if(empty($time)){ |
|
294 | + if (empty($time)) { |
|
295 | 295 | list($msec, $sec) = explode(' ', microtime()); |
296 | - $millisecond = (int)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); |
|
297 | - }elseif(is_numeric($time) && strlen((string)$time)==10){ |
|
298 | - $millisecond = (string)$time."000"; |
|
299 | - }else{ |
|
296 | + $millisecond = (int) sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); |
|
297 | + }elseif (is_numeric($time) && strlen((string) $time) == 10) { |
|
298 | + $millisecond = (string) $time."000"; |
|
299 | + } else { |
|
300 | 300 | $millisecond = strtotime($time)."000"; |
301 | 301 | } |
302 | - return (int)$millisecond; |
|
302 | + return (int) $millisecond; |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | /** |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | * @param string $string |
309 | 309 | * @return bool |
310 | 310 | */ |
311 | - public static function isContainChinese($string=''):bool { |
|
311 | + public static function isContainChinese($string = ''):bool { |
|
312 | 312 | $result = preg_match('/[\x{4e00}-\x{9fa5}]/u', $string); |
313 | 313 | return $result == 0 ? false : true; |
314 | 314 | } |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | * @param string $string |
320 | 320 | * @return bool |
321 | 321 | */ |
322 | - public static function isAllChinese($string=''):bool { |
|
322 | + public static function isAllChinese($string = ''):bool { |
|
323 | 323 | $result = preg_match('/^[\x{4e00}-\x{9fa5}]+$/u', $string); |
324 | 324 | return $result == 0 ? false : true; |
325 | 325 | } |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | * @param string $string |
332 | 332 | * @return bool |
333 | 333 | */ |
334 | - public static function isMobile($string=''):bool { |
|
334 | + public static function isMobile($string = ''):bool { |
|
335 | 335 | if (!preg_match("/(^1[3|4|5|7|8][0-9]{9}$)/", $string)) { |
336 | 336 | return false; |
337 | 337 | } |
@@ -346,9 +346,9 @@ discard block |
||
346 | 346 | * @param int $double 小数点保留位数 默认3位 |
347 | 347 | * @return string |
348 | 348 | */ |
349 | - public static function sctonum($num, $double = 3){ |
|
350 | - if(false !== stripos($num, "e")){ |
|
351 | - $a = explode("e",strtolower($num)); |
|
349 | + public static function sctonum($num, $double = 3) { |
|
350 | + if (false !== stripos($num, "e")) { |
|
351 | + $a = explode("e", strtolower($num)); |
|
352 | 352 | return bcmul($a[0], bcpow(10, $a[1], $double), $double); |
353 | 353 | } |
354 | 354 | return $num; |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | * @param string $to |
363 | 363 | * @return array|false|string|string[]|null |
364 | 364 | */ |
365 | - public static function autoCharset($string, $from='gbk', $to='utf-8') { |
|
365 | + public static function autoCharset($string, $from = 'gbk', $to = 'utf-8') { |
|
366 | 366 | $from = strtoupper($from) == 'UTF8' ? 'utf-8' : $from; |
367 | 367 | $to = strtoupper($to) == 'UTF8' ? 'utf-8' : $to; |
368 | 368 | if (strtoupper($from) === strtoupper($to) || empty($string) || (is_scalar($string) && !is_string($string))) { |
@@ -398,7 +398,7 @@ discard block |
||
398 | 398 | * @param $html |
399 | 399 | * @return string |
400 | 400 | */ |
401 | - public static function filterATag($html=''):string { |
|
401 | + public static function filterATag($html = ''):string { |
|
402 | 402 | return preg_replace("#<a[^>]*>(.*?)</a>#is", "$1", $html); |
403 | 403 | } |
404 | 404 | |
@@ -409,7 +409,7 @@ discard block |
||
409 | 409 | * @param $html |
410 | 410 | * @return string |
411 | 411 | */ |
412 | - public static function deleteATag($html=''):string { |
|
412 | + public static function deleteATag($html = ''):string { |
|
413 | 413 | return preg_replace("#<a[^>]*>(.*?)</a>#is", "", $html); |
414 | 414 | } |
415 | 415 | |
@@ -421,36 +421,36 @@ discard block |
||
421 | 421 | * @param bool $is_timestamp 是否是时间戳 |
422 | 422 | * @return string |
423 | 423 | */ |
424 | - public static function getTime($date,$is_timestamp=false):string { |
|
425 | - if($is_timestamp === true){ |
|
424 | + public static function getTime($date, $is_timestamp = false):string { |
|
425 | + if ($is_timestamp === true) { |
|
426 | 426 | $time = $date; |
427 | - }else{ |
|
428 | - $time = strtotime($date);//时间转换为时间戳 |
|
427 | + } else { |
|
428 | + $time = strtotime($date); //时间转换为时间戳 |
|
429 | 429 | } |
430 | 430 | |
431 | - if($time >= time()){ |
|
431 | + if ($time >= time()) { |
|
432 | 432 | return '刚刚'; |
433 | 433 | } |
434 | 434 | $seconds = time() - $time; |
435 | - if($seconds <= 60){ |
|
435 | + if ($seconds <= 60) { |
|
436 | 436 | return '刚刚'; |
437 | 437 | } |
438 | 438 | $minutes = intval($seconds / 60); |
439 | - if($minutes <= 60){ |
|
439 | + if ($minutes <= 60) { |
|
440 | 440 | return $minutes.'分钟前'; |
441 | 441 | } |
442 | 442 | $hours = intval($minutes / 60); |
443 | - if($hours <= 24){ |
|
443 | + if ($hours <= 24) { |
|
444 | 444 | return $hours.'小时前'; |
445 | 445 | } |
446 | 446 | $days = intval($hours / 24); |
447 | - if($days <= 3){ |
|
447 | + if ($days <= 3) { |
|
448 | 448 | return $days.'天前'; |
449 | 449 | } |
450 | - if($days <= 365){ |
|
451 | - return date('m-d',/** @scrutinizer ignore-type */ $time); |
|
450 | + if ($days <= 365) { |
|
451 | + return date('m-d', /** @scrutinizer ignore-type */ $time); |
|
452 | 452 | } |
453 | - return date('Y-m-d',$time); |
|
453 | + return date('Y-m-d', $time); |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | /** |
@@ -464,11 +464,11 @@ discard block |
||
464 | 464 | $compress = ''; |
465 | 465 | foreach ($chunks as $c) { |
466 | 466 | if (strtolower(substr($c, 0, 19)) == '<!--<nocompress>-->') { |
467 | - $c = substr($c, 19, strlen($c) - 19 - 20); |
|
467 | + $c = substr($c, 19, strlen($c) - 19 - 20); |
|
468 | 468 | $compress .= $c; |
469 | 469 | continue; |
470 | 470 | } elseif (strtolower(substr($c, 0, 12)) == '<nocompress>') { |
471 | - $c = substr($c, 12, strlen($c) - 12 - 13); |
|
471 | + $c = substr($c, 12, strlen($c) - 12 - 13); |
|
472 | 472 | $compress .= $c; |
473 | 473 | continue; |
474 | 474 | } elseif (strtolower(substr($c, 0, 4)) == '<pre' || strtolower(substr($c, 0, 9)) == '<textarea') { |
@@ -516,14 +516,14 @@ discard block |
||
516 | 516 | * @return mixed |
517 | 517 | */ |
518 | 518 | static public function htmlReplaceXcx(string $content):string { |
519 | - $content = str_replace("\r\n","",$content);//出除回车和换行符 |
|
520 | - $content = preg_replace("/style=\".*?\"/si",'',$content);//style样式 |
|
521 | - $content = preg_replace(["/<strong.*?>/si", "/<\/strong>/si"],['<text class="wx-strong">','</text>'],$content);//strong |
|
522 | - $content = preg_replace(["/<p.*?>/si", "/<\/p>/si"],['<view class="wx-p">','</view>'],$content);//p |
|
523 | - $content = preg_replace(["/<a.*?>/si", "/<\/a>/si"],['<text class="wx-a">','</text>'],$content);//a |
|
524 | - $content = preg_replace(["/<span.*?>/si", "/<\/span>/si"],['<text class="wx-span">','</text>'],$content);//span |
|
525 | - $content = preg_replace(["/<h[1-6].*?>/si", "/<\/h[1-6]>/si"],['<view class="wx-h">','</view>'],$content);//h |
|
526 | - $content = preg_replace("/<img.*?/si",'<image class="wx-img"',$content);//img |
|
519 | + $content = str_replace("\r\n", "", $content); //出除回车和换行符 |
|
520 | + $content = preg_replace("/style=\".*?\"/si", '', $content); //style样式 |
|
521 | + $content = preg_replace(["/<strong.*?>/si", "/<\/strong>/si"], ['<text class="wx-strong">', '</text>'], $content); //strong |
|
522 | + $content = preg_replace(["/<p.*?>/si", "/<\/p>/si"], ['<view class="wx-p">', '</view>'], $content); //p |
|
523 | + $content = preg_replace(["/<a.*?>/si", "/<\/a>/si"], ['<text class="wx-a">', '</text>'], $content); //a |
|
524 | + $content = preg_replace(["/<span.*?>/si", "/<\/span>/si"], ['<text class="wx-span">', '</text>'], $content); //span |
|
525 | + $content = preg_replace(["/<h[1-6].*?>/si", "/<\/h[1-6]>/si"], ['<view class="wx-h">', '</view>'], $content); //h |
|
526 | + $content = preg_replace("/<img.*?/si", '<image class="wx-img"', $content); //img |
|
527 | 527 | return $content; |
528 | 528 | } |
529 | 529 | |
@@ -535,8 +535,8 @@ discard block |
||
535 | 535 | * @return string |
536 | 536 | */ |
537 | 537 | static public function pReplaceSpan(string $content):string { |
538 | - $content = str_replace(["\r","\n","\t"],'',$content); |
|
539 | - $content = preg_replace(["/<p/si", "/<\/p>/si"],['<span','</span><br>'],$content);//p |
|
538 | + $content = str_replace(["\r", "\n", "\t"], '', $content); |
|
539 | + $content = preg_replace(["/<p/si", "/<\/p>/si"], ['<span', '</span><br>'], $content); //p |
|
540 | 540 | return $content; |
541 | 541 | } |
542 | 542 | |
@@ -547,10 +547,10 @@ discard block |
||
547 | 547 | * @param string $keyword |
548 | 548 | * @return string |
549 | 549 | */ |
550 | - static public function filterPunctuation($keyword){ |
|
551 | - $keyword = str_replace(["\r\n", "\r", "\n"," "," "], "", trim($keyword));//删除空格 |
|
552 | - $keyword = preg_replace('# #','',$keyword); |
|
553 | - $keyword = preg_replace("/[ '.,:;*?~`!@#$%^&+=)(<>{}]|\]|\[|\/|\\\|\"|\|/",'',$keyword); |
|
550 | + static public function filterPunctuation($keyword) { |
|
551 | + $keyword = str_replace(["\r\n", "\r", "\n", " ", " "], "", trim($keyword)); //删除空格 |
|
552 | + $keyword = preg_replace('# #', '', $keyword); |
|
553 | + $keyword = preg_replace("/[ '.,:;*?~`!@#$%^&+=)(<>{}]|\]|\[|\/|\\\|\"|\|/", '', $keyword); |
|
554 | 554 | return $keyword; |
555 | 555 | } |
556 | 556 | |
@@ -562,9 +562,9 @@ discard block |
||
562 | 562 | * @param string $allowable_tags |
563 | 563 | * @return string |
564 | 564 | */ |
565 | - static public function stripTags($content,$allowable_tags = '<font>'){ |
|
566 | - $content = strip_tags($content,$allowable_tags);//替换标签 |
|
567 | - $content = str_replace(["\r\n", "\r", "\n"," "], "", trim($content));//删除空格 |
|
565 | + static public function stripTags($content, $allowable_tags = '<font>') { |
|
566 | + $content = strip_tags($content, $allowable_tags); //替换标签 |
|
567 | + $content = str_replace(["\r\n", "\r", "\n", " "], "", trim($content)); //删除空格 |
|
568 | 568 | return $content; |
569 | 569 | } |
570 | 570 |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * Description: Tool.php. |
9 | 9 | */ |
10 | 10 | |
11 | -class ArrayTool{ |
|
11 | +class ArrayTool { |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * @param $arr |
@@ -16,20 +16,20 @@ discard block |
||
16 | 16 | * @param $type |
17 | 17 | * @return array |
18 | 18 | */ |
19 | - static public function arraySort($arr,$keys,$type='asc'){ |
|
19 | + static public function arraySort($arr, $keys, $type = 'asc') { |
|
20 | 20 | $keysValue = $newArray = array(); |
21 | - foreach ($arr as $k=>$v){ |
|
22 | - if(isset($v[$keys])){ |
|
21 | + foreach ($arr as $k=>$v) { |
|
22 | + if (isset($v[$keys])) { |
|
23 | 23 | $keysValue[$k] = $v[$keys]; |
24 | 24 | } |
25 | 25 | } |
26 | - if($type == 'asc'){ |
|
26 | + if ($type == 'asc') { |
|
27 | 27 | asort($keysValue); |
28 | - }else{ |
|
28 | + } else { |
|
29 | 29 | arsort($keysValue); |
30 | 30 | } |
31 | 31 | reset($keysValue); |
32 | - foreach ($keysValue as $k=>$v){ |
|
32 | + foreach ($keysValue as $k=>$v) { |
|
33 | 33 | $newArray[$k] = $arr[$k]; |
34 | 34 | } |
35 | 35 | return array_values($newArray); |
@@ -46,14 +46,14 @@ discard block |
||
46 | 46 | * @param string $childrenName child |
47 | 47 | * @return array |
48 | 48 | */ |
49 | - public static function getTreeStructureRecursion(array $list,string $filed='id',string $parentFiled='pid',int $parentId=0,string $childrenName = 'child') |
|
49 | + public static function getTreeStructureRecursion(array $list, string $filed = 'id', string $parentFiled = 'pid', int $parentId = 0, string $childrenName = 'child') |
|
50 | 50 | { |
51 | 51 | $result = array(); |
52 | - if(!empty($list)){ |
|
53 | - foreach($list as $val){ |
|
54 | - if($val[$parentFiled] == $parentId){ |
|
55 | - $val[$childrenName] = self::getTreeStructureRecursion($list,$filed,$parentFiled,$val[$filed]); |
|
56 | - if(empty($val[$childrenName])){ |
|
52 | + if (!empty($list)) { |
|
53 | + foreach ($list as $val) { |
|
54 | + if ($val[$parentFiled] == $parentId) { |
|
55 | + $val[$childrenName] = self::getTreeStructureRecursion($list, $filed, $parentFiled, $val[$filed]); |
|
56 | + if (empty($val[$childrenName])) { |
|
57 | 57 | unset($val[$childrenName]); |
58 | 58 | } |
59 | 59 | $result[] = $val; |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * @param string $childrenName child |
74 | 74 | * @return array |
75 | 75 | */ |
76 | - public static function getTreeStructure(array $list,string $filed = 'id', string $parentFiled = 'pid', string $childrenName = 'child') |
|
76 | + public static function getTreeStructure(array $list, string $filed = 'id', string $parentFiled = 'pid', string $childrenName = 'child') |
|
77 | 77 | { |
78 | 78 | $result = array(); |
79 | 79 | foreach ($list as $value) { |
@@ -97,12 +97,12 @@ discard block |
||
97 | 97 | * @param $obj |
98 | 98 | * @return array |
99 | 99 | */ |
100 | - public static function objectToArray($obj){ |
|
101 | - if(!is_object($obj) && !is_array($obj)) { |
|
100 | + public static function objectToArray($obj) { |
|
101 | + if (!is_object($obj) && !is_array($obj)) { |
|
102 | 102 | return $obj; |
103 | 103 | } |
104 | 104 | $arr = array(); |
105 | - foreach($obj as $k => $v){ |
|
105 | + foreach ($obj as $k => $v) { |
|
106 | 106 | $arr[$k] = self::objectToArray($v); |
107 | 107 | } |
108 | 108 | return $arr; |
@@ -114,12 +114,12 @@ discard block |
||
114 | 114 | * @Author: TinyMeng <[email protected]> |
115 | 115 | * @param $data |
116 | 116 | */ |
117 | - public static function nullArrayToObject(&$data){ |
|
118 | - foreach ($data as $key=>&$val){ |
|
119 | - if(is_array($val)){ |
|
120 | - if(empty($val)){ |
|
121 | - settype($val,'object'); |
|
122 | - }else{ |
|
117 | + public static function nullArrayToObject(&$data) { |
|
118 | + foreach ($data as $key=>&$val) { |
|
119 | + if (is_array($val)) { |
|
120 | + if (empty($val)) { |
|
121 | + settype($val, 'object'); |
|
122 | + } else { |
|
123 | 123 | self::nullArrayToObject($val); |
124 | 124 | } |
125 | 125 | } |