change ctx return force to ContextInterface (build 437)

This commit is contained in:
crazywhalecc
2022-03-17 19:42:59 +08:00
parent 1706afbcd0
commit ce7f2b1765
3 changed files with 13 additions and 6 deletions

View File

@@ -71,5 +71,6 @@
| E00069 | 框架不能启动两个 ConsoleApplication 实例 | 不要重复使用 `new ConsoleApplication()`。 |
| E00070 | 框架找不到 `zm_data` 目录 | 检查配置中指定的 `zm_data` 目录是否存在。 |
| E00071 | 框架找不到对应类型的 API 调用类 | 检查 `getExtendedAPI($name)` 传入的 `$name` 是否正确 |
| E00072 | 上下文无法找到 | 检查上下文环境,如是否处于协程环境中
| E99999 | 未知错误 | |

View File

@@ -28,9 +28,9 @@ use ZM\Exception\InitException;
class ConsoleApplication extends Application
{
public const VERSION_ID = 436;
public const VERSION_ID = 437;
public const VERSION = '2.7.0-beta2';
public const VERSION = '2.7.0-beta3';
private static $obj;

View File

@@ -17,6 +17,7 @@ use ZM\Context\ContextInterface;
use ZM\Event\EventManager;
use ZM\Exception\RobotNotFoundException;
use ZM\Exception\ZMException;
use ZM\Exception\ZMKnownException;
use ZM\Framework;
use ZM\Store\LightCacheInside;
use ZM\Store\ZMAtomic;
@@ -224,12 +225,18 @@ function set_coroutine_params($array)
}
}
function context(): ?ContextInterface
/**
* @throws ZMKnownException
*/
function context(): ContextInterface
{
return ctx();
}
function ctx(): ?ContextInterface
/**
* @throws ZMKnownException
*/
function ctx(): ContextInterface
{
$cid = Co::getCid();
$c_class = ZMConfig::get('global', 'context_class');
@@ -243,8 +250,7 @@ function ctx(): ?ContextInterface
return ZMBuf::$context_class[$cid] ?? (ZMBuf::$context_class[$cid] = new $c_class($cid));
}
}
return null;
throw new ZMKnownException(zm_internal_errcode('E00072') . 'Unable to find context environment');
}
function onebot_target_id_name($message_type): string