|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Basster\Silex\Provider\Swagger; |
|
4
|
|
|
|
|
5
|
|
|
use Silex\Application; |
|
6
|
|
|
use Silex\ServiceProviderInterface; |
|
7
|
|
|
use Swagger\Annotations as SWG; |
|
8
|
|
|
|
|
9
|
|
|
class SwaggerProvider implements ServiceProviderInterface, SwaggerServiceKey |
|
10
|
|
|
{ |
|
11
|
|
|
/** {@inheritdoc} */ |
|
12
|
11 |
|
public function register(Application $app) |
|
13
|
|
|
{ |
|
14
|
11 |
|
$app[self::SWAGGER_API_DOC_PATH] = '/api/api-docs'; |
|
15
|
11 |
|
$app[self::SWAGGER_EXCLUDE_PATH] = null; |
|
16
|
11 |
|
$app[self::SWAGGER_CACHE] = []; |
|
17
|
11 |
|
$app[self::SWAGGER_SERVICE_PATH] = null; |
|
18
|
11 |
|
$app[self::SWAGGER_ANALYSER] = null; |
|
19
|
11 |
|
$app[self::SWAGGER_ANALYSIS] = null; |
|
20
|
11 |
|
$app[self::SWAGGER_PROCESSORS] = []; |
|
21
|
|
|
|
|
22
|
|
|
$app[self::SWAGGER_CONFIG] = $app::share(function (Application $app) { |
|
23
|
3 |
|
return new SwaggerConfig( |
|
24
|
3 |
|
$app[self::SWAGGER_SERVICE_PATH], |
|
25
|
3 |
|
$app[self::SWAGGER_ANALYSER], |
|
26
|
3 |
|
$app[self::SWAGGER_ANALYSIS], |
|
27
|
3 |
|
$app[self::SWAGGER_PROCESSORS], |
|
28
|
3 |
|
$app[self::SWAGGER_EXCLUDE_PATH] |
|
29
|
3 |
|
); |
|
30
|
11 |
|
}); |
|
31
|
|
|
|
|
32
|
|
|
$app[self::SWAGGER_SERVICE] = $app::share(function (Application $app) { |
|
33
|
2 |
|
return new SwaggerService( |
|
34
|
2 |
|
$app[self::SWAGGER_CONFIG], |
|
35
|
2 |
|
$app[self::SWAGGER_CACHE] |
|
36
|
2 |
|
); |
|
37
|
11 |
|
}); |
|
38
|
|
|
|
|
39
|
11 |
|
$app[self::SWAGGER] = $app::share(function (Application $app) { |
|
40
|
|
|
/** @var SwaggerService $swagger */ |
|
41
|
1 |
|
$swagger = $app[self::SWAGGER_SERVICE]; |
|
42
|
1 |
|
return $swagger->getSwagger(); |
|
43
|
11 |
|
}); |
|
44
|
11 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** {@inheritdoc} */ |
|
47
|
1 |
|
public function boot(Application $app) |
|
48
|
|
|
{ |
|
49
|
1 |
|
$app->get( |
|
50
|
1 |
|
$app[self::SWAGGER_API_DOC_PATH], |
|
51
|
1 |
|
[$app[self::SWAGGER_SERVICE], 'getSwaggerResponse'] |
|
52
|
1 |
|
); |
|
53
|
1 |
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|