1
|
|
|
<?php |
2
|
|
|
namespace W2w\Laravel\Apie\Controllers; |
3
|
|
|
|
4
|
|
|
use Illuminate\Contracts\Routing\UrlGenerator as LaravelUrlGenerator; |
5
|
|
|
use Laravel\Lumen\Routing\UrlGenerator as LumenUrlGenerator; |
|
|
|
|
6
|
|
|
use W2w\Laravel\Apie\Exceptions\FileNotFoundException; |
7
|
|
|
use W2w\Laravel\Apie\Services\ApieContext; |
8
|
|
|
use Zend\Diactoros\Response\TextResponse; |
|
|
|
|
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Renders swagger UI for the openAPI spec generated by Apie. |
12
|
|
|
*/ |
13
|
|
|
class SwaggerUiController |
14
|
|
|
{ |
15
|
|
|
private $apieContext; |
16
|
|
|
|
17
|
|
|
private $urlGenerator; |
18
|
|
|
|
19
|
|
|
private $htmlLocation; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param ApieContext $apieContext |
23
|
|
|
* @param LaravelUrlGenerator|LumenUrlGenerator $urlGenerator |
24
|
|
|
* @param string $htmlLocation |
25
|
|
|
*/ |
26
|
|
|
public function __construct(ApieContext $apieContext, $urlGenerator, string $htmlLocation) |
27
|
|
|
{ |
28
|
|
|
$this->apieContext = $apieContext; |
29
|
|
|
$this->urlGenerator = $urlGenerator; |
30
|
|
|
$this->htmlLocation = $htmlLocation; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function __invoke() |
34
|
|
|
{ |
35
|
|
|
$contents = @file_get_contents($this->htmlLocation); |
36
|
|
|
if (false === $contents) { |
37
|
|
|
throw new FileNotFoundException($this->htmlLocation); |
38
|
|
|
} |
39
|
|
|
$context = $this->apieContext->getActiveContext()->getContextKey(); |
40
|
|
|
$contextString = empty($context) ? '' : (implode('.', $context) . '.'); |
41
|
|
|
$url = $this->urlGenerator->route('apie.' . $contextString . 'docsyaml'); |
42
|
|
|
|
43
|
|
|
return new TextResponse( |
44
|
|
|
str_replace('{{ url }}', $url, $contents), |
45
|
|
|
200, |
46
|
|
|
[ |
47
|
|
|
'content-type' => 'text/html' |
48
|
|
|
] |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths