1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JDesrosiers\Silex\Provider; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Annotations\AnnotationRegistry; |
6
|
|
|
use Silex\Application; |
7
|
|
|
use Silex\ServiceProviderInterface; |
8
|
|
|
use Swagger\Logger; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* The SwaggerServiceProvider adds a swagger-php service to a silex app. It also adds the routes necessary for |
12
|
|
|
* integrating with swagger-ui. |
13
|
|
|
*/ |
14
|
|
|
class SwaggerServiceProvider implements ServiceProviderInterface |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Add routes to the app that generate swagger documentation based on your annotations |
18
|
|
|
* |
19
|
|
|
* @param Application $app |
20
|
|
|
*/ |
21
|
12 |
|
public function boot(Application $app) |
22
|
|
|
{ |
23
|
12 |
|
AnnotationRegistry::registerAutoloadNamespace("Swagger\Annotations", $app["swagger.srcDir"]); |
|
|
|
|
24
|
|
|
|
25
|
12 |
|
if ($app["logger"]) { |
26
|
1 |
|
$logger = Logger::getInstance(); |
27
|
1 |
|
$originalLog = $logger->log; |
28
|
|
|
$logger->log = function ($entry, $type) use ($app, $originalLog) { |
|
|
|
|
29
|
|
|
$app["logger"]->notice($entry); |
30
|
|
|
$originalLog($entry, $type); |
31
|
|
|
}; |
32
|
|
|
} |
33
|
|
|
|
34
|
12 |
|
$app->get($app["swagger.apiDocPath"], new ResourceListController()); |
35
|
12 |
|
$app->get("{$app["swagger.apiDocPath"]}/{service}", new ResourceDefinitionController()); |
36
|
12 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Registers the swagger service |
40
|
|
|
* |
41
|
|
|
* @param Application $app |
42
|
|
|
*/ |
43
|
12 |
|
public function register(Application $app) |
44
|
|
|
{ |
45
|
12 |
|
$app["swagger.apiDocPath"] = "/api/api-docs"; |
46
|
12 |
|
$app["swagger.excludePath"] = array(); |
47
|
12 |
|
$app["swagger.prettyPrint"] = true; |
48
|
12 |
|
$app["swagger.cache"] = array(); |
49
|
12 |
|
$app["swagger.basePath"] = null; |
50
|
12 |
|
$app["swagger.apiVersion"] = null; |
51
|
12 |
|
$app["swagger.swaggerVersion"] = "1.2"; |
52
|
12 |
|
$app["swagger.resourcePrefix"] = "/"; |
53
|
12 |
|
$app["swagger.resourceSuffix"] = ""; |
54
|
|
|
|
55
|
12 |
|
$app["swagger"] = $app->share(new SwaggerService()); |
56
|
12 |
|
} |
57
|
|
|
} |
58
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.