var-dumper 将变量打印到浏览器

1.1.1 版本
2022-09-12 版本更新时间
43 安装
0 star

简介

这是一款将变量用symfony/var-dumper打印到浏览器的包,支持Webman, MaxPHP,Hyperf等框架。

安装

composer require max/var-dumper

使用

webman

建立新的异常处理类

<?php

namespace App;

use Max\VarDumper\Abort;
use Max\VarDumper\AbortHandler;
use support\exception\Handler;
use Throwable;
use Webman\Http\Request;
use Webman\Http\Response;

class ExceptionHandler extends Handler
{
    use AbortHandler;

    public function render(Request $request, Throwable $exception): Response
    {
        if ($exception instanceof Abort) {
            return \response($this->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' => [
            \Max\VarDumper\Adapter\HyperfAbortHandler::class,
            Hyperf\HttpServer\Exception\Handler\HttpExceptionHandler::class,
            App\Exception\Handler\AppExceptionHandler::class,
        ],
    ],
];

打印

d($request);

注意是d,不是dd/dump