请教,基于webman,如何设计request_id呢?
在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;
/**
感谢大佬
在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 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;
}
}
感谢大佬