Skip to content

Latest commit

 

History

History
77 lines (55 loc) · 1.24 KB

README.md

File metadata and controls

77 lines (55 loc) · 1.24 KB

var-dumper 适配包,用来将变量打印到浏览器

安装

composer require next/var-dumper

使用

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,
        ],
    ],
];

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,
];

其他框架可参考webman配置,引入DumperHandler,将异常转为响应即可

打印

d($request);