This commit is contained in:
as2252258@163.com
2021-05-02 05:00:06 +08:00
parent 7473193da6
commit ca6ff010ed
+1 -24
View File
@@ -16,7 +16,6 @@ class Context extends BaseContext
protected static array $_contents = []; protected static array $_contents = [];
/** /**
* @param $id * @param $id
* @param $context * @param $context
@@ -25,11 +24,7 @@ class Context extends BaseContext
*/ */
public static function setContext($id, $context, $key = null): mixed public static function setContext($id, $context, $key = null): mixed
{ {
if (static::inCoroutine()) {
return self::setCoroutine($id, $context, $key); return self::setCoroutine($id, $context, $key);
} else {
return self::setStatic($id, $context, $key);
}
} }
/** /**
@@ -78,9 +73,6 @@ class Context extends BaseContext
*/ */
public static function increment($id, $key = null, $value = 1): bool|int public static function increment($id, $key = null, $value = 1): bool|int
{ {
if (!static::inCoroutine()) {
return false;
}
if (!isset(Coroutine::getContext()[$id][$key])) { if (!isset(Coroutine::getContext()[$id][$key])) {
return false; return false;
} }
@@ -95,7 +87,7 @@ class Context extends BaseContext
*/ */
public static function decrement($id, $key = null, $value = 1): bool|int public static function decrement($id, $key = null, $value = 1): bool|int
{ {
if (!static::inCoroutine() || !static::hasContext($id)) { if (!static::hasContext($id)) {
return false; return false;
} }
if (!isset(Coroutine::getContext()[$id][$key])) { if (!isset(Coroutine::getContext()[$id][$key])) {
@@ -111,14 +103,7 @@ class Context extends BaseContext
*/ */
public static function getContext($id, $key = null): mixed public static function getContext($id, $key = null): mixed
{ {
if (!static::hasContext($id)) {
return null;
}
if (static::inCoroutine()) {
return static::loadByContext($id, $key); return static::loadByContext($id, $key);
} else {
return static::loadByStatic($id, $key);
}
} }
@@ -179,10 +164,6 @@ class Context extends BaseContext
if (!static::hasContext($id, $key)) { if (!static::hasContext($id, $key)) {
return; return;
} }
if (static::inCoroutine()) {
unset(static::$_contents[$id]);
return;
}
if (!empty($key)) { if (!empty($key)) {
unset(Coroutine::getContext()[$id][$key]); unset(Coroutine::getContext()[$id][$key]);
} else { } else {
@@ -197,12 +178,8 @@ class Context extends BaseContext
*/ */
public static function hasContext($id, $key = null): bool public static function hasContext($id, $key = null): bool
{ {
if (!static::inCoroutine()) {
return static::searchByStatic($id, $key);
} else {
return static::searchByCoroutine($id, $key); return static::searchByCoroutine($id, $key);
} }
}
/** /**