Merge branch 'master' of github.com:as2252258/kiri-core
This commit is contained in:
+35
-24
@@ -12,10 +12,10 @@ use Swoole\Coroutine;
|
|||||||
*/
|
*/
|
||||||
class Context extends BaseContext
|
class Context extends BaseContext
|
||||||
{
|
{
|
||||||
|
|
||||||
protected static array $_contents = [];
|
protected static array $_contents = [];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $id
|
* @param $id
|
||||||
* @param $context
|
* @param $context
|
||||||
@@ -32,7 +32,7 @@ class Context extends BaseContext
|
|||||||
}
|
}
|
||||||
return static::$_contents[$id] = $context;
|
return static::$_contents[$id] = $context;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $id
|
* @param $id
|
||||||
* @param int $value
|
* @param int $value
|
||||||
@@ -49,7 +49,7 @@ class Context extends BaseContext
|
|||||||
}
|
}
|
||||||
return Coroutine::getContext($coroutineId)[$id] += $value;
|
return Coroutine::getContext($coroutineId)[$id] += $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $id
|
* @param $id
|
||||||
* @param int $value
|
* @param int $value
|
||||||
@@ -66,7 +66,7 @@ class Context extends BaseContext
|
|||||||
}
|
}
|
||||||
return Coroutine::getContext($coroutineId)[$id] -= $value;
|
return Coroutine::getContext($coroutineId)[$id] -= $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $id
|
* @param $id
|
||||||
* @param null $default
|
* @param null $default
|
||||||
@@ -80,8 +80,8 @@ class Context extends BaseContext
|
|||||||
}
|
}
|
||||||
return static::loadByContext($id, $default, $coroutineId);
|
return static::loadByContext($id, $default, $coroutineId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $id
|
* @param $id
|
||||||
* @param null $default
|
* @param null $default
|
||||||
@@ -95,8 +95,8 @@ class Context extends BaseContext
|
|||||||
}
|
}
|
||||||
return Coroutine::getContext($coroutineId)[$id] ?? $default;
|
return Coroutine::getContext($coroutineId)[$id] ?? $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $id
|
* @param $id
|
||||||
* @param null $default
|
* @param null $default
|
||||||
@@ -106,8 +106,8 @@ class Context extends BaseContext
|
|||||||
{
|
{
|
||||||
return static::$_contents[$id] ?? $default;
|
return static::$_contents[$id] ?? $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param null $coroutineId
|
* @param null $coroutineId
|
||||||
* @return Coroutine\Context|array
|
* @return Coroutine\Context|array
|
||||||
@@ -120,7 +120,18 @@ class Context extends BaseContext
|
|||||||
return static::$_contents ?? [];
|
return static::$_contents ?? [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function clearAll(): void
|
||||||
|
{
|
||||||
|
if (Coroutine::getCid() === -1) {
|
||||||
|
static::$_contents = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $id
|
* @param string $id
|
||||||
* @param null $coroutineId
|
* @param null $coroutineId
|
||||||
@@ -135,16 +146,16 @@ class Context extends BaseContext
|
|||||||
}
|
}
|
||||||
if (Coroutine::getCid() === -1) {
|
if (Coroutine::getCid() === -1) {
|
||||||
static::$_contents[$id] = null;
|
static::$_contents[$id] = null;
|
||||||
|
|
||||||
unset(static::$_contents[$id]);
|
unset(static::$_contents[$id]);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Coroutine::getContext($coroutineId)[$id] = null;
|
Coroutine::getContext($coroutineId)[$id] = null;
|
||||||
|
|
||||||
unset(Coroutine::getContext($coroutineId)[$id]);
|
unset(Coroutine::getContext($coroutineId)[$id]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $id
|
* @param $id
|
||||||
* @param null $key
|
* @param null $key
|
||||||
@@ -158,8 +169,8 @@ class Context extends BaseContext
|
|||||||
}
|
}
|
||||||
return static::searchByCoroutine($id, $key, $coroutineId);
|
return static::searchByCoroutine($id, $key, $coroutineId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $id
|
* @param $id
|
||||||
* @param null $key
|
* @param null $key
|
||||||
@@ -176,8 +187,8 @@ class Context extends BaseContext
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $id
|
* @param $id
|
||||||
* @param null $key
|
* @param null $key
|
||||||
@@ -198,8 +209,8 @@ class Context extends BaseContext
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@@ -207,7 +218,7 @@ class Context extends BaseContext
|
|||||||
{
|
{
|
||||||
return Coroutine::getCid() !== -1;
|
return Coroutine::getCid() !== -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user