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, $identifier = null) |
31
|
|
|
{ |
32
|
|
|
$this->methodName = $methodName; |
33
|
|
|
$this->identifier = $identifier |
34
|
|
|
// If identifier not given => camelize methodName |
35
|
|
|
?? strtr( |
36
|
|
|
ucwords(strtr( |
37
|
|
|
$methodName, |
38
|
|
|
['_' => ' ', '/' => ' ', '.' => '_ ', '\\' => '_ '] |
39
|
|
|
)), |
40
|
|
|
[' ' => ''] |
41
|
|
|
) |
42
|
|
|
; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param string $identifier |
47
|
|
|
* |
48
|
|
|
* @return MethodDoc |
49
|
|
|
*/ |
50
|
|
|
public function setIdentifier(string $identifier) : MethodDoc |
51
|
|
|
{ |
52
|
|
|
$this->identifier = $identifier; |
53
|
|
|
|
54
|
|
|
return $this; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param TypeDoc $paramsDoc |
59
|
|
|
* |
60
|
|
|
* @return MethodDoc |
61
|
|
|
*/ |
62
|
|
|
public function setParamsDoc(TypeDoc $paramsDoc) : MethodDoc |
63
|
|
|
{ |
64
|
|
|
$this->paramsDoc = $paramsDoc; |
65
|
|
|
|
66
|
|
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param TypeDoc $resultDoc |
71
|
|
|
* |
72
|
|
|
* @return MethodDoc |
73
|
|
|
*/ |
74
|
|
|
public function setResultDoc(TypeDoc $resultDoc) : MethodDoc |
75
|
|
|
{ |
76
|
|
|
$this->resultDoc = $resultDoc; |
77
|
|
|
|
78
|
|
|
return $this; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param string $description |
83
|
|
|
* |
84
|
|
|
* @return MethodDoc |
85
|
|
|
*/ |
86
|
|
|
public function setDescription(string $description) : MethodDoc |
87
|
|
|
{ |
88
|
|
|
$this->description = $description; |
89
|
|
|
|
90
|
|
|
return $this; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param string $tag |
95
|
|
|
* |
96
|
|
|
* @return MethodDoc |
97
|
|
|
*/ |
98
|
|
|
public function addTag(string $tag) : MethodDoc |
99
|
|
|
{ |
100
|
|
|
$this->tags[] = $tag; |
101
|
|
|
|
102
|
|
|
return $this; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param ErrorDoc $customError |
107
|
|
|
* |
108
|
|
|
* @return MethodDoc |
109
|
|
|
*/ |
110
|
|
|
public function addCustomError(ErrorDoc $customError) : MethodDoc |
111
|
|
|
{ |
112
|
|
|
$this->customErrorList[] = $customError; |
113
|
|
|
|
114
|
|
|
return $this; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return string |
119
|
|
|
*/ |
120
|
|
|
public function getMethodName() : string |
121
|
|
|
{ |
122
|
|
|
return $this->methodName; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @return TypeDoc|null |
127
|
|
|
*/ |
128
|
|
|
public function getParamsDoc() |
129
|
|
|
{ |
130
|
|
|
return $this->paramsDoc; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @return TypeDoc|null |
135
|
|
|
*/ |
136
|
|
|
public function getResultDoc() |
137
|
|
|
{ |
138
|
|
|
return $this->resultDoc; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @return string |
143
|
|
|
*/ |
144
|
|
|
public function getIdentifier() |
145
|
|
|
{ |
146
|
|
|
return $this->identifier; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @return null|string |
151
|
|
|
*/ |
152
|
|
|
public function getDescription() |
153
|
|
|
{ |
154
|
|
|
return $this->description; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @return string[] |
159
|
|
|
*/ |
160
|
|
|
public function getTags() |
161
|
|
|
{ |
162
|
|
|
return $this->tags; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @return ErrorDoc[] |
167
|
|
|
*/ |
168
|
|
|
public function getCustomErrorList() |
169
|
|
|
{ |
170
|
|
|
return $this->customErrorList; |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|