This commit is contained in:
as2252258@163.com
2021-05-02 05:08:02 +08:00
parent ca6ff010ed
commit 1699a72add
+20 -3
View File
@@ -24,6 +24,9 @@ class Context extends BaseContext
*/ */
public static function setContext($id, $context, $key = null): mixed public static function setContext($id, $context, $key = null): mixed
{ {
if (Coroutine::getCid() > 0) {
return static::setStatic($id, $context, $key);
}
return self::setCoroutine($id, $context, $key); return self::setCoroutine($id, $context, $key);
} }
@@ -103,6 +106,9 @@ class Context extends BaseContext
*/ */
public static function getContext($id, $key = null): mixed public static function getContext($id, $key = null): mixed
{ {
if (Coroutine::getCid() > 0) {
return static::loadByStatic($id, $key);
}
return static::loadByContext($id, $key); return static::loadByContext($id, $key);
} }
@@ -164,10 +170,18 @@ class Context extends BaseContext
if (!static::hasContext($id, $key)) { if (!static::hasContext($id, $key)) {
return; return;
} }
if (!empty($key)) { if (Coroutine::getCid() > 0) {
unset(Coroutine::getContext()[$id][$key]); if (!empty($key)) {
unset(static::$_contents[$id][$key]);
} else {
unset(static::$_contents[$id]);
}
} else { } else {
unset(Coroutine::getContext()[$id]); if (!empty($key)) {
unset(Coroutine::getContext()[$id][$key]);
} else {
unset(Coroutine::getContext()[$id]);
}
} }
} }
@@ -178,6 +192,9 @@ class Context extends BaseContext
*/ */
public static function hasContext($id, $key = null): bool public static function hasContext($id, $key = null): bool
{ {
if (Coroutine::getCid() > 0) {
return static::searchByStatic($id, $key);
}
return static::searchByCoroutine($id, $key); return static::searchByCoroutine($id, $key);
} }