基于webman,如何设计request_id呢?

yysu

请教,基于webman,如何设计request_id呢?

1588 1 1
1个回答

WatcherLuo

在config/middleware.php配置全局中间件
return [
// 全局中间件
'' => [
app\middleware\RequestId::class,
]
];

app\middleware目录新建RequestId.php

namespace app\middleware;

use Webman\MiddlewareInterface;
use Webman\Http\Response;
use Webman\Http\Request;

/**

  • Class StaticFile
  • @package app\middleware
    */
    class RequestId implements MiddlewareInterface
    {
    public function process(Request $request, callable $next): Response
    {
    $requestID = strtoupper(uniqid(date('ymdHis') . create_random_string(2), true));
    $request->requestID = $requestID; // 带出
    $response = $next($request);
    return $response;
    }
    }
年代过于久远,无法发表回答
×
🔝