该包已被废弃且不再维护。未建议替代包。

HTTP Web 调试协议的实现(核心库)

dev-master 2019-04-05 08:44 UTC

This package is auto-updated.

Last update: 2023-04-05 18:16:34 UTC


README

Build Status

这是官方PHP核心库,实现了https://web-debug.dev/的服务端实现

您应使用它来为其他框架和CMS的级别1捆绑包/模块。

安装

$ composer require web-debug/core

支持的方案版本

版本 是否支持?
1

如何使用

use WebDebug\Builders\Events\EventLog;
use WebDebug\Builders\Types\TypeTagMultipart;
use WebDebug\Profiler;

// use any psr-6/psr-16 cache for persistent storage
$cache = new Symfony\Component\Cache\Simple\FilesystemCache('cache', 60, 'cache');

// make new profiler storage object
$profiler = new Profiler(
    version: Profiler::VERSION_1, 
    storage: $cache, 
    isProduction: false
);

// create some events
$log = new EventLog('Hello world');
$log->context = [
    'something' => 123
];
$log->tags->add(new TypeTagMultipart('name', 'value_for_filter'));
$log->tags->add(new TypeTagMultipart('component', 'kernel'));

// add events to scheme
$profiler->addEvent($log);
$profiler->addEvent(new EventLog('Another message'));
$profiler->addEvent(new EventLog('And another'));

// save generated json to storage
$uuid = $profiler->push(); // bdb01adb-895b-4a8b-b1b3-bbd5aca237fe
$json = $profiler->pop($uuid); // json for HTTP response

这将生成这里描述的有效方案:https://web-debug.dev/docs/scheme/

{
   "id":"bdb01adb-895b-4a8b-b1b3-bbd5aca237fe",
   "version":1,
   "events":[
      {
         "type":"log",
         "payload":{
            "message":"Hello world",
            "context":"{\"something\":123}"
         },
         "tags":[
            "name:value_for_filter",
            "component:kernel"
         ],
         "importance":1,
         "time":1554234913359,
         "nested":[]
      },
      {
         "type":"log",
         "payload":{
            "message":"Another message"
         },
         "tags":[],
         "importance":1,
         "time":1554234913447,
         "nested":[]
      },
      {
         "type":"log",
         "payload":{
            "message":"And another"
         },
         "tags":[],
         "importance":1,
         "time":1554234913506,
         "nested":[]
      }
   ]
}

在此查看可用事件列表

https://web-debug.dev/docs/scheme/events.html

如何获取HTTP传输的头部信息

https://web-debug.dev/docs/specification/transport/headers-request.html

此传输需要两个头部信息

X-Http-Debug-Id: ef95a542-25a3-4f71-a0e9-640c92f43813
X-Http-Debug-Api: /_profile/?id=
$profiler = new Profiler(..);
$xHttpDebugId = $profiler->uuid; // ef95a542-25a3-4f71-a0e9-640c92f43813
$xHttpDebugApi = '<your api endpoint>';