Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
AddHeaders | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
process | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace Engelsystem\Middleware; |
6 | |
7 | use Engelsystem\Config\Config; |
8 | use Psr\Http\Message\ResponseInterface; |
9 | use Psr\Http\Message\ServerRequestInterface; |
10 | use Psr\Http\Server\MiddlewareInterface; |
11 | use Psr\Http\Server\RequestHandlerInterface; |
12 | |
13 | class AddHeaders implements MiddlewareInterface |
14 | { |
15 | public function __construct(protected Config $config) |
16 | { |
17 | } |
18 | |
19 | /** |
20 | * Process an incoming server request and setting the locale if required |
21 | */ |
22 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
23 | { |
24 | $response = $handler->handle($request); |
25 | if (!$this->config->get('add_headers', true)) { |
26 | return $response; |
27 | } |
28 | |
29 | $headers = $this->config->get('headers', []); |
30 | |
31 | foreach ($headers as $name => $value) { |
32 | $response = $response->withAddedHeader($name, $value); |
33 | } |
34 | |
35 | return $response; |
36 | } |
37 | } |