Skip to content

Commit c600eb0

Browse files
committed
Add psr-15
1 parent 7c13dac commit c600eb0

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

Diff for: composer.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
],
1111
"require": {
1212
"php": "^5.6 || ^7.0",
13-
"psr/http-message": "^1.0"
13+
"psr/http-message": "^1.0",
14+
"php-middleware/double-pass-compatibility": "^1.0",
15+
"http-interop/http-middleware": "^0.4.1"
1416
},
1517
"require-dev": {
1618
"phpunit/phpunit": "^5.6 || ^6.1.3",

Diff for: src/RequestIdMiddleware.php

+10-11
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22

33
namespace PhpMiddleware\RequestId;
44

5+
use Interop\Http\ServerMiddleware\DelegateInterface;
6+
use Interop\Http\ServerMiddleware\MiddlewareInterface;
7+
use PhpMiddleware\DoublePassCompatibilityTrait;
58
use PhpMiddleware\RequestId\Exception\NotGenerated;
69
use PhpMiddleware\RequestId\RequestIdProviderFactoryInterface;
710
use Psr\Http\Message\ResponseInterface;
811
use Psr\Http\Message\ServerRequestInterface;
912

10-
final class RequestIdMiddleware implements RequestIdProviderInterface
13+
final class RequestIdMiddleware implements RequestIdProviderInterface, MiddlewareInterface
1114
{
15+
use DoublePassCompatibilityTrait;
16+
1217
const DEFAULT_RESPONSE_HEADER = 'X-Request-Id';
1318
const ATTRIBUTE_NAME = 'request-id';
1419

@@ -40,26 +45,20 @@ public function __construct(
4045
}
4146

4247
/**
43-
* @param ServerRequestInterface $request
44-
* @param ResponseInterface $response
45-
* @param callable $next
46-
*
4748
* @return ResponseInterface
4849
*/
49-
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
50+
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
5051
{
5152
$requestIdProvider = $this->requestIdProviderFactory->create($request);
52-
5353
$this->requestId = $requestIdProvider->getRequestId();
54-
5554
$requestWithAttribute = $request->withAttribute(self::ATTRIBUTE_NAME, $this->requestId);
5655

57-
$nextResponse = $next($requestWithAttribute, $response);
56+
$response = $delegate->process($requestWithAttribute);
5857

5958
if (is_string($this->responseHeader)) {
60-
return $nextResponse->withHeader($this->responseHeader, $this->requestId);
59+
return $response->withHeader($this->responseHeader, $this->requestId);
6160
}
62-
return $nextResponse;
61+
return $response;
6362
}
6463

6564
/**

0 commit comments

Comments
 (0)