Passed
Push — master ( 1ffb2d...f18857 )
by Dmitriy
05:56 queued 02:52
created

DebugHeaders   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 14
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 8 1
A __construct() 0 2 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Api\Debug\Middleware;
6
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
use Psr\Http\Server\MiddlewareInterface;
10
use Psr\Http\Server\RequestHandlerInterface;
11
use Yiisoft\Router\UrlGeneratorInterface;
12
use Yiisoft\Yii\Debug\DebuggerIdGenerator;
13
14
/**
15
 * Adds debug headers to response. Information from these headers may be used to request information about
16
 * the current request as it is done in the debug toolbar.
17
 */
18
final class DebugHeaders implements MiddlewareInterface
19
{
20
    public function __construct(private DebuggerIdGenerator $idGenerator, private UrlGeneratorInterface $urlGenerator)
21
    {
22
    }
23
24
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
25
    {
26
        $response = $handler->handle($request);
27
        $link = $this->urlGenerator->generate('debug/api/view', ['id' => $this->idGenerator->getId()]);
28
29
        return $response
30
            ->withHeader('X-Debug-Id', $this->idGenerator->getId())
31
            ->withHeader('X-Debug-Link', $link);
32
    }
33
}
34