Commit 83a0791a authored by 谢宇轩's avatar 谢宇轩 😅

Merge branch 'FeatDelUUID' into 'master'

Feat: del uuid library require

See merge request back-end/easy-http-sdk!4
parents c0eda261 e4d0a1a3
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
"symfony/cache": "^5.4", "symfony/cache": "^5.4",
"yosymfony/toml": "^1.0", "yosymfony/toml": "^1.0",
"guzzlehttp/guzzle": "^7.5", "guzzlehttp/guzzle": "^7.5",
"ramsey/uuid": "~3.8.0",
"ext-json": "*" "ext-json": "*"
}, },
"require-dev": { "require-dev": {
......
...@@ -12,11 +12,12 @@ class RequestIDMiddleware implements MiddlewareInterface ...@@ -12,11 +12,12 @@ class RequestIDMiddleware implements MiddlewareInterface
protected $uuid; protected $uuid;
/** /**
* @param string|null $uuid * @param string $uuid
*/ */
public function __construct(string $uuid = null){ public function __construct(string $uuid = "")
if (!$uuid) { {
$uuid = substr(Uuid::uuid4()->toString(), 0, 8); if (empty($uuid)) {
$uuid = sprintf('%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff));
} }
$this->uuid = $uuid; $this->uuid = $uuid;
} }
...@@ -31,7 +32,7 @@ class RequestIDMiddleware implements MiddlewareInterface ...@@ -31,7 +32,7 @@ class RequestIDMiddleware implements MiddlewareInterface
{ {
return function ( return function (
RequestInterface $request, RequestInterface $request,
array $options array $options
) use ($handler) { ) use ($handler) {
$request = $request->withHeader("X-Request-ID", $this->uuid); $request = $request->withHeader("X-Request-ID", $this->uuid);
return $handler($request, $options); return $handler($request, $options);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment