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