From 6039ca70c555a8b320047e519c266c64c3447fe1 Mon Sep 17 00:00:00 2001 From: "as2252258@163.com" Date: Thu, 29 Sep 2022 23:06:08 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kiri-engine/Context.php | 59 ++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/kiri-engine/Context.php b/kiri-engine/Context.php index 7903ddd5..9c797219 100644 --- a/kiri-engine/Context.php +++ b/kiri-engine/Context.php @@ -12,10 +12,10 @@ use Swoole\Coroutine; */ class Context extends BaseContext { - + protected static array $_contents = []; - - + + /** * @param $id * @param $context @@ -32,7 +32,7 @@ class Context extends BaseContext } return static::$_contents[$id] = $context; } - + /** * @param $id * @param int $value @@ -49,7 +49,7 @@ class Context extends BaseContext } return Coroutine::getContext($coroutineId)[$id] += $value; } - + /** * @param $id * @param int $value @@ -66,7 +66,7 @@ class Context extends BaseContext } return Coroutine::getContext($coroutineId)[$id] -= $value; } - + /** * @param $id * @param null $default @@ -80,8 +80,8 @@ class Context extends BaseContext } return static::loadByContext($id, $default, $coroutineId); } - - + + /** * @param $id * @param null $default @@ -95,8 +95,8 @@ class Context extends BaseContext } return Coroutine::getContext($coroutineId)[$id] ?? $default; } - - + + /** * @param $id * @param null $default @@ -106,8 +106,8 @@ class Context extends BaseContext { return static::$_contents[$id] ?? $default; } - - + + /** * @param null $coroutineId * @return mixed @@ -120,7 +120,18 @@ class Context extends BaseContext return static::$_contents ?? []; } } - + + + /** + * @return void + */ + public static function clearAll(): void + { + if (Coroutine::getCid() === -1) { + static::$_contents = []; + } + } + /** * @param string $id * @param null $coroutineId @@ -135,16 +146,16 @@ class Context extends BaseContext } if (Coroutine::getCid() === -1) { static::$_contents[$id] = null; - + unset(static::$_contents[$id]); - + } else { Coroutine::getContext($coroutineId)[$id] = null; - + unset(Coroutine::getContext($coroutineId)[$id]); } } - + /** * @param $id * @param null $key @@ -158,8 +169,8 @@ class Context extends BaseContext } return static::searchByCoroutine($id, $key, $coroutineId); } - - + + /** * @param $id * @param null $key @@ -176,8 +187,8 @@ class Context extends BaseContext } return true; } - - + + /** * @param $id * @param null $key @@ -198,8 +209,8 @@ class Context extends BaseContext } return true; } - - + + /** * @return bool */ @@ -207,7 +218,7 @@ class Context extends BaseContext { return Coroutine::getCid() !== -1; } - + } From 530f2ea98d013328f7b3701df673683d4eac9481 Mon Sep 17 00:00:00 2001 From: "as2252258@163.com" Date: Thu, 29 Sep 2022 23:49:07 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kiri-engine/Context.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kiri-engine/Context.php b/kiri-engine/Context.php index 9c797219..c9b5b647 100644 --- a/kiri-engine/Context.php +++ b/kiri-engine/Context.php @@ -110,12 +110,12 @@ class Context extends BaseContext /** * @param null $coroutineId - * @return mixed + * @return Coroutine\Context|array */ - public static function getAllContext($coroutineId = null): mixed + public static function getAllContext($coroutineId = null): Coroutine\Context|array { if (Coroutine::getCid() === -1) { - return Coroutine::getContext($coroutineId) ?? []; + return Coroutine::getContext((int)$coroutineId) ?? []; } else { return static::$_contents ?? []; } From d8eae58bfd439ec387a01e65f166606facb8fa6f Mon Sep 17 00:00:00 2001 From: "as2252258@163.com" Date: Thu, 29 Sep 2022 23:49:33 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kiri-engine/Context.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/kiri-engine/Context.php b/kiri-engine/Context.php index c9b5b647..8da6349b 100644 --- a/kiri-engine/Context.php +++ b/kiri-engine/Context.php @@ -127,9 +127,7 @@ class Context extends BaseContext */ public static function clearAll(): void { - if (Coroutine::getCid() === -1) { - static::$_contents = []; - } + static::$_contents = []; } /** From 8d8033027dc1e55a57a4dc66241680d65d68c4be Mon Sep 17 00:00:00 2001 From: "as2252258@163.com" Date: Thu, 29 Sep 2022 23:51:17 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kiri-engine/Context.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kiri-engine/Context.php b/kiri-engine/Context.php index 8da6349b..c9b5b647 100644 --- a/kiri-engine/Context.php +++ b/kiri-engine/Context.php @@ -127,7 +127,9 @@ class Context extends BaseContext */ public static function clearAll(): void { - static::$_contents = []; + if (Coroutine::getCid() === -1) { + static::$_contents = []; + } } /**