1
This commit is contained in:
+47
-32
@@ -29,7 +29,7 @@ if (!function_exists('make')) {
|
|||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
function make($name, $default = null): mixed
|
function make($name, $default = NULL): mixed
|
||||||
{
|
{
|
||||||
if (class_exists($name)) {
|
if (class_exists($name)) {
|
||||||
return Kiri::createObject($name);
|
return Kiri::createObject($name);
|
||||||
@@ -44,7 +44,7 @@ if (!function_exists('make')) {
|
|||||||
return Kiri::app()->get($default);
|
return Kiri::app()->get($default);
|
||||||
}
|
}
|
||||||
$class = Kiri::createObject($default);
|
$class = Kiri::createObject($default);
|
||||||
class_alias($name, $default, true);
|
class_alias($name, $default, TRUE);
|
||||||
return $class;
|
return $class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ if (!function_exists('checkPortIsAlready')) {
|
|||||||
{
|
{
|
||||||
if (!Kiri::getPlatform()->isLinux()) {
|
if (!Kiri::getPlatform()->isLinux()) {
|
||||||
exec("lsof -i :" . $port . " | grep -i 'LISTEN' | awk '{print $2}'", $output);
|
exec("lsof -i :" . $port . " | grep -i 'LISTEN' | awk '{print $2}'", $output);
|
||||||
if (empty($output)) return false;
|
if (empty($output)) return FALSE;
|
||||||
$output = explode(PHP_EOL, $output[0]);
|
$output = explode(PHP_EOL, $output[0]);
|
||||||
return $output[0];
|
return $output[0];
|
||||||
}
|
}
|
||||||
@@ -92,7 +92,7 @@ if (!function_exists('checkPortIsAlready')) {
|
|||||||
|
|
||||||
exec('netstat -lnp | grep ' . $port . ' | grep "LISTEN" | awk \'{print $7}\'', $output);
|
exec('netstat -lnp | grep ' . $port . ' | grep "LISTEN" | awk \'{print $7}\'', $output);
|
||||||
if (empty($output)) {
|
if (empty($output)) {
|
||||||
return false;
|
return FALSE;
|
||||||
}
|
}
|
||||||
return explode('/', $output[0])[0];
|
return explode('/', $output[0])[0];
|
||||||
}
|
}
|
||||||
@@ -172,7 +172,7 @@ if (!function_exists('now')) {
|
|||||||
*/
|
*/
|
||||||
function now(): string
|
function now(): string
|
||||||
{
|
{
|
||||||
return date('Y-m-d H:i:s') . '.' . str_replace(time() . '.', '', (string)microtime(true));
|
return date('Y-m-d H:i:s') . '.' . str_replace(time() . '.', '', (string)microtime(TRUE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,6 +228,21 @@ if (!function_exists('scan_directory')) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!class_exists('ReturnTypeWillChange')) {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 8.0
|
||||||
|
*/
|
||||||
|
#[Attribute(Attribute::TARGET_METHOD)]
|
||||||
|
class ReturnTypeWillChange
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!function_exists('injectRuntime')) {
|
if (!function_exists('injectRuntime')) {
|
||||||
|
|
||||||
@@ -246,7 +261,7 @@ if (!function_exists('injectRuntime')) {
|
|||||||
$router = [];
|
$router = [];
|
||||||
foreach ($fileLists as $class) {
|
foreach ($fileLists as $class) {
|
||||||
foreach (NoteManager::getTargetNote($class) as $value) {
|
foreach (NoteManager::getTargetNote($class) as $value) {
|
||||||
if (!method_exists($value, 'execute')){
|
if (!method_exists($value, 'execute')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$value->execute($class);
|
$value->execute($class);
|
||||||
@@ -260,7 +275,7 @@ if (!function_exists('injectRuntime')) {
|
|||||||
if ($item instanceof Route) {
|
if ($item instanceof Route) {
|
||||||
$router[] = [$item, $class, $method];
|
$router[] = [$item, $class, $method];
|
||||||
} else {
|
} else {
|
||||||
if (!method_exists($item, 'execute')){
|
if (!method_exists($item, 'execute')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$item->execute($class, $method);
|
$item->execute($class, $method);
|
||||||
@@ -271,7 +286,7 @@ if (!function_exists('injectRuntime')) {
|
|||||||
if (!empty($router)) {
|
if (!empty($router)) {
|
||||||
foreach ($router as $class) {
|
foreach ($router as $class) {
|
||||||
[$item, $class, $method] = $class;
|
[$item, $class, $method] = $class;
|
||||||
if (!method_exists($item, 'execute')){
|
if (!method_exists($item, 'execute')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$item->execute($class, $method);
|
$item->execute($class, $method);
|
||||||
@@ -321,14 +336,14 @@ if (!function_exists('isUrl')) {
|
|||||||
* @param bool $get_info
|
* @param bool $get_info
|
||||||
* @return false|array
|
* @return false|array
|
||||||
*/
|
*/
|
||||||
function isUrl($url, bool $get_info = true): bool|array
|
function isUrl($url, bool $get_info = TRUE): bool|array
|
||||||
{
|
{
|
||||||
if (str_starts_with($url, '/')) {
|
if (str_starts_with($url, '/')) {
|
||||||
return false;
|
return FALSE;
|
||||||
}
|
}
|
||||||
$queryMatch = '/((http[s]?):\/\/)?(([\w\-\_]+\.)+\w+(:\d+)?)(\/.*)?/';
|
$queryMatch = '/((http[s]?):\/\/)?(([\w\-\_]+\.)+\w+(:\d+)?)(\/.*)?/';
|
||||||
if (!preg_match($queryMatch, $url, $outPut)) {
|
if (!preg_match($queryMatch, $url, $outPut)) {
|
||||||
return false;
|
return FALSE;
|
||||||
}
|
}
|
||||||
$port = str_replace(':', '', $outPut[5]);
|
$port = str_replace(':', '', $outPut[5]);
|
||||||
|
|
||||||
@@ -354,8 +369,8 @@ if (!function_exists('split_request_uri')) {
|
|||||||
*/
|
*/
|
||||||
function split_request_uri($url): bool|array
|
function split_request_uri($url): bool|array
|
||||||
{
|
{
|
||||||
if (($parse = isUrl($url, null)) === false) {
|
if (($parse = isUrl($url, NULL)) === FALSE) {
|
||||||
return false;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
[$isHttps, $domain, $port, $path] = $parse;
|
[$isHttps, $domain, $port, $path] = $parse;
|
||||||
@@ -379,7 +394,7 @@ if (!function_exists('hadDomain')) {
|
|||||||
function hadDomain($url): bool|array
|
function hadDomain($url): bool|array
|
||||||
{
|
{
|
||||||
$param = split_request_uri($url);
|
$param = split_request_uri($url);
|
||||||
return !is_array($param) ? false : $param[0];
|
return !is_array($param) ? FALSE : $param[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -428,7 +443,7 @@ if (!function_exists('loadByDir')) {
|
|||||||
classAutoload($namespace, $value);
|
classAutoload($namespace, $value);
|
||||||
} else {
|
} else {
|
||||||
$pos = strpos($value, '.php');
|
$pos = strpos($value, '.php');
|
||||||
if ($pos === false || strlen($value) - 4 != $pos) {
|
if ($pos === FALSE || strlen($value) - 4 != $pos) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -506,7 +521,7 @@ if (!function_exists('instance_load')) {
|
|||||||
|
|
||||||
function instance_load()
|
function instance_load()
|
||||||
{
|
{
|
||||||
$content = json_decode(file_get_contents(__DIR__ . '/composer.json'), true);
|
$content = json_decode(file_get_contents(__DIR__ . '/composer.json'), TRUE);
|
||||||
if (isset($content['autoload']) && isset($content['autoload']['psr-4'])) {
|
if (isset($content['autoload']) && isset($content['autoload']['psr-4'])) {
|
||||||
$psr4 = $content['autoload']['psr-4'];
|
$psr4 = $content['autoload']['psr-4'];
|
||||||
foreach ($psr4 as $namespace => $dirname) {
|
foreach ($psr4 as $namespace => $dirname) {
|
||||||
@@ -556,7 +571,7 @@ if (!function_exists('trim_blank')) {
|
|||||||
* @param bool $htmlTags
|
* @param bool $htmlTags
|
||||||
* @return array|string|null
|
* @return array|string|null
|
||||||
*/
|
*/
|
||||||
function trim_blank(string $content, int $len = 0, string $encode = 'utf-8', bool $htmlTags = true): array|string|null
|
function trim_blank(string $content, int $len = 0, string $encode = 'utf-8', bool $htmlTags = TRUE): array|string|null
|
||||||
{
|
{
|
||||||
$str = trim($content);
|
$str = trim($content);
|
||||||
if ($htmlTags) {
|
if ($htmlTags) {
|
||||||
@@ -796,12 +811,12 @@ if (!function_exists('get_file_extension')) {
|
|||||||
$ext = strtolower(array_pop($explode));
|
$ext = strtolower(array_pop($explode));
|
||||||
if (array_key_exists($ext, $mime_types)) {
|
if (array_key_exists($ext, $mime_types)) {
|
||||||
return $ext;
|
return $ext;
|
||||||
} elseif (function_exists('finfo_open')) {
|
} else if (function_exists('finfo_open')) {
|
||||||
$fInfo = finfo_open(FILEINFO_MIME);
|
$fInfo = finfo_open(FILEINFO_MIME);
|
||||||
$mimeType = finfo_file($fInfo, $filename);
|
$mimeType = finfo_file($fInfo, $filename);
|
||||||
finfo_close($fInfo);
|
finfo_close($fInfo);
|
||||||
$mimeType = current(explode('; ', $mimeType));
|
$mimeType = current(explode('; ', $mimeType));
|
||||||
if (($search = array_search($mimeType, $mime_types)) == false) {
|
if (($search = array_search($mimeType, $mime_types)) == FALSE) {
|
||||||
return $mimeType;
|
return $mimeType;
|
||||||
}
|
}
|
||||||
return $search;
|
return $search;
|
||||||
@@ -826,7 +841,7 @@ if (!function_exists('storage')) {
|
|||||||
if (!empty($path)) {
|
if (!empty($path)) {
|
||||||
$path = ltrim($path, '/');
|
$path = ltrim($path, '/');
|
||||||
if (!is_dir($basePath . '/' . $path)) {
|
if (!is_dir($basePath . '/' . $path)) {
|
||||||
mkdir($basePath . '/' . $path, 0777, true);
|
mkdir($basePath . '/' . $path, 0777, TRUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (empty($fileName)) {
|
if (empty($fileName)) {
|
||||||
@@ -850,7 +865,7 @@ if (!function_exists('event')) {
|
|||||||
* @param bool $isAppend
|
* @param bool $isAppend
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
function event($name, $callback, bool $isAppend = true)
|
function event($name, $callback, bool $isAppend = TRUE)
|
||||||
{
|
{
|
||||||
$pro = di(EventProvider::class);
|
$pro = di(EventProvider::class);
|
||||||
$pro->on($name, $callback, 0);
|
$pro->on($name, $callback, 0);
|
||||||
@@ -867,7 +882,7 @@ if (!function_exists('name')) {
|
|||||||
* @throws ConfigException
|
* @throws ConfigException
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
function name(int $pid, string $prefix = null)
|
function name(int $pid, string $prefix = NULL)
|
||||||
{
|
{
|
||||||
if (Kiri::getPlatform()->isMac()) {
|
if (Kiri::getPlatform()->isMac()) {
|
||||||
return;
|
return;
|
||||||
@@ -898,10 +913,10 @@ if (!function_exists('env')) {
|
|||||||
* @param null $default
|
* @param null $default
|
||||||
* @return array|string|null
|
* @return array|string|null
|
||||||
*/
|
*/
|
||||||
#[Pure] function env($key, $default = null): null|array|string
|
#[Pure] function env($key, $default = NULL): null|array|string
|
||||||
{
|
{
|
||||||
$env = getenv($key);
|
$env = getenv($key);
|
||||||
if ($env === false) {
|
if ($env === FALSE) {
|
||||||
return $default;
|
return $default;
|
||||||
}
|
}
|
||||||
return $env;
|
return $env;
|
||||||
@@ -934,7 +949,7 @@ if (!function_exists('interval')) {
|
|||||||
* @param int $interval
|
* @param int $interval
|
||||||
* @param bool $is
|
* @param bool $is
|
||||||
*/
|
*/
|
||||||
function interval(callable $callback, int $interval = 1000, bool $is = false)
|
function interval(callable $callback, int $interval = 1000, bool $is = FALSE)
|
||||||
{
|
{
|
||||||
usleep($interval * 1000);
|
usleep($interval * 1000);
|
||||||
|
|
||||||
@@ -1013,7 +1028,7 @@ if (!function_exists('swoole_unserialize')) {
|
|||||||
function swoole_unserialize($data): mixed
|
function swoole_unserialize($data): mixed
|
||||||
{
|
{
|
||||||
if (empty($data)) {
|
if (empty($data)) {
|
||||||
return null;
|
return NULL;
|
||||||
}
|
}
|
||||||
// if (class_exists('swoole_serialize')) {
|
// if (class_exists('swoole_serialize')) {
|
||||||
// return \swoole_serialize::unpack($data);
|
// return \swoole_serialize::unpack($data);
|
||||||
@@ -1094,7 +1109,7 @@ if (!function_exists('jTraceEx')) {
|
|||||||
* @param bool $toHtml
|
* @param bool $toHtml
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function jTraceEx($e, $seen = null, bool $toHtml = false): string
|
function jTraceEx($e, $seen = NULL, bool $toHtml = FALSE): string
|
||||||
{
|
{
|
||||||
$starter = $seen ? 'Caused by: ' : '';
|
$starter = $seen ? 'Caused by: ' : '';
|
||||||
$result = [];
|
$result = [];
|
||||||
@@ -1110,12 +1125,12 @@ if (!function_exists('jTraceEx')) {
|
|||||||
count($value) && array_key_exists('class', $value) ? str_replace('\\', '.', $value['class']) : '',
|
count($value) && array_key_exists('class', $value) ? str_replace('\\', '.', $value['class']) : '',
|
||||||
count($value) && array_key_exists('class', $value) && array_key_exists('function', $value) ? '.' : '',
|
count($value) && array_key_exists('class', $value) && array_key_exists('function', $value) ? '.' : '',
|
||||||
count($value) && array_key_exists('function', $value) ? str_replace('\\', '.', $value['function']) : '(main)',
|
count($value) && array_key_exists('function', $value) ? str_replace('\\', '.', $value['function']) : '(main)',
|
||||||
$line === null ? $file : basename($file),
|
$line === NULL ? $file : basename($file),
|
||||||
$line === null ? '' : ':',
|
$line === NULL ? '' : ':',
|
||||||
$line === null ? '' : $line);
|
$line === NULL ? '' : $line);
|
||||||
|
|
||||||
$file = array_key_exists('file', $value) ? $value['file'] : 'Unknown Source';
|
$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;
|
$line = array_key_exists('file', $value) && array_key_exists('line', $value) && $value['line'] ? $value['line'] : NULL;
|
||||||
}
|
}
|
||||||
$result = join($toHtml ? "<br>" : "\n", $result);
|
$result = join($toHtml ? "<br>" : "\n", $result);
|
||||||
if ($prev) {
|
if ($prev) {
|
||||||
@@ -1139,7 +1154,7 @@ if (!function_exists('swoole_substr_json_decode')) {
|
|||||||
*/
|
*/
|
||||||
function swoole_substr_json_decode($packet, int $length = 0): mixed
|
function swoole_substr_json_decode($packet, int $length = 0): mixed
|
||||||
{
|
{
|
||||||
return json_decode($packet, true);
|
return json_decode($packet, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user