Merge pull request #310 from zhamao-robot/add-invalid-definition-solutions

添加 InvalidDefinition 解决方案提示
This commit is contained in:
sunxyw 2023-02-13 11:14:16 +08:00 committed by GitHub
commit d559a91ddb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -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 ZhamaoThis is the first 3.0 page' . ($params['id'] ?? '');
}

View File

@ -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']
),
],
};
}
}