2024-05-31 09:27:37 +08:00

78 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var-dumper 适配包,用来将变量打印到浏览器
# 安装
```shell
composer require next/var-dumper
```
# 使用
## hyperf
修改`app/config/autoload/exceptions.php`
```php
<?php
declare(strict_types=1);
return [
'handler' => [
'http' => [
Next\VarDumper\Adapter\HyperfDumperHandler::class,
Hyperf\HttpServer\Exception\Handler\HttpExceptionHandler::class,
App\Exception\Handler\AppExceptionHandler::class,
],
],
];
```
## webman
建立新的异常处理类
```php
<?php
namespace App;
use Next\VarDumper\Dumper;
use Next\VarDumper\DumperHandler;
use support\exception\Handler;
use Throwable;
use Webman\Http\Request;
use Webman\Http\Response;
class ExceptionHandler extends Handler
{
use DumperHandler;
public function render(Request $request, Throwable $exception): Response
{
if ($exception instanceof Dumper) {
return \response(self::convertToHtml($exception));
}
return parent::render($request, $exception);
}
}
```
修改config/exception.php
```php
return [
'' => \App\ExceptionHandler::class,
];
```
## 其他框架可参考webman配置引入DumperHandler将异常转为响应即可
# 打印
```php
d($request);
```