var-dumper 将变量打印到浏览器
0.1.1
版本
2024-05-24
版本更新时间
2221
安装
0
star
简介
这是一款将变量用symfony/var-dumper打印到浏览器的包,支持Webman, NextPHP,Hyperf等框架。
安装
composer require next/var-dumper
使用
webman
建立新的异常处理类
<?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,
];
hyperf
修改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,
],
],
];
打印
d($request);
注意是d,不是dd/dump