mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-21 15:45:36 +08:00
fix container and coroutine
This commit is contained in:
@@ -17,17 +17,16 @@
|
|||||||
"ext-json": "*",
|
"ext-json": "*",
|
||||||
"doctrine/dbal": "^2.13.1",
|
"doctrine/dbal": "^2.13.1",
|
||||||
"dragonmantank/cron-expression": "^3.3",
|
"dragonmantank/cron-expression": "^3.3",
|
||||||
"jasny/phpdoc-parser": "^1.0",
|
|
||||||
"jelix/version": "^2.0",
|
"jelix/version": "^2.0",
|
||||||
"koriym/attributes": "^1.0",
|
"koriym/attributes": "^1.0",
|
||||||
"onebot/libonebot": "dev-develop",
|
|
||||||
"psr/container": "^2.0",
|
"psr/container": "^2.0",
|
||||||
"symfony/console": "~6.0 || ~5.0 || ~4.0",
|
"symfony/console": "~6.0 || ~5.0 || ~4.0",
|
||||||
"symfony/polyfill-ctype": "^1.19",
|
"symfony/polyfill-ctype": "^1.19",
|
||||||
"symfony/polyfill-mbstring": "^1.19",
|
"symfony/polyfill-mbstring": "^1.19",
|
||||||
"symfony/polyfill-php80": "^1.16",
|
"symfony/polyfill-php80": "^1.16",
|
||||||
"symfony/routing": "~6.0 || ~5.0 || ~4.0",
|
"symfony/routing": "~6.0 || ~5.0 || ~4.0",
|
||||||
"zhamao/logger": "dev-master"
|
"zhamao/logger": "dev-master",
|
||||||
|
"onebot/libonebot": "dev-develop"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"brainmaestro/composer-git-hooks": "^2.8",
|
"brainmaestro/composer-git-hooks": "^2.8",
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ parameters:
|
|||||||
- '#PHPDoc tag @throws with type Psr\\Container\\ContainerExceptionInterface is not subtype of Throwable#'
|
- '#PHPDoc tag @throws with type Psr\\Container\\ContainerExceptionInterface is not subtype of Throwable#'
|
||||||
- '#Unsafe usage of new static#'
|
- '#Unsafe usage of new static#'
|
||||||
- '#Call to method initTableList\(\) of deprecated class ZM\\DB\\DB#'
|
- '#Call to method initTableList\(\) of deprecated class ZM\\DB\\DB#'
|
||||||
|
- '#class Fiber#'
|
||||||
dynamicConstantNames:
|
dynamicConstantNames:
|
||||||
- SWOOLE_VERSION
|
- SWOOLE_VERSION
|
||||||
- ZM_TEST_LOG_DEBUG
|
- ZM_TEST_LOG_DEBUG
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use OneBot\Driver\Coroutine\Adaptive;
|
||||||
|
use OneBot\Driver\Coroutine\CoroutineInterface;
|
||||||
|
use OneBot\Driver\Process\ExecutionResult;
|
||||||
use OneBot\V12\Object\MessageSegment;
|
use OneBot\V12\Object\MessageSegment;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use ZM\Container\Container;
|
use ZM\Container\Container;
|
||||||
@@ -28,6 +31,34 @@ function zm_dir(string $dir): string
|
|||||||
return str_replace('/', DIRECTORY_SEPARATOR, $dir);
|
return str_replace('/', DIRECTORY_SEPARATOR, $dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行shell指令
|
||||||
|
*
|
||||||
|
* @param string $cmd 命令行
|
||||||
|
*/
|
||||||
|
function zm_exec(string $cmd): ExecutionResult
|
||||||
|
{
|
||||||
|
return Adaptive::exec($cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sleep 指定时间,单位为秒(最小单位为1毫秒,即0.001)
|
||||||
|
*
|
||||||
|
* @param float|int $time
|
||||||
|
*/
|
||||||
|
function zm_sleep($time)
|
||||||
|
{
|
||||||
|
Adaptive::sleep($time);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取协程接口
|
||||||
|
*/
|
||||||
|
function coroutine(): ?CoroutineInterface
|
||||||
|
{
|
||||||
|
return Adaptive::getCoroutine();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取内部错误码
|
* 获取内部错误码
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -90,9 +90,9 @@ class ContainerServicesProvider
|
|||||||
{
|
{
|
||||||
// $context = Context::$context[zm_cid()];
|
// $context = Context::$context[zm_cid()];
|
||||||
$container->instance(HttpRequestEvent::class, $event);
|
$container->instance(HttpRequestEvent::class, $event);
|
||||||
$container->alias('http.request.event', HttpRequestEvent::class);
|
$container->alias(HttpRequestEvent::class, 'http.request.event');
|
||||||
$container->instance(ServerRequestInterface::class, $event->getRequest());
|
$container->instance(ServerRequestInterface::class, $event->getRequest());
|
||||||
$container->alias('http.request', ServerRequestInterface::class);
|
$container->alias(ServerRequestInterface::class, 'http.request');
|
||||||
// $container->instance(Request::class, $context['request']);
|
// $container->instance(Request::class, $context['request']);
|
||||||
// $container->instance(Response::class, $context['response']);
|
// $container->instance(Response::class, $context['response']);
|
||||||
$container->bind(ContextInterface::class, Context::class);
|
$container->bind(ContextInterface::class, Context::class);
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ class HttpEventListener
|
|||||||
{
|
{
|
||||||
// 注册容器
|
// 注册容器
|
||||||
resolve(ContainerServicesProvider::class)->registerServices('request', $event);
|
resolve(ContainerServicesProvider::class)->registerServices('request', $event);
|
||||||
|
// TODO: 这里有个bug,如果是用的Workerman+Fiber协程的话,有个前置协程挂起,这里获取到的Event是被挂起的Event对象,触发两次事件才能归正
|
||||||
// 跑一遍 BindEvent 绑定了 HttpRequestEvent 的注解
|
// 跑一遍 BindEvent 绑定了 HttpRequestEvent 的注解
|
||||||
$handler = new AnnotationHandler(BindEvent::class);
|
$handler = new AnnotationHandler(BindEvent::class);
|
||||||
$handler->setRuleCallback(function (BindEvent $anno) {
|
$handler->setRuleCallback(function (BindEvent $anno) {
|
||||||
|
|||||||
@@ -8,9 +8,10 @@ class ZMUtil
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* 获取 composer.json 并转为数组进行读取使用
|
* 获取 composer.json 并转为数组进行读取使用
|
||||||
|
* @param null|string $path 路径
|
||||||
*/
|
*/
|
||||||
public static function getComposerMetadata(): ?array
|
public static function getComposerMetadata(?string $path = null): ?array
|
||||||
{
|
{
|
||||||
return json_decode(file_get_contents(SOURCE_ROOT_DIR . '/composer.json'), true);
|
return json_decode(file_get_contents(($path ?? SOURCE_ROOT_DIR) . '/composer.json'), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user