1 | <?php |
||
24 | final class DefaultServiceMethodBuilder implements ServiceMethodBuilder |
||
25 | { |
||
26 | /** |
||
27 | * The request method |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | private $method; |
||
32 | |||
33 | /** |
||
34 | * The request base url |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | private $baseUrl; |
||
39 | |||
40 | /** |
||
41 | * The request path |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | private $path; |
||
46 | |||
47 | /** |
||
48 | * True if the request has a body |
||
49 | * |
||
50 | * @var bool |
||
51 | */ |
||
52 | private $hasBody; |
||
53 | |||
54 | /** |
||
55 | * The request body content type |
||
56 | * |
||
57 | * @var string |
||
58 | */ |
||
59 | private $contentType; |
||
60 | |||
61 | /** |
||
62 | * Array of headers |
||
63 | * |
||
64 | * @var array |
||
65 | */ |
||
66 | private $headers = []; |
||
67 | |||
68 | /** |
||
69 | * Array of Parameter handlers, indexed to match the position of the parameters |
||
70 | * |
||
71 | * @var ParameterHandler[] |
||
72 | */ |
||
73 | private $parameterHandlers = []; |
||
74 | |||
75 | /** |
||
76 | * Converts successful response bodies to expected value |
||
77 | * |
||
78 | * @var ResponseBodyConverter |
||
79 | */ |
||
80 | private $responseBodyConverter; |
||
81 | |||
82 | /** |
||
83 | * Converts error response bodies to expected value |
||
84 | * |
||
85 | * @var ResponseBodyConverter |
||
86 | */ |
||
87 | private $errorBodyConverter; |
||
88 | |||
89 | /** |
||
90 | * Adapts a [@see Call] to expected value |
||
91 | * |
||
92 | * @var CallAdapter |
||
93 | */ |
||
94 | private $callAdapter; |
||
95 | |||
96 | /** |
||
97 | * Set the request method (e.g. GET, POST) |
||
98 | * |
||
99 | * @param string $method |
||
100 | * @return ServiceMethodBuilder |
||
101 | * @throws \LogicException |
||
102 | */ |
||
103 | 33 | public function setMethod(string $method): ServiceMethodBuilder |
|
117 | |||
118 | /** |
||
119 | * Set the request base url (e.g. http://example.com) |
||
120 | * |
||
121 | * @param string $baseUrl |
||
122 | * @return ServiceMethodBuilder |
||
123 | */ |
||
124 | 29 | public function setBaseUrl(string $baseUrl): ServiceMethodBuilder |
|
130 | |||
131 | /** |
||
132 | * Set the request path |
||
133 | * |
||
134 | * @param string $path |
||
135 | * @return ServiceMethodBuilder |
||
136 | */ |
||
137 | 30 | public function setPath(string $path): ServiceMethodBuilder |
|
143 | |||
144 | /** |
||
145 | * Set to true if an annotation exists that denotes a request body. This should also set |
||
146 | * the request content type. |
||
147 | * |
||
148 | * @param bool $hasBody |
||
149 | * @return ServiceMethodBuilder |
||
150 | * @throws \LogicException |
||
151 | */ |
||
152 | 34 | public function setHasBody(bool $hasBody): ServiceMethodBuilder |
|
166 | |||
167 | /** |
||
168 | * Set the content type of the request. A content type should not be set if there |
||
169 | * isn't a request body. |
||
170 | * |
||
171 | * @param string $contentType |
||
172 | * @return ServiceMethodBuilder |
||
173 | * @throws \LogicException |
||
174 | */ |
||
175 | 19 | public function setContentType(string $contentType): ServiceMethodBuilder |
|
189 | |||
190 | /** |
||
191 | * Convenience method to declare that the request has content and is json |
||
192 | * |
||
193 | * @return ServiceMethodBuilder |
||
194 | * @throws \LogicException |
||
195 | */ |
||
196 | 10 | public function setIsJson(): ServiceMethodBuilder |
|
203 | |||
204 | |||
205 | /** |
||
206 | * Convenience method to declare that the request has content and is form encoded |
||
207 | * |
||
208 | * @return ServiceMethodBuilder |
||
209 | * @throws \LogicException |
||
210 | */ |
||
211 | 5 | public function setIsFormUrlEncoded(): ServiceMethodBuilder |
|
218 | |||
219 | /** |
||
220 | * Convenience method to declare that the request has content and is multipart |
||
221 | * |
||
222 | * @return ServiceMethodBuilder |
||
223 | * @throws \LogicException |
||
224 | */ |
||
225 | 4 | public function setIsMultipart(): ServiceMethodBuilder |
|
232 | |||
233 | /** |
||
234 | * Add a request header. Header name should be normalized. |
||
235 | * |
||
236 | * @param string $name |
||
237 | * @param string $header |
||
238 | * @return ServiceMethodBuilder |
||
239 | */ |
||
240 | 11 | public function addHeader(string $name, string $header): ServiceMethodBuilder |
|
246 | |||
247 | /** |
||
248 | * Add a [@see ParameterHandler] at the position the parameter exists |
||
249 | * |
||
250 | * @param int $index |
||
251 | * @param ParameterHandler $parameterHandler |
||
252 | * @return ServiceMethodBuilder |
||
253 | */ |
||
254 | 25 | public function addParameterHandler(int $index, ParameterHandler $parameterHandler): ServiceMethodBuilder |
|
260 | |||
261 | /** |
||
262 | * Set the [@see CallAdapter] |
||
263 | * |
||
264 | * @param CallAdapter $callAdapter |
||
265 | * @return ServiceMethodBuilder |
||
266 | */ |
||
267 | 23 | public function setCallAdapter(CallAdapter $callAdapter): ServiceMethodBuilder |
|
273 | |||
274 | /** |
||
275 | * Set the response body converter to convert successful responses |
||
276 | * |
||
277 | * @param ResponseBodyConverter $responseBodyConverter |
||
278 | * @return ServiceMethodBuilder |
||
279 | */ |
||
280 | 24 | public function setResponseBodyConverter(ResponseBodyConverter $responseBodyConverter): ServiceMethodBuilder |
|
286 | |||
287 | /** |
||
288 | * Set the response body converter to convert error responses |
||
289 | * |
||
290 | * @param ResponseBodyConverter $errorBodyConverter |
||
291 | * @return ServiceMethodBuilder |
||
292 | */ |
||
293 | 23 | public function setErrorBodyConverter(ResponseBodyConverter $errorBodyConverter): ServiceMethodBuilder |
|
299 | |||
300 | /** |
||
301 | * Create a new [@see DefaultServiceMethod] from previously set parameters |
||
302 | * |
||
303 | * @return DefaultServiceMethod |
||
304 | * @throws \LogicException |
||
305 | */ |
||
306 | 30 | public function build(): DefaultServiceMethod |
|
380 | } |
||
381 |