hhxsv5 / laravel-s

LaravelS is an out-of-the-box adapter between Laravel/Lumen and Swoole.
MIT License
3.84k stars 475 forks source link

Feature Request: add dump and die support #286

Open juslintek opened 4 years ago

juslintek commented 4 years ago

This has been added by https://github.com/swooletw/laravel-swoole/issues/254 You can even override dd: https://gist.github.com/chrisliuqq/96de1ef8160a1d41b6af315c6fb611f3

hhxsv5 commented 4 years ago

Thanks for your request, I'm trying to find a way to implement die().

use Symfony\Component\VarDumper\Caster\ReflectionCaster;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\CliDumper;
use Symfony\Component\VarDumper\Dumper\HtmlDumper;

if (!function_exists('dd')) {
    function dd()
    {
        static $cloner, $dumper;
        if (null === $cloner) {
            $cloner = new VarCloner();
            $cloner->addCasters(ReflectionCaster::UNSET_CLOSURE_FILE_INFO);

            if (app()->offsetExists('swoole') && app('swoole')->worker_id < app('swoole')->setting['worker_num']) {
                $dumper = new HtmlDumper();
            } else {
                $dumper = new CliDumper();
            }
        }
        if ($dumper instanceof HtmlDumper) {
            $dumper->setStyles([]);
        }

        foreach (func_get_args() as $var) {
            $dumper->dump($cloner->cloneVar($var));
        }

        // how to die ?
    }
}