1
|
|
|
<?php |
2
|
|
|
namespace Yoanm\JsonRpcServerDoc\Model; |
3
|
|
|
|
4
|
|
|
use Yoanm\JsonRpcServerDoc\Model\Type\TypeDoc; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class MethodDoc |
8
|
|
|
*/ |
9
|
|
|
class MethodDoc |
10
|
|
|
{ |
11
|
|
|
/** @var string */ |
12
|
|
|
private $methodName; |
13
|
|
|
/** @var string */ |
14
|
|
|
private $identifier; |
15
|
|
|
/** @var null|TypeDoc */ |
16
|
|
|
private $paramsDoc = null; |
17
|
|
|
/** @var null|TypeDoc */ |
18
|
|
|
private $resultDoc = null; |
19
|
|
|
/** @var null|string */ |
20
|
|
|
private $description = null; |
21
|
|
|
/** @var string[] */ |
22
|
|
|
private $tags = []; |
23
|
|
|
/** @var ErrorDoc[] */ |
24
|
|
|
private $customErrorList = []; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param string $methodName |
28
|
|
|
* @param string|null $identifier |
29
|
|
|
*/ |
30
|
|
|
public function __construct(string $methodName, string $identifier = null) |
31
|
|
|
{ |
32
|
|
|
$this->methodName = $methodName; |
33
|
|
|
$this->setIdentifier($identifier ?? $methodName) |
34
|
|
|
; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param string $identifier |
39
|
|
|
* |
40
|
|
|
* @return MethodDoc |
41
|
|
|
*/ |
42
|
|
|
public function setIdentifier(string $identifier) : MethodDoc |
43
|
|
|
{ |
44
|
|
|
// Sanitize Identifier => remove space and slashes |
45
|
|
|
$this->identifier = strtr( |
46
|
|
|
ucwords(strtr( |
47
|
|
|
$identifier, |
48
|
|
|
['_' => ' ', '/' => ' ', '.' => '_ ', '\\' => '_ '] |
49
|
|
|
)), |
50
|
|
|
[' ' => ''] |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
return $this; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param TypeDoc $paramsDoc |
58
|
|
|
* |
59
|
|
|
* @return MethodDoc |
60
|
|
|
*/ |
61
|
|
|
public function setParamsDoc(TypeDoc $paramsDoc) : MethodDoc |
62
|
|
|
{ |
63
|
|
|
$this->paramsDoc = $paramsDoc; |
64
|
|
|
|
65
|
|
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param TypeDoc $resultDoc |
70
|
|
|
* |
71
|
|
|
* @return MethodDoc |
72
|
|
|
*/ |
73
|
|
|
public function setResultDoc(TypeDoc $resultDoc) : MethodDoc |
74
|
|
|
{ |
75
|
|
|
$this->resultDoc = $resultDoc; |
76
|
|
|
|
77
|
|
|
return $this; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param string $description |
82
|
|
|
* |
83
|
|
|
* @return MethodDoc |
84
|
|
|
*/ |
85
|
|
|
public function setDescription(string $description) : MethodDoc |
86
|
|
|
{ |
87
|
|
|
$this->description = $description; |
88
|
|
|
|
89
|
|
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param string $tag |
94
|
|
|
* |
95
|
|
|
* @return MethodDoc |
96
|
|
|
*/ |
97
|
|
|
public function addTag(string $tag) : MethodDoc |
98
|
|
|
{ |
99
|
|
|
$this->tags[] = $tag; |
100
|
|
|
|
101
|
|
|
return $this; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param ErrorDoc $customError |
106
|
|
|
* |
107
|
|
|
* @return MethodDoc |
108
|
|
|
*/ |
109
|
|
|
public function addCustomError(ErrorDoc $customError) : MethodDoc |
110
|
|
|
{ |
111
|
|
|
$this->customErrorList[] = $customError; |
112
|
|
|
|
113
|
|
|
return $this; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return string |
118
|
|
|
*/ |
119
|
|
|
public function getMethodName() : string |
120
|
|
|
{ |
121
|
|
|
return $this->methodName; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @return TypeDoc|null |
126
|
|
|
*/ |
127
|
|
|
public function getParamsDoc() |
128
|
|
|
{ |
129
|
|
|
return $this->paramsDoc; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @return TypeDoc|null |
134
|
|
|
*/ |
135
|
|
|
public function getResultDoc() |
136
|
|
|
{ |
137
|
|
|
return $this->resultDoc; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @return string |
142
|
|
|
*/ |
143
|
|
|
public function getIdentifier() : string |
144
|
|
|
{ |
145
|
|
|
return $this->identifier; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @return null|string |
150
|
|
|
*/ |
151
|
|
|
public function getDescription() |
152
|
|
|
{ |
153
|
|
|
return $this->description; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @return string[] |
158
|
|
|
*/ |
159
|
|
|
public function getTags() : array |
160
|
|
|
{ |
161
|
|
|
return $this->tags; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @return ErrorDoc[] |
166
|
|
|
*/ |
167
|
|
|
public function getCustomErrorList() : array |
168
|
|
|
{ |
169
|
|
|
return $this->customErrorList; |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|