1
|
|
|
<?php |
2
|
|
|
namespace Yoanm\JsonRpcServerDoc\Normalizer; |
3
|
|
|
|
4
|
|
|
use Yoanm\JsonRpcServerDoc\Model\ServerDoc; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class ServerDocNormalizer |
8
|
|
|
*/ |
9
|
|
|
class ServerDocNormalizer |
10
|
|
|
{ |
11
|
|
|
/** @var MethodDocNormalizer */ |
12
|
|
|
private $methodDocNormalizer; |
13
|
|
|
/** @var TagDocNormalizer */ |
14
|
|
|
private $tagDocNormalizer; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @param MethodDocNormalizer $methodDocNormalizer |
18
|
|
|
* @param TagDocNormalizer $tagDocNormalizer |
19
|
|
|
*/ |
20
|
|
|
public function __construct(MethodDocNormalizer $methodDocNormalizer, TagDocNormalizer $tagDocNormalizer) |
21
|
|
|
{ |
22
|
|
|
$this->methodDocNormalizer = $methodDocNormalizer; |
23
|
|
|
$this->tagDocNormalizer = $tagDocNormalizer; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param ServerDoc $doc |
28
|
|
|
* |
29
|
|
|
* @return array |
30
|
|
|
*/ |
31
|
|
|
public function normalize(ServerDoc $doc) |
32
|
|
|
{ |
33
|
|
|
$rawInfo = $methodsDoc = $tagsDoc = []; |
34
|
|
|
if (null !== $doc->getName()) { |
35
|
|
|
$rawInfo['info']['title'] = $doc->getName(); |
36
|
|
|
} |
37
|
|
|
if (null !== $doc->getVersion()) { |
38
|
|
|
$rawInfo['info']['version'] = $doc->getVersion(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$methodDocList = array_map([$this->methodDocNormalizer, 'normalize'], $doc->getMethodList()); |
42
|
|
|
$tagDocList = array_map([$this->tagDocNormalizer, 'normalize'], $doc->getTagList()); |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
if (count($methodDocList)) { |
46
|
|
|
$methodsDoc['methods'] = $methodDocList; |
47
|
|
|
} |
48
|
|
|
if (count($tagDocList)) { |
49
|
|
|
$tagsDoc['tags'] = $tagDocList; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return $rawInfo |
53
|
|
|
+ $tagsDoc |
54
|
|
|
+ $methodsDoc; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|