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