diff --git a/function.php b/function.php index 7e6f4e31..b22a214b 100644 --- a/function.php +++ b/function.php @@ -19,8 +19,8 @@ use Psr\Log\LoggerInterface; use Swoole\Process; if (!function_exists('make')) { - - + + /** * @param $name * @param $default @@ -34,25 +34,25 @@ if (!function_exists('make')) { } return Kiri::getDi()->get($name); } - + } if (!function_exists('isJson')) { - - + + function isJson(?string $string): bool { if (is_null($string)) return false; return (str_starts_with($string, '{') && str_ends_with($string, '}')) || (str_ends_with($string, '[') && str_starts_with($string, ']')); } - + } if (!function_exists('instance')) { - - + + /** * @param $class * @param array $constrict @@ -63,14 +63,14 @@ if (!function_exists('instance')) { { return Kiri::getDi()->create($class, $constrict, $config); } - - + + } if (!function_exists('call')) { - - + + /** * @param $handler * @param mixed ...$params @@ -87,13 +87,13 @@ if (!function_exists('call')) { } return call_user_func($handler, ...$params); } - + } if (!function_exists('map')) { - - + + /** * @param array $params * @param Closure $closure @@ -103,13 +103,13 @@ if (!function_exists('map')) { { return array_map($closure, $params); } - + } if (!function_exists('checkPortIsAlready')) { - - + + /** * @param $port * @return bool|string @@ -123,24 +123,24 @@ if (!function_exists('checkPortIsAlready')) { $output = explode(PHP_EOL, $output[0]); return $output[0]; } - + $serverPid = file_get_contents(storage('.swoole.pid')); if (!empty($serverPid) && shell_exec('ps -ef | grep ' . $serverPid . ' | grep -v grep')) { Process::kill($serverPid, 0) && Process::kill($serverPid, SIGTERM); } - + exec('netstat -lnp | grep ' . $port . ' | grep "LISTEN" | awk \'{print $7}\'', $output); if (empty($output)) { return FALSE; } return explode('/', $output[0])[0]; } - + } if (!function_exists('done')) { - + /** * */ @@ -148,13 +148,13 @@ if (!function_exists('done')) { { set_env('state', 'exit'); } - + } if (!function_exists('set_env')) { - - + + /** * @param $key * @param $value @@ -163,24 +163,24 @@ if (!function_exists('set_env')) { { putenv(sprintf('%s=%s', $key, $value)); } - + } if (!function_exists('enable_file_modification_listening')) { - - + + function enable_file_modification_listening(): void { putenv('enable_file_modification_listening=on'); } - - + + } if (!function_exists('is_enable_file_modification_listening')) { - - + + /** * @return bool */ @@ -188,24 +188,24 @@ if (!function_exists('is_enable_file_modification_listening')) { { return env('enable_file_modification_listening', 'off') == 'on'; } - - + + } if (!function_exists('disable_file_modification_listening')) { - - + + function disable_file_modification_listening() { putenv('enable_file_modification_listening=off'); } - - + + } if (!function_exists('now')) { - + /** * @return string */ @@ -217,8 +217,8 @@ if (!function_exists('now')) { if (!function_exists('Annotation')) { - - + + /** * @return Annotation * @throws Exception @@ -227,14 +227,14 @@ if (!function_exists('Annotation')) { { return Kiri::getAnnotation(); } - - + + } if (!function_exists('scan_directory')) { - - + + /** * @param $dir * @param $namespace @@ -246,16 +246,16 @@ if (!function_exists('scan_directory')) { { $annotation = Kiri::getDi()->get(Annotation::class); $annotation->read($dir, $namespace, $exclude); - + injectRuntime($dir, $exclude); } - + } if (!function_exists('injectRuntime')) { - - + + /** * @param string $path * @param array $exclude @@ -265,7 +265,7 @@ if (!function_exists('injectRuntime')) { function injectRuntime(string $path, array $exclude = []): void { $fileLists = Kiri::getAnnotation()->runtime($path, $exclude); - + $router = []; foreach ($fileLists as $class) { $target = TargetManager::get($class); @@ -277,8 +277,8 @@ if (!function_exists('injectRuntime')) { } $value->execute($class); } - - + + $methods = $target->getMethodsAttribute(); foreach ($methods as $method => $attribute) { /** @var ReflectionAttribute $item */ @@ -308,12 +308,12 @@ if (!function_exists('injectRuntime')) { } } } - + } if (!function_exists('directory')) { - + /** * @param $name * @return string @@ -322,14 +322,14 @@ if (!function_exists('directory')) { { return realpath(APP_PATH . $name); } - - + + } if (!function_exists('isUrl')) { - - + + /** * @param $url * @param bool $get_info @@ -344,24 +344,24 @@ if (!function_exists('isUrl')) { if (!preg_match($queryMatch, $url, $outPut)) { return FALSE; } - + [$scheme, $host, $port, $user, $pass, $query, $path, $fragment] = parse_url($url); if ($scheme == 'https' && empty($port)) { $port = 443; } - + if (!empty($query)) $path .= '?' . $query; if (!empty($fragment)) $path .= '#' . $fragment; - + return [$scheme == 'https', $host, $port, $path]; } - + } if (!function_exists('split_request_uri')) { - - + + /** * @param $url * @return false|array @@ -371,7 +371,7 @@ if (!function_exists('split_request_uri')) { if (($parse = isUrl($url, NULL)) === FALSE) { return FALSE; } - + [$isHttps, $domain, $port, $path] = $parse; $uri = $isHttps ? 'https://' . $domain : 'http://' . $domain; if (!empty($port)) { @@ -379,13 +379,13 @@ if (!function_exists('split_request_uri')) { } return [$uri, $path]; } - + } if (!function_exists('hadDomain')) { - - + + /** * @param $url * @return false|array @@ -395,13 +395,13 @@ if (!function_exists('hadDomain')) { $param = split_request_uri($url); return !is_array($param) ? FALSE : $param[0]; } - + } if (!function_exists('isDomain')) { - - + + /** * @param $url * @return false|array @@ -410,11 +410,11 @@ if (!function_exists('isDomain')) { { return !isIp($url); } - + } if (!function_exists('isIp')) { - - + + /** * @param $url * @return false|array @@ -423,13 +423,13 @@ if (!function_exists('isIp')) { { return preg_match('/(\d{1,3}\.){3}\.\d{1,3}(:\d{1,5})?/', $url); } - + } if (!function_exists('loadByDir')) { - - + + /** * @param $namespace * @param $dirname @@ -445,25 +445,25 @@ if (!function_exists('loadByDir')) { if ($pos === FALSE || strlen($value) - 4 != $pos) { continue; } - + $replace = ltrim(str_replace(__DIR__, '', $value), '/'); $replace = str_replace('.php', '', $replace); - + $first = explode(DIRECTORY_SEPARATOR, $replace); array_shift($first); - + Kiri::setAutoload($namespace . '\\' . implode('\\', $first), $value); } } } - - + + } if (!function_exists('redis')) { - - + + /** * @return \Kiri\Redis\Redis|Redis * @throws Exception @@ -475,8 +475,8 @@ if (!function_exists('redis')) { } if (!function_exists('fire')) { - - + + /** * @param object $event */ @@ -487,8 +487,8 @@ if (!function_exists('fire')) { } if (!function_exists('instance_load')) { - - + + /** * @return void */ @@ -502,12 +502,12 @@ if (!function_exists('instance_load')) { } } } - + } if (!function_exists('exif_imagetype')) { - + /** * @param $name * @return string @@ -520,8 +520,8 @@ if (!function_exists('exif_imagetype')) { if (!function_exists('logger')) { - - + + /** * @throws Exception */ @@ -533,8 +533,8 @@ if (!function_exists('logger')) { if (!function_exists('trim_blank')) { - - + + /** * 空白字符替换 * @param string $content 内容 @@ -561,224 +561,224 @@ if (!function_exists('trim_blank')) { if (!function_exists('get_file_extension')) { - + function get_file_extension($filename): bool|int|string { $mime_types = [ - 'txt' => 'text/plain', - 'htm' => 'text/html', + 'txt' => 'text/plain', + 'htm' => 'text/html', 'html' => 'text/html', - 'php' => 'text/html', - 'css' => 'text/css', - 'js' => 'application/javascript', + 'php' => 'text/html', + 'css' => 'text/css', + 'js' => 'application/javascript', 'json' => 'application/json', - 'xml' => 'application/xml', - 'swf' => 'application/x-shockwave-flash', - 'flv' => 'video/x-flv', - + 'xml' => 'application/xml', + 'swf' => 'application/x-shockwave-flash', + 'flv' => 'video/x-flv', + // images - 'png' => 'image/png', + 'png' => 'image/png', 'jpeg' => 'image/jpeg', - 'gif' => 'image/gif', - 'bmp' => 'image/bmp', - 'ico' => 'image/vnd.microsoft.icon', + 'gif' => 'image/gif', + 'bmp' => 'image/bmp', + 'ico' => 'image/vnd.microsoft.icon', 'tiff' => 'image/tiff', - 'svg' => 'image/svg+xml', - + 'svg' => 'image/svg+xml', + // archives - 'zip' => 'application/zip', - 'rar' => 'application/x-rar-compressed', - 'exe' => 'application/x-msdownload', - 'msi' => 'application/x-msdownload', - 'cab' => 'application/vnd.ms-cab-compressed', - + 'zip' => 'application/zip', + 'rar' => 'application/x-rar-compressed', + 'exe' => 'application/x-msdownload', + 'msi' => 'application/x-msdownload', + 'cab' => 'application/vnd.ms-cab-compressed', + // audio/video - 'mp3' => 'audio/mpeg', - 'qt' => 'video/quicktime', - 'mov' => 'video/quicktime', - + 'mp3' => 'audio/mpeg', + 'qt' => 'video/quicktime', + 'mov' => 'video/quicktime', + // adobe - 'pdf' => 'application/pdf', - 'psd' => 'image/vnd.adobe.photoshop', - 'ai' => 'application/postscript', - 'eps' => 'application/postscript', - 'ps' => 'application/postscript', - + 'pdf' => 'application/pdf', + 'psd' => 'image/vnd.adobe.photoshop', + 'ai' => 'application/postscript', + 'eps' => 'application/postscript', + 'ps' => 'application/postscript', + // ms office - 'doc' => 'application/msword', - 'rtf' => 'application/rtf', - 'xls' => 'application/vnd.ms-excel', - 'ppt' => 'application/vnd.ms-powerpoint', - + 'doc' => 'application/msword', + 'rtf' => 'application/rtf', + 'xls' => 'application/vnd.ms-excel', + 'ppt' => 'application/vnd.ms-powerpoint', + // open office - 'odt' => 'application/vnd.oasis.opendocument.text', - 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', - - - '323' => 'text / h323', - 'acx' => 'application/internet-property-stream', - 'aif' => 'audio/x-aiff', - 'aifc' => 'audio/x-aiff', - 'aiff' => 'audio/x-aiff', - 'asf' => 'video/x-ms-asf', - 'asr' => 'video/x-ms-asf', - 'asx' => 'video/x-ms-asf', - 'au' => 'audio/basic', - 'avi' => 'video/x-msvideo', - 'axs' => 'application/olescript', - 'bas' => 'text/plain', - 'bcpio' => 'application/x-bcpio', - 'bin' => 'application/octet-stream', - 'c' => 'text/plain', - 'cat' => 'application/vnd.ms-pkiseccat', - 'cdf' => 'application/x-cdf', - 'cer' => 'application/x-x509-ca-cert', - 'class' => 'application/octet-stream', - 'clp' => 'application/x-msclip', - 'cmx' => 'image/x-cmx', - 'cod' => 'image/cis-cod', - 'cpio' => 'application/x-cpio', - 'crd' => 'application/x-mscardfile', - 'crl' => 'application/pkix-crl', - 'crt' => 'application/x-x509-ca-cert', - 'csh' => 'application/x-csh', - 'dcr' => 'application/x-director', - 'der' => 'application/x-x509-ca-cert', - 'dir' => 'application/x-director', - 'dll' => 'application/x-msdownload', - 'dms' => 'application/octet-stream', - 'dot' => 'application/msword', - 'dvi' => 'application/x-dvi', - 'dxr' => 'application/x-director', - 'etx' => 'text/x-setext', - 'evy' => 'application/envoy', - 'fif' => 'application/fractals', - 'flr' => 'x-world/x-vrml', - 'gtar' => 'application/x-gtar', - 'gz' => 'application/x-gzip', - 'h' => 'text/plain', - 'hdf' => 'application/x-hdf', - 'hlp' => 'application/winhlp', - 'hqx' => 'application/mac-binhex40', - 'hta' => 'application/hta', - 'htc' => 'text/x-component', - 'htt' => 'text/webviewhtml', - 'ief' => 'image/ief', - 'iii' => 'application/x-iphone', - 'ins' => 'application/x-internet-signup', - 'isp' => 'application/x-internet-signup', - 'jfif' => 'image/pipeg', - 'jpe' => 'image/jpeg', - 'jpg' => 'image/jpeg', - 'latex' => 'application/x-latex', - 'lha' => 'application/octet-stream', - 'lsf' => 'video/x-la-asf', - 'lsx' => 'video/x-la-asf', - 'lzh' => 'application/octet-stream', - 'm13' => 'application/x-msmediaview', - 'm14' => 'application/x-msmediaview', - 'm3u' => 'audio/x-mpegurl', - 'man' => 'application/x-troff-man', - 'mdb' => 'application/x-msaccess', - 'me' => 'application/x-troff-me', - 'mht' => 'message/rfc822', - 'mhtml' => 'message/rfc822', - 'mid' => 'audio/mid', - 'mny' => 'application/x-msmoney', - 'movie' => 'video/x-sgi-movie', - 'mp2' => 'video/mpeg', - 'mpa' => 'video/mpeg', - 'mpe' => 'video/mpeg', - 'mpeg' => 'video/mpeg', - 'mpg' => 'video/mpeg', - 'mpp' => 'application/vnd.ms-project', - 'mpv2' => 'video/mpeg', - 'ms' => 'application/x-troff-ms', - 'mvb' => 'application/x-msmediaview', - 'nws' => 'message/rfc822', - 'oda' => 'application/oda', - 'p10' => 'application/pkcs10', - 'p12' => 'application/x-pkcs12', - 'p7b' => 'application/x-pkcs7-certificates', - 'p7c' => 'application/x-pkcs7-mime', - 'p7m' => 'application/x-pkcs7-mime', - 'p7r' => 'application/x-pkcs7-certreqresp', - 'p7s' => 'application/x-pkcs7-signature', - 'pbm' => 'image/x-portable-bitmap', - 'pfx' => 'application/x-pkcs12', - 'pgm' => 'image/x-portable-graymap', - 'pko' => 'application/ynd.ms-pkipko', - 'pma' => 'application/x-perfmon', - 'pmc' => 'application/x-perfmon', - 'pml' => 'application/x-perfmon', - 'pmr' => 'application/x-perfmon', - 'pmw' => 'application/x-perfmon', - 'pnm' => 'image/x-portable-anymap', - 'pot' => 'application/vnd.ms-powerpoint', - 'ppm' => 'image/x-portable-pixmap', - 'pps' => 'application/vnd.ms-powerpoint', - 'prf' => 'application/pics-rules', - 'pub' => 'application/x-mspublisher', - 'ra' => 'audio/x-pn-realaudio', - 'ram' => 'audio/x-pn-realaudio', - 'ras' => 'image/x-cmu-raster', - 'rgb' => 'image/x-rgb', - 'rmi' => 'audio/mid', - 'roff' => 'application/x-troff', - 'rtx' => 'text/richtext', - 'scd' => 'application/x-msschedule', - 'sct' => 'text/scriptlet', - 'setpay' => 'application/set-payment-initiation', - 'setreg' => 'application/set-registration-initiation', - 'sh' => 'application/x-sh', - 'shar' => 'application/x-shar', - 'sit' => 'application/x-stuffit', - 'snd' => 'audio/basic', - 'spc' => 'application/x-pkcs7-certificates', - 'spl' => 'application/futuresplash', - 'src' => 'application/x-wais-source', - 'sst' => 'application/vnd.ms-pkicertstore', - 'stl' => 'application/vnd.ms-pkistl', - 'stm' => 'text/html', + 'odt' => 'application/vnd.oasis.opendocument.text', + 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', + + + '323' => 'text / h323', + 'acx' => 'application/internet-property-stream', + 'aif' => 'audio/x-aiff', + 'aifc' => 'audio/x-aiff', + 'aiff' => 'audio/x-aiff', + 'asf' => 'video/x-ms-asf', + 'asr' => 'video/x-ms-asf', + 'asx' => 'video/x-ms-asf', + 'au' => 'audio/basic', + 'avi' => 'video/x-msvideo', + 'axs' => 'application/olescript', + 'bas' => 'text/plain', + 'bcpio' => 'application/x-bcpio', + 'bin' => 'application/octet-stream', + 'c' => 'text/plain', + 'cat' => 'application/vnd.ms-pkiseccat', + 'cdf' => 'application/x-cdf', + 'cer' => 'application/x-x509-ca-cert', + 'class' => 'application/octet-stream', + 'clp' => 'application/x-msclip', + 'cmx' => 'image/x-cmx', + 'cod' => 'image/cis-cod', + 'cpio' => 'application/x-cpio', + 'crd' => 'application/x-mscardfile', + 'crl' => 'application/pkix-crl', + 'crt' => 'application/x-x509-ca-cert', + 'csh' => 'application/x-csh', + 'dcr' => 'application/x-director', + 'der' => 'application/x-x509-ca-cert', + 'dir' => 'application/x-director', + 'dll' => 'application/x-msdownload', + 'dms' => 'application/octet-stream', + 'dot' => 'application/msword', + 'dvi' => 'application/x-dvi', + 'dxr' => 'application/x-director', + 'etx' => 'text/x-setext', + 'evy' => 'application/envoy', + 'fif' => 'application/fractals', + 'flr' => 'x-world/x-vrml', + 'gtar' => 'application/x-gtar', + 'gz' => 'application/x-gzip', + 'h' => 'text/plain', + 'hdf' => 'application/x-hdf', + 'hlp' => 'application/winhlp', + 'hqx' => 'application/mac-binhex40', + 'hta' => 'application/hta', + 'htc' => 'text/x-component', + 'htt' => 'text/webviewhtml', + 'ief' => 'image/ief', + 'iii' => 'application/x-iphone', + 'ins' => 'application/x-internet-signup', + 'isp' => 'application/x-internet-signup', + 'jfif' => 'image/pipeg', + 'jpe' => 'image/jpeg', + 'jpg' => 'image/jpeg', + 'latex' => 'application/x-latex', + 'lha' => 'application/octet-stream', + 'lsf' => 'video/x-la-asf', + 'lsx' => 'video/x-la-asf', + 'lzh' => 'application/octet-stream', + 'm13' => 'application/x-msmediaview', + 'm14' => 'application/x-msmediaview', + 'm3u' => 'audio/x-mpegurl', + 'man' => 'application/x-troff-man', + 'mdb' => 'application/x-msaccess', + 'me' => 'application/x-troff-me', + 'mht' => 'message/rfc822', + 'mhtml' => 'message/rfc822', + 'mid' => 'audio/mid', + 'mny' => 'application/x-msmoney', + 'movie' => 'video/x-sgi-movie', + 'mp2' => 'video/mpeg', + 'mpa' => 'video/mpeg', + 'mpe' => 'video/mpeg', + 'mpeg' => 'video/mpeg', + 'mpg' => 'video/mpeg', + 'mpp' => 'application/vnd.ms-project', + 'mpv2' => 'video/mpeg', + 'ms' => 'application/x-troff-ms', + 'mvb' => 'application/x-msmediaview', + 'nws' => 'message/rfc822', + 'oda' => 'application/oda', + 'p10' => 'application/pkcs10', + 'p12' => 'application/x-pkcs12', + 'p7b' => 'application/x-pkcs7-certificates', + 'p7c' => 'application/x-pkcs7-mime', + 'p7m' => 'application/x-pkcs7-mime', + 'p7r' => 'application/x-pkcs7-certreqresp', + 'p7s' => 'application/x-pkcs7-signature', + 'pbm' => 'image/x-portable-bitmap', + 'pfx' => 'application/x-pkcs12', + 'pgm' => 'image/x-portable-graymap', + 'pko' => 'application/ynd.ms-pkipko', + 'pma' => 'application/x-perfmon', + 'pmc' => 'application/x-perfmon', + 'pml' => 'application/x-perfmon', + 'pmr' => 'application/x-perfmon', + 'pmw' => 'application/x-perfmon', + 'pnm' => 'image/x-portable-anymap', + 'pot' => 'application/vnd.ms-powerpoint', + 'ppm' => 'image/x-portable-pixmap', + 'pps' => 'application/vnd.ms-powerpoint', + 'prf' => 'application/pics-rules', + 'pub' => 'application/x-mspublisher', + 'ra' => 'audio/x-pn-realaudio', + 'ram' => 'audio/x-pn-realaudio', + 'ras' => 'image/x-cmu-raster', + 'rgb' => 'image/x-rgb', + 'rmi' => 'audio/mid', + 'roff' => 'application/x-troff', + 'rtx' => 'text/richtext', + 'scd' => 'application/x-msschedule', + 'sct' => 'text/scriptlet', + 'setpay' => 'application/set-payment-initiation', + 'setreg' => 'application/set-registration-initiation', + 'sh' => 'application/x-sh', + 'shar' => 'application/x-shar', + 'sit' => 'application/x-stuffit', + 'snd' => 'audio/basic', + 'spc' => 'application/x-pkcs7-certificates', + 'spl' => 'application/futuresplash', + 'src' => 'application/x-wais-source', + 'sst' => 'application/vnd.ms-pkicertstore', + 'stl' => 'application/vnd.ms-pkistl', + 'stm' => 'text/html', 'sv4cpio' => 'application/x-sv4cpio', - 'sv4crc' => 'application/x-sv4crc', - 't' => 'application/x-troff', - 'tar' => 'application/x-tar', - 'tcl' => 'application/x-tcl', - 'tex' => 'application/x-tex', - 'texi' => 'application/x-texinfo', + 'sv4crc' => 'application/x-sv4crc', + 't' => 'application/x-troff', + 'tar' => 'application/x-tar', + 'tcl' => 'application/x-tcl', + 'tex' => 'application/x-tex', + 'texi' => 'application/x-texinfo', 'texinfo' => 'application/x-texinfo', - 'tgz' => 'application/x-compressed', - 'tif' => 'image/tiff', - 'tr' => 'application/x-troff', - 'trm' => 'application/x-msterminal', - 'tsv' => 'text/tab-separated-values', - 'uls' => 'text/iuls', - 'ustar' => 'application/x-ustar', - 'vcf' => 'text/x-vcard', - 'vrml' => 'x-world/x-vrml', - 'wav' => 'audio/x-wav', - 'wcm' => 'application/vnd.ms-works', - 'wdb' => 'application/vnd.ms-works', - 'wks' => 'application/vnd.ms-works', - 'wmf' => 'application/x-msmetafile', - 'wps' => 'application/vnd.ms-works', - 'wri' => 'application/x-mswrite', - 'wrl' => 'x-world/x-vrml', - 'wrz' => 'x-world/x-vrml', - 'xaf' => 'x-world/x-vrml', - 'xbm' => 'image/x-xbitmap', - 'xla' => 'application/vnd.ms-excel', - 'xlc' => 'application/vnd.ms-excel', - 'xlm' => 'application/vnd.ms-excel', - 'xlt' => 'application/vnd.ms-excel', - 'xlw' => 'application/vnd.ms-excel', - 'xof' => 'x-world/x-vrml', - 'xpm' => 'image/x-xpixmap', - 'xwd' => 'image/x-xwindowdump', - 'z' => 'application/x-compress', + 'tgz' => 'application/x-compressed', + 'tif' => 'image/tiff', + 'tr' => 'application/x-troff', + 'trm' => 'application/x-msterminal', + 'tsv' => 'text/tab-separated-values', + 'uls' => 'text/iuls', + 'ustar' => 'application/x-ustar', + 'vcf' => 'text/x-vcard', + 'vrml' => 'x-world/x-vrml', + 'wav' => 'audio/x-wav', + 'wcm' => 'application/vnd.ms-works', + 'wdb' => 'application/vnd.ms-works', + 'wks' => 'application/vnd.ms-works', + 'wmf' => 'application/x-msmetafile', + 'wps' => 'application/vnd.ms-works', + 'wri' => 'application/x-mswrite', + 'wrl' => 'x-world/x-vrml', + 'wrz' => 'x-world/x-vrml', + 'xaf' => 'x-world/x-vrml', + 'xbm' => 'image/x-xbitmap', + 'xla' => 'application/vnd.ms-excel', + 'xlc' => 'application/vnd.ms-excel', + 'xlm' => 'application/vnd.ms-excel', + 'xlt' => 'application/vnd.ms-excel', + 'xlw' => 'application/vnd.ms-excel', + 'xof' => 'x-world/x-vrml', + 'xpm' => 'image/x-xpixmap', + 'xwd' => 'image/x-xwindowdump', + 'z' => 'application/x-compress', ]; - + $explode = explode('.', $filename); $ext = strtolower(array_pop($explode)); if (array_key_exists($ext, $mime_types)) { @@ -799,7 +799,7 @@ if (!function_exists('get_file_extension')) { } if (!function_exists('storage')) { - + /** * @param string|null $fileName * @param string|null $path @@ -808,7 +808,7 @@ if (!function_exists('storage')) { */ function storage(?string $fileName = '', ?string $path = ''): string { - + $basePath = rtrim(Kiri::getStoragePath(), '/'); if (!empty($path)) { $path = ltrim($path, '/'); @@ -829,8 +829,8 @@ if (!function_exists('storage')) { if (!function_exists('event')) { - - + + /** * @param $name * @param $callback @@ -842,12 +842,12 @@ if (!function_exists('event')) { $pro = di(EventProvider::class); $pro->on($name, $callback, 0); } - + } if (!function_exists('name')) { - + /** * @param int $pid * @param string|null $prefix @@ -859,14 +859,14 @@ if (!function_exists('name')) { if (Kiri::getPlatform()->isMac()) { return; } - + $name = Config::get('id', 'system') . '[' . $pid . ']'; if (!empty($prefix)) { $name .= '.' . $prefix; } swoole_set_process_name($name); } - + } @@ -879,7 +879,7 @@ if (!function_exists('zero_full')) { if (!function_exists('env')) { - + /** * @param $key * @param null $default @@ -893,13 +893,13 @@ if (!function_exists('env')) { } return $env; } - + } if (!function_exists('di')) { - - + + /** * @param string $className * @return mixed @@ -908,13 +908,13 @@ if (!function_exists('di')) { { return Kiri::getDi()->get($className); } - + } if (!function_exists('interval')) { - - + + /** * @param callable $callback * @param int $interval @@ -923,17 +923,17 @@ if (!function_exists('interval')) { function interval(callable $callback, int $interval = 1000, bool $is = FALSE) { usleep($interval * 1000); - + $callback(); - + interval($callback, $interval, $is); } - + } if (!function_exists('sweep')) { - + /** * @param string $configPath * @return array|false|string|null @@ -946,13 +946,13 @@ if (!function_exists('sweep')) { } return $array; } - + } if (!function_exists('swoole_serialize')) { - - + + /** * @param $data * @return string @@ -965,13 +965,13 @@ if (!function_exists('swoole_serialize')) { return serialize($data); // } } - + } if (!function_exists('swoole_unserialize')) { - - + + /** * @param $data * @return string @@ -987,13 +987,13 @@ if (!function_exists('swoole_unserialize')) { return unserialize($data); // } } - + } if (!function_exists('merge')) { - - + + /** * @param $param * @param $param1 @@ -1003,13 +1003,13 @@ if (!function_exists('merge')) { { return ArrayAccess::merge($param, $param1); } - + } if (!function_exists('router')) { - - + + /** * @return Router * @throws Exception @@ -1018,12 +1018,12 @@ if (!function_exists('router')) { { return Kiri::getDi()->get(Router::class); } - + } if (!function_exists('jTraceEx')) { - + /** * @param $e * @param null $seen @@ -1040,7 +1040,7 @@ if (!function_exists('jTraceEx')) { $result[] = sprintf('%s%s: %s', $starter, $e::class, $e->getMessage()); $file = $e->getFile(); $line = $e->getLine(); - + foreach ($trace as $value) { $result[] = sprintf(' at %s%s%s(%s%s%s)', count($value) && array_key_exists('class', $value) ? str_replace('\\', '.', $value['class']) : '', @@ -1049,7 +1049,7 @@ if (!function_exists('jTraceEx')) { $line === NULL ? $file : basename($file), $line === NULL ? '' : ':', $line === NULL ? '' : $line); - + $file = array_key_exists('file', $value) ? $value['file'] : 'Unknown Source'; $line = array_key_exists('file', $value) && array_key_exists('line', $value) && $value['line'] ? $value['line'] : NULL; } @@ -1057,17 +1057,17 @@ if (!function_exists('jTraceEx')) { if ($prev) { $result .= ($toHtml ? "
" : "\n") . jTraceEx($prev, $seen, $toHtml); } - + return $result; } - - + + } if (!function_exists('swoole_substr_json_decode')) { - - + + /** * @param $packet * @param int $length @@ -1077,12 +1077,12 @@ if (!function_exists('swoole_substr_json_decode')) { { return json_decode($packet, TRUE); } - + } if (!function_exists('swoole_substr_unserialize')) { - + /** * @param $packet * @param int $length @@ -1092,12 +1092,12 @@ if (!function_exists('swoole_substr_unserialize')) { { return unserialize($packet); } - + } if (!function_exists('debug')) { - + /** * @param mixed $message * @param string $method @@ -1107,11 +1107,11 @@ if (!function_exists('debug')) { { Kiri::getLogger()->debug($method, [$message]); } - + } if (!function_exists('info')) { - + /** * @param mixed $message * @param string $method @@ -1121,11 +1121,11 @@ if (!function_exists('info')) { { Kiri::getLogger()->info($method, [$message]); } - + } if (!function_exists('error')) { - + /** * @param mixed $message * @param string $method @@ -1139,7 +1139,7 @@ if (!function_exists('error')) { } if (!function_exists('success')) { - + /** * @param mixed $message * @param string $method @@ -1153,29 +1153,29 @@ if (!function_exists('success')) { if (!function_exists('throwable')) { - - + + /** * @param Throwable|Error $throwable * @return string */ function throwable(\Throwable|\Error $throwable): string { - $message = $throwable->getMessage() . ' ' . $throwable->getFile() . " at line " . $throwable->getLine() . "\n"; + $message = $throwable->getMessage() . ' ' . $throwable->getFile() . " at line " . $throwable->getLine() . PHP_EOL; foreach ($throwable->getTrace() as $value) { if (!isset($value['file'])) { continue; } - $message .= $value['file'] . " -> " . (isset($value['class']) ? $value['class'] . '::' : '') . ($value['function'] ?? 'Closure') . "(" . $value['line'] . ")\n"; + $message .= $value['file'] . " -> " . (isset($value['class']) ? $value['class'] . '::' : '') . ($value['function'] ?? 'Closure') . "(" . $value['line'] . ")" . PHP_EOL; } return $message; } - + } if (!function_exists('map')) { - + /** * @param array $map * @param Closure $closure