var-dumper 适配包,用来将变量打印到浏览器
composer require next/var-dumper
修改app/config/autoload/exceptions.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,
],
],
];
建立新的异常处理类
<?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
return [
'' => \App\ExceptionHandler::class,
];
d($request);