[Pandaman] #[AsDebugDataCollector] debug信息收集注解

wasoncheung

debug是开发中 必不可少的一环

pandaman内置了debugbar,使用注解可以快速方便的在任何位置注册你的debug信息

// 注册debug信息收集器
#[AsDebugDataCollector]
class ConfigDataCollector extends RequestDataCollector
{
    public function getName()
    {
        return 'config';
    }

    public function collect()
    {
        foreach (\config()->get() as $key => $value) {
            $data[$key] = $this->getDataFormatter()->formatVar($value);
        }

        return $data ?? [];
    }

    public function getWidgets()
    {
        return array(
            "config" => array(
                "icon" => "gears",
                "widget" => "PhpDebugBar.Widgets.VariableListWidget",
                "map" => "config",
                "default" => "{}"
            )
        );
    }
}

425 0 0
0个评论

wasoncheung

1070
积分
0
获赞数
0
粉丝数
2022-11-15 加入
🔝