From 360347325e972614b3709dcb4dd7f893d4dab87b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Fri, 25 Feb 2022 18:33:05 +0800 Subject: [PATCH] modify plugin name --- kiri-engine/Context.php | 54 ++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/kiri-engine/Context.php b/kiri-engine/Context.php index df524598..10e94f94 100644 --- a/kiri-engine/Context.php +++ b/kiri-engine/Context.php @@ -5,7 +5,7 @@ namespace Kiri; use Kiri\Abstracts\BaseContext; use Swoole\Coroutine; -use Kiri; + /** * Class Context * @package Yoc\http @@ -24,13 +24,13 @@ class Context extends BaseContext */ public static function setContext($id, $context, $coroutineId = null): mixed { - if (is_null($coroutineId)) { - $coroutineId = Coroutine::getCid(); - } + if (is_null($coroutineId)) { + $coroutineId = Coroutine::getCid(); + } if (Coroutine::getCid() !== -1) { - return Coroutine::getContext($coroutineId)[$id] = $context; - } - return static::$_contents[$id] = $context; + return Coroutine::getContext($coroutineId)[$id] = $context; + } + return static::$_contents[$id] = $context; } /** @@ -41,9 +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 (is_null($coroutineId)) { + $coroutineId = Coroutine::getCid(); + } if (!isset(Coroutine::getContext($coroutineId)[$id])) { Coroutine::getContext($coroutineId)[$id] = 0; } @@ -58,9 +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 (is_null($coroutineId)) { + $coroutineId = Coroutine::getCid(); + } if (!isset(Coroutine::getContext($coroutineId)[$id])) { Coroutine::getContext($coroutineId)[$id] = 0; } @@ -90,9 +90,9 @@ class Context extends BaseContext */ private static function loadByContext($id, $default = null, $coroutineId = null): mixed { - if (is_null($coroutineId)) { - $coroutineId = Coroutine::getCid(); - } + if (is_null($coroutineId)) { + $coroutineId = Coroutine::getCid(); + } return Coroutine::getContext($coroutineId)[$id] ?? $default; } @@ -127,9 +127,9 @@ class Context extends BaseContext */ public static function remove(string $id, $coroutineId = null) { - if (is_null($coroutineId)) { - $coroutineId = Coroutine::getCid(); - } + if (is_null($coroutineId)) { + $coroutineId = Coroutine::getCid(); + } if (!static::hasContext($id, $coroutineId)) { return; } @@ -165,9 +165,9 @@ class Context extends BaseContext if (!isset(static::$_contents[$id])) { return false; } - $value = static::$_contents[$id]; - if (!empty($key) && is_array($value)) { - return isset($value[$key]); + $value = static::$_contents[$id]; + if (!empty($key) && is_array($value)) { + return isset($value[$key]) && $value[$key] !== null; } return true; } @@ -181,15 +181,15 @@ class Context extends BaseContext */ private static function searchByCoroutine($id, $key = null, $coroutineId = null): bool { - if (is_null($coroutineId)) { - $coroutineId = Coroutine::getCid(); - } + if (is_null($coroutineId)) { + $coroutineId = Coroutine::getCid(); + } if (!isset(Coroutine::getContext($coroutineId)[$id])) { return false; } - $value = Coroutine::getContext($coroutineId)[$id]; + $value = Coroutine::getContext($coroutineId)[$id]; if ($key !== null && is_array($value)) { - return isset($value[$key]); + return isset($value[$key]) && $value[$key] !== null; } return true; }