Completed
Push — master ( 69874a...7c59db )
by Vytautas
02:52
created

SwaggerUI::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 1
crap 1
1
<?php
2
3
namespace SwaggerMiddleware\Middleware;
4
5
use Psr\Http\Message\ResponseInterface;
6
use Psr\Http\Server\RequestHandlerInterface;
7
use Psr\Http\Message\ServerRequestInterface;
8
use Zend\Diactoros\Response\HtmlResponse;
9
10
class SwaggerUI implements RequestHandlerInterface
11
{
12
    /**
13
     * @var array
14
     */
15
    private $config;
16
17 6
    public function __construct(array $config)
18
    {
19 6
        $this->config = $config;
20 6
    }
21
22 3
    public function handle(ServerRequestInterface $request): ResponseInterface
23
    {
24 3
        $template = file_get_contents(dirname(__DIR__).'/templates/documentation.phtml');
25
26 3
        $template = str_replace([
27 3
            '{__TITLE__}',
28
            '{__ASSETS_PATH__}',
29
            '{__API_SPEC_URL__}',
30
        ], [
31 3
            $this->config['title'],
32 3
            $this->config['routes']['assets'],
33 3
            $this->config['routes']['specification'],
34 3
        ], $template);
35
36 3
        return new HtmlResponse($template);
37
    }
38
}
39