|
1
|
|
|
<?php |
|
2
|
|
|
namespace W2w\Laravel\Apie\Services; |
|
3
|
|
|
|
|
4
|
|
|
use Closure; |
|
5
|
|
|
use W2w\Laravel\Apie\Controllers\SwaggerUiController; |
|
6
|
|
|
use W2w\Lib\Apie\Controllers\DeleteController; |
|
7
|
|
|
use W2w\Lib\Apie\Controllers\DocsController; |
|
8
|
|
|
use W2w\Lib\Apie\Controllers\DocsYamlController; |
|
9
|
|
|
use W2w\Lib\Apie\Controllers\GetAllController; |
|
10
|
|
|
use W2w\Lib\Apie\Controllers\GetController; |
|
11
|
|
|
use W2w\Lib\Apie\Controllers\PostController; |
|
12
|
|
|
use W2w\Lib\Apie\Controllers\PutController; |
|
13
|
|
|
|
|
14
|
|
|
class LumenRouteLoader implements RouteLoaderInterface |
|
15
|
|
|
{ |
|
16
|
|
|
public function addDocUrl(array $context) |
|
17
|
|
|
{ |
|
18
|
|
|
if (empty($context)) { |
|
19
|
|
|
$contextString = ''; |
|
20
|
|
|
} else { |
|
21
|
|
|
$contextString = implode('.', $context) . '.'; |
|
22
|
|
|
} |
|
23
|
|
|
$router = app('router'); |
|
24
|
|
|
$router->get('/doc.json', ['as' => 'apie.' . $contextString . 'docs', 'uses' => DocsController::class]); |
|
25
|
|
|
$router->get('/doc.yml', ['as' => 'apie.' . $contextString . 'docsyaml', 'uses' => DocsYamlController::class]); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function addResourceUrl(array $context) |
|
29
|
|
|
{ |
|
30
|
|
|
if (empty($context)) { |
|
31
|
|
|
$contextString = ''; |
|
32
|
|
|
} else { |
|
33
|
|
|
$contextString = implode('.', $context) . '.'; |
|
34
|
|
|
} |
|
35
|
|
|
$router = app('router'); |
|
36
|
|
|
$router->post('/{resource}/', ['as' => 'apie.' . $contextString . 'post', 'uses' => PostController::class]); |
|
37
|
|
|
$router->put('/{resource}/{id}', ['as' => 'apie.' . $contextString . 'put', 'uses' => PutController::class]); |
|
38
|
|
|
$router->get('/{resource}/', ['as' => 'apie.' . $contextString . 'all', 'uses' => GetAllController::class]); |
|
39
|
|
|
$router->get('/{resource}/{id}', ['as' => 'apie.' . $contextString . 'get', 'uses' => GetController::class]); |
|
40
|
|
|
$router->delete('/{resource}/{id}', ['as' => 'apie.' . $contextString . 'delete', 'uses' => DeleteController::class]); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function addSwaggerUiUrl(array $context) |
|
44
|
|
|
{ |
|
45
|
|
|
if (empty($context)) { |
|
46
|
|
|
$contextString = ''; |
|
47
|
|
|
} else { |
|
48
|
|
|
$contextString = implode('.', $context) . '.'; |
|
49
|
|
|
} |
|
50
|
|
|
$router = app('router'); |
|
51
|
|
|
$router->get( |
|
52
|
|
|
'', |
|
53
|
|
|
[ |
|
54
|
|
|
'as' => 'apie.' . $contextString . 'swagger-ui', |
|
55
|
|
|
'uses' => SwaggerUiController::class |
|
56
|
|
|
] |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function context(array $context, string $prefix, array $middleware, Closure $closure) |
|
61
|
|
|
{ |
|
62
|
|
|
$router = app('router'); |
|
63
|
|
|
$router->group( |
|
64
|
|
|
['parameters' => ['context' => $context], 'prefix' => $prefix, 'middleware' => $middleware], |
|
65
|
|
|
function () use ($closure) { |
|
66
|
|
|
$closure(); |
|
67
|
|
|
} |
|
68
|
|
|
); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|