mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-02 14:25:38 +08:00
fix properties not initialized
This commit is contained in:
@@ -7,8 +7,8 @@ use OneBot\Driver\Process\ProcessManager;
|
|||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use ZM\Config\Environment;
|
use ZM\Config\Environment;
|
||||||
use ZM\Config\EnvironmentInterface;
|
use ZM\Config\EnvironmentInterface;
|
||||||
use ZM\Config\ZMConfig;
|
|
||||||
use ZM\Framework;
|
use ZM\Framework;
|
||||||
|
use ZM\Kernel;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 这里是容器的配置文件,你可以在这里配置容器的绑定和其他一些参数。
|
* 这里是容器的配置文件,你可以在这里配置容器的绑定和其他一些参数。
|
||||||
@@ -37,7 +37,7 @@ return [
|
|||||||
// 详细介绍请参阅:https://php-di.org/doc/performances.html#caching
|
// 详细介绍请参阅:https://php-di.org/doc/performances.html#caching
|
||||||
'cache' => [
|
'cache' => [
|
||||||
// 是否启用缓存,支持 bool、callable
|
// 是否启用缓存,支持 bool、callable
|
||||||
'enable' => fn () => ZMConfig::getInstance()->getEnvironment() === 'production',
|
'enable' => fn () => Kernel::getInstance()->environment('production'),
|
||||||
'namespace' => 'zm',
|
'namespace' => 'zm',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -5,15 +5,11 @@ declare(strict_types=1);
|
|||||||
namespace Module\Example;
|
namespace Module\Example;
|
||||||
|
|
||||||
use Choir\Http\ServerRequest;
|
use Choir\Http\ServerRequest;
|
||||||
use Choir\WebSocket\FrameInterface;
|
|
||||||
use OneBot\Driver\Coroutine\Adaptive;
|
|
||||||
use OneBot\Driver\Event\WebSocket\WebSocketMessageEvent;
|
use OneBot\Driver\Event\WebSocket\WebSocketMessageEvent;
|
||||||
use ZM\Annotation\Framework\BindEvent;
|
use ZM\Annotation\Framework\BindEvent;
|
||||||
use ZM\Annotation\Framework\Cron;
|
|
||||||
use ZM\Annotation\Http\Route;
|
use ZM\Annotation\Http\Route;
|
||||||
use ZM\Annotation\Middleware\Middleware;
|
use ZM\Annotation\Middleware\Middleware;
|
||||||
use ZM\Annotation\OneBot\BotCommand;
|
use ZM\Annotation\OneBot\BotCommand;
|
||||||
use ZM\Annotation\OneBot\BotEvent;
|
|
||||||
use ZM\Annotation\OneBot\CommandArgument;
|
use ZM\Annotation\OneBot\CommandArgument;
|
||||||
use ZM\Annotation\OneBot\CommandHelp;
|
use ZM\Annotation\OneBot\CommandHelp;
|
||||||
use ZM\Context\BotContext;
|
use ZM\Context\BotContext;
|
||||||
@@ -21,22 +17,22 @@ use ZM\Middleware\TimerMiddleware;
|
|||||||
|
|
||||||
class Hello123
|
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', request_method: ['GET'])]
|
||||||
#[Route('/route/{id}', request_method: ['GET'])]
|
#[Route('/route/{id}', request_method: ['GET'])]
|
||||||
#[Middleware(TimerMiddleware::class)]
|
#[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'] ?? '');
|
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')]
|
#[BotCommand('echo', 'echo')]
|
||||||
#[CommandArgument('text', '要回复的内容', required: true)]
|
#[CommandArgument('text', '要回复的内容', required: true)]
|
||||||
#[CommandHelp('复读机', '只需要发送 echo+内容 即可自动复读', 'echo 你好 会回复 你好')]
|
#[CommandHelp('复读机', '只需要发送 echo+内容 即可自动复读', 'echo 你好 会回复 你好')]
|
||||||
@@ -44,25 +40,4 @@ class Hello123
|
|||||||
{
|
{
|
||||||
$context->reply($event->getMessage());
|
$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 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 bool $debug_mode = false;
|
||||||
|
|
||||||
private string $log_level;
|
private string $log_level = 'info';
|
||||||
|
|
||||||
private bool $test_mode = false;
|
private bool $test_mode = false;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user