1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace W2w\Laravel\Apie\Services; |
5
|
|
|
|
6
|
|
|
class ApieRouteLoader |
7
|
|
|
{ |
8
|
|
|
private $context; |
9
|
|
|
|
10
|
|
|
private $routeLoader; |
11
|
|
|
|
12
|
|
|
public function __construct(ApieContext $context, RouteLoaderInterface $routeLoader) { |
13
|
|
|
$this->context = $context; |
14
|
|
|
$this->routeLoader = $routeLoader; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function renderRoutes() |
18
|
|
|
{ |
19
|
|
|
$this->renderContext($this->context); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
private function renderContext(ApieContext $context) |
23
|
|
|
{ |
24
|
|
|
if (!$context->getConfig('disable-routes')) { |
25
|
|
|
$this->routeLoader->context( |
26
|
|
|
$context->getContextKey(), |
27
|
|
|
$context->getConfig('api-url'), |
28
|
|
|
$context->getConfig('swagger-ui-test-page-middleware'), |
29
|
|
|
function () use ($context) { |
30
|
|
|
$this->routeLoader->addDocUrl($context->getContextKey()); |
31
|
|
|
} |
32
|
|
|
); |
33
|
|
|
$this->routeLoader->context( |
34
|
|
|
$context->getContextKey(), |
35
|
|
|
$context->getConfig('api-url'), |
36
|
|
|
$context->getConfig('apie-middleware'), |
37
|
|
|
function () use ($context) { |
38
|
|
|
$this->routeLoader->addResourceUrl($context->getContextKey()); |
39
|
|
|
} |
40
|
|
|
); |
41
|
|
|
if ($context->getConfig('swagger-ui-test-page')) { |
42
|
|
|
$this->routeLoader->context( |
43
|
|
|
$context->getContextKey(), |
44
|
|
|
$context->getConfig('swagger-ui-test-page'), |
45
|
|
|
$context->getConfig('swagger-ui-test-page-middleware'), |
46
|
|
|
function () use ($context) { |
47
|
|
|
$this->routeLoader->addSwaggerUiUrl($context->getContextKey()); |
48
|
|
|
} |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
foreach ($context->allContexts() as $childContext) { |
53
|
|
|
$this->renderContext($childContext); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|