|
1
|
|
|
<?php namespace Comodojo\RpcServer\Request; |
|
2
|
|
|
|
|
3
|
|
|
use \Comodojo\RpcServer\Component\Capabilities; |
|
4
|
|
|
use \Comodojo\RpcServer\Component\Methods; |
|
5
|
|
|
use \Comodojo\RpcServer\Component\Errors; |
|
6
|
|
|
use \Psr\Log\LoggerInterface; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* The parameters object |
|
10
|
|
|
* |
|
11
|
|
|
* It provides to each RPC method a way to access: |
|
12
|
|
|
* - Provided parameters |
|
13
|
|
|
* - Supported capabilities |
|
14
|
|
|
* - Implemented methods |
|
15
|
|
|
* - Predefined errors |
|
16
|
|
|
* - Current RPC protocol |
|
17
|
|
|
* - Current logger |
|
18
|
|
|
* |
|
19
|
|
|
* The parameter object is the only one parameter passed to a RPC method's implementation |
|
20
|
|
|
* |
|
21
|
|
|
* @package Comodojo Spare Parts |
|
22
|
|
|
* @author Marco Giovinazzi <[email protected]> |
|
23
|
|
|
* @license MIT |
|
24
|
|
|
* |
|
25
|
|
|
* LICENSE: |
|
26
|
|
|
* |
|
27
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
28
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
29
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
30
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
31
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
32
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
33
|
|
|
* THE SOFTWARE. |
|
34
|
|
|
*/ |
|
35
|
|
|
|
|
36
|
|
|
class Parameters { |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Array of provided parameters |
|
40
|
|
|
* |
|
41
|
|
|
* @var array |
|
42
|
|
|
*/ |
|
43
|
|
|
private $parameters = []; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Supported capabilities |
|
47
|
|
|
* |
|
48
|
|
|
* @var Capabilities |
|
49
|
|
|
*/ |
|
50
|
|
|
private $capabilities; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Implemented methods |
|
54
|
|
|
* |
|
55
|
|
|
* @var Methods |
|
56
|
|
|
*/ |
|
57
|
|
|
private $methods; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Predefined errors |
|
61
|
|
|
* |
|
62
|
|
|
* @var Errors |
|
63
|
|
|
*/ |
|
64
|
|
|
private $errors; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Current RPC protocol (json|rpc) |
|
68
|
|
|
* |
|
69
|
|
|
* @var string |
|
70
|
|
|
*/ |
|
71
|
|
|
private $protocol; |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Current logger |
|
75
|
|
|
* |
|
76
|
|
|
* @var LoggerInterface |
|
77
|
|
|
*/ |
|
78
|
|
|
private $logger; |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Class constructor |
|
82
|
|
|
* |
|
83
|
|
|
* @param Capabilities $capabilities |
|
84
|
|
|
* @param Methods $methods |
|
85
|
|
|
* @param Errors $errors |
|
86
|
|
|
* @param LoggerInterface $logger |
|
87
|
|
|
* @param string $protocol |
|
88
|
|
|
*/ |
|
89
|
84 |
|
public function __construct( |
|
90
|
|
|
Capabilities $capabilities, |
|
91
|
|
|
Methods $methods, |
|
92
|
|
|
Errors $errors, |
|
93
|
|
|
LoggerInterface $logger, |
|
94
|
|
|
$protocol |
|
95
|
|
|
) { |
|
96
|
|
|
|
|
97
|
84 |
|
$this->capabilities = $capabilities; |
|
98
|
|
|
|
|
99
|
84 |
|
$this->methods = $methods; |
|
100
|
|
|
|
|
101
|
84 |
|
$this->errors = $errors; |
|
102
|
|
|
|
|
103
|
84 |
|
$this->logger = $logger; |
|
104
|
|
|
|
|
105
|
84 |
|
$this->protocol = $protocol; |
|
106
|
|
|
|
|
107
|
84 |
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Set provided parameters |
|
111
|
|
|
* |
|
112
|
|
|
* @param array $parameters |
|
113
|
|
|
* |
|
114
|
|
|
* @return Parameters |
|
115
|
|
|
*/ |
|
116
|
78 |
|
final public function setParameters(array $parameters = []) { |
|
117
|
|
|
|
|
118
|
78 |
|
$this->parameters = $parameters; |
|
119
|
|
|
|
|
120
|
78 |
|
return $this; |
|
121
|
|
|
|
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Get capabilities object |
|
126
|
|
|
* |
|
127
|
|
|
* @deprecated |
|
128
|
|
|
* @see Parameters::getCapabilities() |
|
129
|
|
|
* @return Capabilities |
|
130
|
|
|
*/ |
|
131
|
21 |
|
public function capabilities() { |
|
132
|
|
|
|
|
133
|
21 |
|
return $this->getCapabilities(); |
|
|
|
|
|
|
134
|
|
|
|
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Get capabilities object |
|
139
|
|
|
* |
|
140
|
|
|
* @deprecated |
|
141
|
|
|
* @see Parameters::getCapabilities() |
|
142
|
|
|
* @return Capabilities |
|
143
|
|
|
*/ |
|
144
|
21 |
|
public function getCapabilities() { |
|
145
|
|
|
|
|
146
|
21 |
|
return $this->capabilities; |
|
147
|
|
|
|
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* Get methods object |
|
152
|
|
|
* |
|
153
|
|
|
* @deprecated |
|
154
|
|
|
* @see Parameters::getMethods() |
|
155
|
|
|
* @return Methods |
|
156
|
|
|
*/ |
|
157
|
84 |
|
public function methods() { |
|
158
|
|
|
|
|
159
|
84 |
|
return $this->getMethods(); |
|
160
|
|
|
|
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Get methods object |
|
165
|
|
|
* |
|
166
|
|
|
* @return Methods |
|
167
|
|
|
*/ |
|
168
|
84 |
|
public function getMethods() { |
|
169
|
|
|
|
|
170
|
84 |
|
return $this->methods; |
|
171
|
|
|
|
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* Get errors object |
|
176
|
|
|
* |
|
177
|
|
|
* @deprecated |
|
178
|
|
|
* @see Parameters::getErrors() |
|
179
|
|
|
* @return Errors |
|
180
|
|
|
*/ |
|
181
|
15 |
|
public function errors() { |
|
182
|
|
|
|
|
183
|
15 |
|
return $this->getErrors(); |
|
184
|
|
|
|
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* Get errors object |
|
189
|
|
|
* |
|
190
|
|
|
* @return Errors |
|
191
|
|
|
*/ |
|
192
|
15 |
|
public function getErrors() { |
|
193
|
|
|
|
|
194
|
15 |
|
return $this->errors; |
|
195
|
|
|
|
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* Get current RPC protocol |
|
200
|
|
|
* |
|
201
|
|
|
* @deprecated |
|
202
|
|
|
* @see Parameters::getProtocol() |
|
203
|
|
|
* @return string |
|
204
|
|
|
*/ |
|
205
|
9 |
|
public function protocol() { |
|
206
|
|
|
|
|
207
|
9 |
|
return $this->getProtocol(); |
|
208
|
|
|
|
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* Get current RPC protocol |
|
213
|
|
|
* |
|
214
|
|
|
* @return string |
|
215
|
|
|
*/ |
|
216
|
9 |
|
public function getProtocol() { |
|
217
|
|
|
|
|
218
|
9 |
|
return $this->protocol; |
|
219
|
|
|
|
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* Get current logger instance |
|
224
|
|
|
* |
|
225
|
|
|
* @deprecated |
|
226
|
|
|
* @see Parameters::getLogger() |
|
227
|
|
|
* @return LoggerInterface |
|
228
|
|
|
*/ |
|
229
|
6 |
|
public function logger() { |
|
230
|
|
|
|
|
231
|
6 |
|
return $this->getLogger(); |
|
232
|
|
|
|
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
/** |
|
236
|
|
|
* Get current logger instance |
|
237
|
|
|
* |
|
238
|
|
|
* @return LoggerInterface |
|
239
|
|
|
*/ |
|
240
|
6 |
|
public function getLogger() { |
|
241
|
|
|
|
|
242
|
6 |
|
return $this->logger; |
|
243
|
|
|
|
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
/** |
|
247
|
|
|
* Get parameter(s) |
|
248
|
|
|
* |
|
249
|
|
|
* @param string $parameter (optional) The parameter name (null will return whole array of parameters) |
|
250
|
|
|
* |
|
251
|
|
|
* @return mixed |
|
252
|
|
|
*/ |
|
253
|
48 |
|
public function get($parameter = null) { |
|
254
|
|
|
|
|
255
|
48 |
|
if ( empty($parameter) ) { |
|
256
|
|
|
|
|
257
|
|
|
$return = $this->parameters; |
|
258
|
|
|
|
|
259
|
48 |
|
} else if ( array_key_exists($parameter, $this->parameters) ) { |
|
260
|
|
|
|
|
261
|
48 |
|
$return = $this->parameters[$parameter]; |
|
262
|
|
|
|
|
263
|
16 |
|
} else { |
|
264
|
|
|
|
|
265
|
3 |
|
$return = null; |
|
266
|
|
|
|
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
48 |
|
return $return; |
|
270
|
|
|
|
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
|
|
} |
|
274
|
|
|
|