mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-03-17 20:54:52 +08:00
Merge pull request #310 from zhamao-robot/add-invalid-definition-solutions
添加 InvalidDefinition 解决方案提示
This commit is contained in:
commit
d559a91ddb
@ -4,6 +4,7 @@ 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;
|
||||
@ -23,8 +24,10 @@ class Hello123
|
||||
#[Route('/route', request_method: ['GET'])]
|
||||
#[Route('/route/{id}', request_method: ['GET'])]
|
||||
#[Middleware(TimerMiddleware::class)]
|
||||
public function route(array $params)
|
||||
public function route(array $params, ServerRequest $request, \HttpRequestEvent $event)
|
||||
{
|
||||
// 目前因内部实现限制,路由方法的参数必须按照这个顺序定义,可以省略,但是不能乱序
|
||||
// 如果希望获取其他依赖,可以在现有参数后面继续添加
|
||||
return 'Hello Zhamao!This is the first 3.0 page!' . ($params['id'] ?? '');
|
||||
}
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace ZM\Exception\Solution;
|
||||
|
||||
use DI\Definition\Exception\InvalidDefinition;
|
||||
use NunoMaduro\Collision\Contracts\SolutionsRepository;
|
||||
|
||||
class SolutionRepository implements SolutionsRepository
|
||||
@ -17,6 +18,14 @@ class SolutionRepository implements SolutionsRepository
|
||||
{
|
||||
return match ($throwable::class) {
|
||||
default => [],
|
||||
InvalidDefinition::class => [
|
||||
new Solution('无法解析依赖注入', '请检查依赖注入的类是否存在,或者定义是否正确。', []),
|
||||
new Solution(
|
||||
'依赖注入用例错误',
|
||||
'请检查注入的类是否在对应的事件中可用,详情可以查看文档。',
|
||||
['https://framework.zhamao.xin/components/container/dependencies.html']
|
||||
),
|
||||
],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user