mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-03-17 20:54:52 +08:00
fix properties not initialized
This commit is contained in:
parent
d513495b3b
commit
8f43012a5c
@ -7,8 +7,8 @@ use OneBot\Driver\Process\ProcessManager;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use ZM\Config\Environment;
|
||||
use ZM\Config\EnvironmentInterface;
|
||||
use ZM\Config\ZMConfig;
|
||||
use ZM\Framework;
|
||||
use ZM\Kernel;
|
||||
|
||||
/*
|
||||
* 这里是容器的配置文件,你可以在这里配置容器的绑定和其他一些参数。
|
||||
@ -37,7 +37,7 @@ return [
|
||||
// 详细介绍请参阅:https://php-di.org/doc/performances.html#caching
|
||||
'cache' => [
|
||||
// 是否启用缓存,支持 bool、callable
|
||||
'enable' => fn () => ZMConfig::getInstance()->getEnvironment() === 'production',
|
||||
'enable' => fn () => Kernel::getInstance()->environment('production'),
|
||||
'namespace' => 'zm',
|
||||
],
|
||||
];
|
||||
|
||||
@ -5,15 +5,11 @@ declare(strict_types=1);
|
||||
namespace Module\Example;
|
||||
|
||||
use Choir\Http\ServerRequest;
|
||||
use Choir\WebSocket\FrameInterface;
|
||||
use OneBot\Driver\Coroutine\Adaptive;
|
||||
use OneBot\Driver\Event\WebSocket\WebSocketMessageEvent;
|
||||
use ZM\Annotation\Framework\BindEvent;
|
||||
use ZM\Annotation\Framework\Cron;
|
||||
use ZM\Annotation\Http\Route;
|
||||
use ZM\Annotation\Middleware\Middleware;
|
||||
use ZM\Annotation\OneBot\BotCommand;
|
||||
use ZM\Annotation\OneBot\BotEvent;
|
||||
use ZM\Annotation\OneBot\CommandArgument;
|
||||
use ZM\Annotation\OneBot\CommandHelp;
|
||||
use ZM\Context\BotContext;
|
||||
@ -21,22 +17,22 @@ use ZM\Middleware\TimerMiddleware;
|
||||
|
||||
class Hello123
|
||||
{
|
||||
#[BindEvent(WebSocketMessageEvent::class, level: 5000)]
|
||||
public function onMessage(WebSocketMessageEvent $event)
|
||||
{
|
||||
$Data = json_decode($event->getFrame()->getData(), true);
|
||||
}
|
||||
|
||||
#[Route('/route', request_method: ['GET'])]
|
||||
#[Route('/route/{id}', request_method: ['GET'])]
|
||||
#[Middleware(TimerMiddleware::class)]
|
||||
public function route(array $params, ServerRequest $request, \HttpRequestEvent $event)
|
||||
public function route(array $params, ServerRequest $request, \HttpRequestEvent $event, BotContext $ctx)
|
||||
{
|
||||
// 目前因内部实现限制,路由方法的参数必须按照这个顺序定义,可以省略,但是不能乱序
|
||||
// 如果希望获取其他依赖,可以在现有参数后面继续添加
|
||||
return 'Hello Zhamao!This is the first 3.0 page!' . ($params['id'] ?? '');
|
||||
}
|
||||
|
||||
#[BotEvent()]
|
||||
public function onOBEvent(WebSocketMessageEvent $messageEvent, \OneBotEvent $event): void
|
||||
{
|
||||
logger()->info("收到了 {$event->getType()}.{$event->getDetailType()} 事件");
|
||||
}
|
||||
|
||||
#[BotCommand('echo', 'echo')]
|
||||
#[CommandArgument('text', '要回复的内容', required: true)]
|
||||
#[CommandHelp('复读机', '只需要发送 echo+内容 即可自动复读', 'echo 你好 会回复 你好')]
|
||||
@ -44,25 +40,4 @@ class Hello123
|
||||
{
|
||||
$context->reply($event->getMessage());
|
||||
}
|
||||
|
||||
#[BindEvent(WebSocketMessageEvent::class)]
|
||||
public function onWSMessage(FrameInterface $frame, WebSocketMessageEvent $event): void
|
||||
{
|
||||
logger()->info('收到了 WebSocket 消息');
|
||||
}
|
||||
|
||||
#[Cron('* * * * *', no_overlap: true)]
|
||||
public function logTime(): void
|
||||
{
|
||||
$time = date('Y-m-d H:i:s');
|
||||
logger()->info('我看到时间了,让我写下来');
|
||||
Adaptive::sleep(5);
|
||||
logger()->info('写好啦,时间是' . $time);
|
||||
}
|
||||
|
||||
#[Cron('* * * * *')]
|
||||
public function logTime2(): void
|
||||
{
|
||||
logger()->info('我不需要等,但也不给你看时间');
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,13 +13,13 @@ class Kernel
|
||||
|
||||
private array $bootstrappers = [];
|
||||
|
||||
private string $config_dir;
|
||||
private string $config_dir = SOURCE_ROOT_DIR . '/config';
|
||||
|
||||
private string $environment;
|
||||
private string $environment = 'development';
|
||||
|
||||
private bool $debug_mode = false;
|
||||
|
||||
private string $log_level;
|
||||
private string $log_level = 'info';
|
||||
|
||||
private bool $test_mode = false;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user