-
Notifications
You must be signed in to change notification settings - Fork 1
/
SwaggerDoc.hooks.php
49 lines (43 loc) · 1.25 KB
/
SwaggerDoc.hooks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
* Hooks for SwaggerDoc extension
*
* @file
* @ingroup Extensions
*/
class SwaggerDocHooks
{
public static function onParserSetup(Parser $parser)
{
$parser->setHook('SwaggerDoc', 'SwaggerDocHooks::processSwaggerDocTag');
return true;
}
public static function processSwaggerDocTag($input, array $args, Parser $parser, PPFrame $frame)
{
// Parse arg for single URL spec
if (isset($args['specurl']))
$specUrl = $args['specurl'];
elseif (isset($args['specUrl']))
$specUrl = $args['specUrl'];
else
$specUrl = '';
// Parse arg for multiple URLs spec
if (isset($args['specurls']))
$specUrls = str_replace("'", '"', $args['specurls']);
elseif (isset($args['specUrls']))
$specUrls = str_replace("'", '"', $args['specUrls']);
else
$specUrls = '';
$parser->getOutput()->addModules(['ext.SwaggerDoc.init']);
// Add div which will be processed on frontend
$outHtml = '<div';
$outHtml = $outHtml . ' class="swagger-iframe-container" ';
$outHtml = $outHtml . ' id="swagger-ui-doc-container" ';
if ($specUrl !== "")
$outHtml = $outHtml . ' dataUrl=\'' . $specUrl . '\' ';
if ($specUrls !== "")
$outHtml = $outHtml . ' dataUrls=\'' . $specUrls . '\' ';
$outHtml = $outHtml . ' ></div>';
return $outHtml;
}
}