Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 154d9d74d6 | |||
| 2c61abff01 | |||
| b4ce762cf3 | |||
| 4b3c2234af | |||
| 7ee78a9642 | |||
| f9838f781d | |||
| 848416af4f | |||
| 0216e761be | |||
| acf6631c5c | |||
| 64e4307a57 | |||
| ab672127e6 | |||
| 6e5b545a1e | |||
| 8229395e6d |
+52
-29
@@ -29,7 +29,7 @@ if (!function_exists('make')) {
|
||||
* @return mixed
|
||||
* @throws
|
||||
*/
|
||||
function make($name, $default = null): mixed
|
||||
function make($name, $default = NULL): mixed
|
||||
{
|
||||
if (class_exists($name)) {
|
||||
return Kiri::createObject($name);
|
||||
@@ -44,7 +44,7 @@ if (!function_exists('make')) {
|
||||
return Kiri::app()->get($default);
|
||||
}
|
||||
$class = Kiri::createObject($default);
|
||||
class_alias($name, $default, true);
|
||||
class_alias($name, $default, TRUE);
|
||||
return $class;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ if (!function_exists('checkPortIsAlready')) {
|
||||
{
|
||||
if (!Kiri::getPlatform()->isLinux()) {
|
||||
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]);
|
||||
return $output[0];
|
||||
}
|
||||
@@ -92,7 +92,7 @@ if (!function_exists('checkPortIsAlready')) {
|
||||
|
||||
exec('netstat -lnp | grep ' . $port . ' | grep "LISTEN" | awk \'{print $7}\'', $output);
|
||||
if (empty($output)) {
|
||||
return false;
|
||||
return FALSE;
|
||||
}
|
||||
return explode('/', $output[0])[0];
|
||||
}
|
||||
@@ -172,7 +172,7 @@ if (!function_exists('now')) {
|
||||
*/
|
||||
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,20 @@ if (!function_exists('scan_directory')) {
|
||||
|
||||
}
|
||||
|
||||
if (!class_exists('ReturnTypeWillChange')) {
|
||||
|
||||
/**
|
||||
* @since 8.1
|
||||
*/
|
||||
#[Attribute(Attribute::TARGET_METHOD)]
|
||||
final class ReturnTypeWillChange
|
||||
{
|
||||
public function __construct() {}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('injectRuntime')) {
|
||||
|
||||
@@ -246,6 +260,9 @@ if (!function_exists('injectRuntime')) {
|
||||
$router = [];
|
||||
foreach ($fileLists as $class) {
|
||||
foreach (NoteManager::getTargetNote($class) as $value) {
|
||||
if (!method_exists($value, 'execute')) {
|
||||
continue;
|
||||
}
|
||||
$value->execute($class);
|
||||
}
|
||||
$methods = $di->getMethodAttribute($class);
|
||||
@@ -257,6 +274,9 @@ if (!function_exists('injectRuntime')) {
|
||||
if ($item instanceof Route) {
|
||||
$router[] = [$item, $class, $method];
|
||||
} else {
|
||||
if (!method_exists($item, 'execute')) {
|
||||
continue;
|
||||
}
|
||||
$item->execute($class, $method);
|
||||
}
|
||||
}
|
||||
@@ -265,6 +285,9 @@ if (!function_exists('injectRuntime')) {
|
||||
if (!empty($router)) {
|
||||
foreach ($router as $class) {
|
||||
[$item, $class, $method] = $class;
|
||||
if (!method_exists($item, 'execute')) {
|
||||
continue;
|
||||
}
|
||||
$item->execute($class, $method);
|
||||
}
|
||||
}
|
||||
@@ -312,14 +335,14 @@ if (!function_exists('isUrl')) {
|
||||
* @param bool $get_info
|
||||
* @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, '/')) {
|
||||
return false;
|
||||
return FALSE;
|
||||
}
|
||||
$queryMatch = '/((http[s]?):\/\/)?(([\w\-\_]+\.)+\w+(:\d+)?)(\/.*)?/';
|
||||
if (!preg_match($queryMatch, $url, $outPut)) {
|
||||
return false;
|
||||
return FALSE;
|
||||
}
|
||||
$port = str_replace(':', '', $outPut[5]);
|
||||
|
||||
@@ -345,8 +368,8 @@ if (!function_exists('split_request_uri')) {
|
||||
*/
|
||||
function split_request_uri($url): bool|array
|
||||
{
|
||||
if (($parse = isUrl($url, null)) === false) {
|
||||
return false;
|
||||
if (($parse = isUrl($url, NULL)) === FALSE) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
[$isHttps, $domain, $port, $path] = $parse;
|
||||
@@ -370,7 +393,7 @@ if (!function_exists('hadDomain')) {
|
||||
function hadDomain($url): bool|array
|
||||
{
|
||||
$param = split_request_uri($url);
|
||||
return !is_array($param) ? false : $param[0];
|
||||
return !is_array($param) ? FALSE : $param[0];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -419,7 +442,7 @@ if (!function_exists('loadByDir')) {
|
||||
classAutoload($namespace, $value);
|
||||
} else {
|
||||
$pos = strpos($value, '.php');
|
||||
if ($pos === false || strlen($value) - 4 != $pos) {
|
||||
if ($pos === FALSE || strlen($value) - 4 != $pos) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -497,7 +520,7 @@ if (!function_exists('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'])) {
|
||||
$psr4 = $content['autoload']['psr-4'];
|
||||
foreach ($psr4 as $namespace => $dirname) {
|
||||
@@ -547,7 +570,7 @@ if (!function_exists('trim_blank')) {
|
||||
* @param bool $htmlTags
|
||||
* @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);
|
||||
if ($htmlTags) {
|
||||
@@ -787,12 +810,12 @@ if (!function_exists('get_file_extension')) {
|
||||
$ext = strtolower(array_pop($explode));
|
||||
if (array_key_exists($ext, $mime_types)) {
|
||||
return $ext;
|
||||
} elseif (function_exists('finfo_open')) {
|
||||
} else if (function_exists('finfo_open')) {
|
||||
$fInfo = finfo_open(FILEINFO_MIME);
|
||||
$mimeType = finfo_file($fInfo, $filename);
|
||||
finfo_close($fInfo);
|
||||
$mimeType = current(explode('; ', $mimeType));
|
||||
if (($search = array_search($mimeType, $mime_types)) == false) {
|
||||
if (($search = array_search($mimeType, $mime_types)) == FALSE) {
|
||||
return $mimeType;
|
||||
}
|
||||
return $search;
|
||||
@@ -817,7 +840,7 @@ if (!function_exists('storage')) {
|
||||
if (!empty($path)) {
|
||||
$path = ltrim($path, '/');
|
||||
if (!is_dir($basePath . '/' . $path)) {
|
||||
mkdir($basePath . '/' . $path, 0777, true);
|
||||
mkdir($basePath . '/' . $path, 0777, TRUE);
|
||||
}
|
||||
}
|
||||
if (empty($fileName)) {
|
||||
@@ -841,7 +864,7 @@ if (!function_exists('event')) {
|
||||
* @param bool $isAppend
|
||||
* @throws Exception
|
||||
*/
|
||||
function event($name, $callback, bool $isAppend = true)
|
||||
function event($name, $callback, bool $isAppend = TRUE)
|
||||
{
|
||||
$pro = di(EventProvider::class);
|
||||
$pro->on($name, $callback, 0);
|
||||
@@ -858,7 +881,7 @@ if (!function_exists('name')) {
|
||||
* @throws ConfigException
|
||||
* @throws Exception
|
||||
*/
|
||||
function name(int $pid, string $prefix = null)
|
||||
function name(int $pid, string $prefix = NULL)
|
||||
{
|
||||
if (Kiri::getPlatform()->isMac()) {
|
||||
return;
|
||||
@@ -889,10 +912,10 @@ if (!function_exists('env')) {
|
||||
* @param null $default
|
||||
* @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);
|
||||
if ($env === false) {
|
||||
if ($env === FALSE) {
|
||||
return $default;
|
||||
}
|
||||
return $env;
|
||||
@@ -925,7 +948,7 @@ if (!function_exists('interval')) {
|
||||
* @param int $interval
|
||||
* @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);
|
||||
|
||||
@@ -1004,7 +1027,7 @@ if (!function_exists('swoole_unserialize')) {
|
||||
function swoole_unserialize($data): mixed
|
||||
{
|
||||
if (empty($data)) {
|
||||
return null;
|
||||
return NULL;
|
||||
}
|
||||
// if (class_exists('swoole_serialize')) {
|
||||
// return \swoole_serialize::unpack($data);
|
||||
@@ -1085,7 +1108,7 @@ if (!function_exists('jTraceEx')) {
|
||||
* @param bool $toHtml
|
||||
* @return string
|
||||
*/
|
||||
function jTraceEx($e, $seen = null, bool $toHtml = false): string
|
||||
function jTraceEx($e, $seen = NULL, bool $toHtml = FALSE): string
|
||||
{
|
||||
$starter = $seen ? 'Caused by: ' : '';
|
||||
$result = [];
|
||||
@@ -1101,12 +1124,12 @@ if (!function_exists('jTraceEx')) {
|
||||
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('function', $value) ? str_replace('\\', '.', $value['function']) : '(main)',
|
||||
$line === null ? $file : basename($file),
|
||||
$line === null ? '' : ':',
|
||||
$line === null ? '' : $line);
|
||||
$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;
|
||||
$line = array_key_exists('file', $value) && array_key_exists('line', $value) && $value['line'] ? $value['line'] : NULL;
|
||||
}
|
||||
$result = join($toHtml ? "<br>" : "\n", $result);
|
||||
if ($prev) {
|
||||
@@ -1130,7 +1153,7 @@ if (!function_exists('swoole_substr_json_decode')) {
|
||||
*/
|
||||
function swoole_substr_json_decode($packet, int $length = 0): mixed
|
||||
{
|
||||
return json_decode($packet, true);
|
||||
return json_decode($packet, TRUE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+23
-4
@@ -24,11 +24,14 @@ class Context extends BaseContext
|
||||
*/
|
||||
public static function setContext($id, $context, $coroutineId = null): mixed
|
||||
{
|
||||
if (Coroutine::getCid() === -1) {
|
||||
return static::$_contents[$id] = $context;
|
||||
if (is_null($coroutineId)) {
|
||||
$coroutineId = Coroutine::getCid();
|
||||
}
|
||||
if (Coroutine::getCid() !== -1) {
|
||||
return Coroutine::getContext($coroutineId)[$id] = $context;
|
||||
}
|
||||
return static::$_contents[$id] = $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
@@ -38,6 +41,9 @@ class Context extends BaseContext
|
||||
*/
|
||||
public static function increment($id, int $value = 1, $coroutineId = null): bool|int
|
||||
{
|
||||
if (is_null($coroutineId)) {
|
||||
$coroutineId = Coroutine::getCid();
|
||||
}
|
||||
if (!isset(Coroutine::getContext($coroutineId)[$id])) {
|
||||
Coroutine::getContext($coroutineId)[$id] = 0;
|
||||
}
|
||||
@@ -52,6 +58,9 @@ class Context extends BaseContext
|
||||
*/
|
||||
public static function decrement($id, int $value = 1, $coroutineId = null): bool|int
|
||||
{
|
||||
if (is_null($coroutineId)) {
|
||||
$coroutineId = Coroutine::getCid();
|
||||
}
|
||||
if (!isset(Coroutine::getContext($coroutineId)[$id])) {
|
||||
Coroutine::getContext($coroutineId)[$id] = 0;
|
||||
}
|
||||
@@ -81,6 +90,9 @@ class Context extends BaseContext
|
||||
*/
|
||||
private static function loadByContext($id, $default = null, $coroutineId = null): mixed
|
||||
{
|
||||
if (is_null($coroutineId)) {
|
||||
$coroutineId = Coroutine::getCid();
|
||||
}
|
||||
return Coroutine::getContext($coroutineId)[$id] ?? $default;
|
||||
}
|
||||
|
||||
@@ -115,6 +127,9 @@ class Context extends BaseContext
|
||||
*/
|
||||
public static function remove(string $id, $coroutineId = null)
|
||||
{
|
||||
if (is_null($coroutineId)) {
|
||||
$coroutineId = Coroutine::getCid();
|
||||
}
|
||||
if (!static::hasContext($id, $coroutineId)) {
|
||||
return;
|
||||
}
|
||||
@@ -165,11 +180,15 @@ class Context extends BaseContext
|
||||
*/
|
||||
private static function searchByCoroutine($id, $key = null, $coroutineId = null): bool
|
||||
{
|
||||
if (is_null($coroutineId)) {
|
||||
$coroutineId = Coroutine::getCid();
|
||||
}
|
||||
if (!isset(Coroutine::getContext($coroutineId)[$id])) {
|
||||
return false;
|
||||
}
|
||||
if ($key !== null) {
|
||||
return isset((Coroutine::getContext($coroutineId)[$id] ?? [])[$key]);
|
||||
$value = Coroutine::getContext($coroutineId)[$id];
|
||||
if ($key !== null && is_array($value)) {
|
||||
return isset($value[$key]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -66,11 +66,11 @@ class Json
|
||||
{
|
||||
$params['code'] = $code;
|
||||
if (!is_string($message)) {
|
||||
$params['message'] = 'System success.';
|
||||
$params['param'] = $message;
|
||||
if (!empty($data)) {
|
||||
$params['exPageInfo'] = $data;
|
||||
}
|
||||
$params['message'] = 'System success.';
|
||||
} else {
|
||||
$params['message'] = $message;
|
||||
$params['param'] = $data;
|
||||
|
||||
+3
-3
@@ -68,7 +68,7 @@ class Gii
|
||||
$this->input = $input;
|
||||
$this->db = $db;
|
||||
|
||||
$make = $this->input->getArgument('action');
|
||||
$make = $this->input->getOption('make');
|
||||
if (empty($make)) {
|
||||
throw new Exception('构建类型不能为空~');
|
||||
}
|
||||
@@ -120,8 +120,8 @@ class Gii
|
||||
private function makeByDatabases($make, InputInterface $input): array
|
||||
{
|
||||
$redis = Kiri::getDi()->get(Redis::class);
|
||||
if ($input->hasArgument('name')) {
|
||||
$this->tableName = $input->getArgument('name');
|
||||
if ($input->hasOption('name')) {
|
||||
$this->tableName = $input->getOption('name');
|
||||
$redis->del('column:' . $this->tableName);
|
||||
}
|
||||
return match ($make) {
|
||||
|
||||
@@ -32,9 +32,9 @@ class GiiCommand extends Command
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('sw:gii')
|
||||
->addArgument('action', InputArgument::REQUIRED)
|
||||
->addArgument('name', InputArgument::OPTIONAL)
|
||||
->addArgument('databases', InputArgument::OPTIONAL)
|
||||
->addOption('make','m', InputArgument::OPTIONAL)
|
||||
->addOption('name','t', InputArgument::OPTIONAL)
|
||||
->addOption('databases','d', InputArgument::OPTIONAL)
|
||||
->setDescription('./snowflake sw:gii make=model|controller|task|interceptor|limits|middleware name=xxxx');
|
||||
}
|
||||
|
||||
@@ -52,12 +52,12 @@ class GiiCommand extends Command
|
||||
$gii = Kiri::app()->get('gii');
|
||||
|
||||
$connections = Kiri::app()->get('db');
|
||||
if (($db = $input->getArgument('databases')) != null) {
|
||||
if (($db = $input->getOption('databases')) != null) {
|
||||
$gii->run($connections->get($db), $input);
|
||||
return 1;
|
||||
}
|
||||
|
||||
$action = $input->getArgument('action');
|
||||
$action = $input->getOption('make');
|
||||
if (!in_array($action, ['model', 'controller'])) {
|
||||
$gii->run(null, $input);
|
||||
return 1;
|
||||
|
||||
@@ -17,6 +17,7 @@ abstract class Attribute implements INote
|
||||
* @param mixed|string $method
|
||||
* @return mixed
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function execute(mixed $class, mixed $method = ''): mixed
|
||||
{
|
||||
// TODO: Implement execute() method.
|
||||
|
||||
Reference in New Issue
Block a user