1 | <?php declare(strict_types=1); |
||
31 | class APIRequestBuilder { |
||
32 | use LoggerAwareTrait; |
||
33 | |||
34 | /** |
||
35 | * Url prefix for making url requests |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $baseUrl = ''; |
||
39 | |||
40 | /** |
||
41 | * Url path of the request |
||
42 | * @var string |
||
43 | */ |
||
44 | protected $path = ''; |
||
45 | |||
46 | /** |
||
47 | * Query string for the request |
||
48 | * @var string |
||
49 | */ |
||
50 | protected $query = ''; |
||
51 | |||
52 | /** |
||
53 | * Default request headers |
||
54 | * @var array |
||
55 | */ |
||
56 | protected $defaultHeaders = []; |
||
57 | |||
58 | /** |
||
59 | * Valid HTTP request methos |
||
60 | * @var array |
||
61 | */ |
||
62 | protected $validMethods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS']; |
||
63 | |||
64 | /** |
||
65 | * The current request |
||
66 | * @var \Amp\Promise |
||
67 | */ |
||
68 | protected $request; |
||
69 | |||
70 | /** |
||
71 | * Set body as form fields |
||
72 | * |
||
73 | * @param array $fields Mapping of field names to values |
||
74 | * @return self |
||
75 | */ |
||
76 | public function setFormFields(array $fields): self |
||
82 | |||
83 | /** |
||
84 | * Set the request body |
||
85 | * |
||
86 | * @param FormBody|string $body |
||
87 | * @return self |
||
88 | */ |
||
89 | public function setBody($body): self |
||
94 | |||
95 | /** |
||
96 | * Set a request header |
||
97 | * |
||
98 | * @param string $name |
||
99 | * @param string $value |
||
100 | * @return self |
||
101 | */ |
||
102 | public function setHeader(string $name, string $value): self |
||
107 | |||
108 | /** |
||
109 | * Set multiple request headers |
||
110 | * |
||
111 | * name => value |
||
112 | * |
||
113 | * @param array $headers |
||
114 | * @return self |
||
115 | */ |
||
116 | public function setHeaders(array $headers): self |
||
125 | |||
126 | /** |
||
127 | * Append a query string in array format |
||
128 | * |
||
129 | * @param array $params |
||
130 | * @return self |
||
131 | */ |
||
132 | public function setQuery(array $params): self |
||
137 | |||
138 | /** |
||
139 | * Return the promise for the current request |
||
140 | * |
||
141 | * @return \Amp\Promise |
||
142 | */ |
||
143 | public function getFullRequest() |
||
148 | |||
149 | /** |
||
150 | * Create a new http request |
||
151 | * |
||
152 | * @param string $type |
||
153 | * @param string $uri |
||
154 | * @return self |
||
155 | */ |
||
156 | public function newRequest(string $type, string $uri): self |
||
171 | |||
172 | /** |
||
173 | * Create the full request url |
||
174 | * |
||
175 | * @return void |
||
176 | */ |
||
177 | private function buildUri() |
||
190 | |||
191 | /** |
||
192 | * Unencode the dual-encoded ampersands in the body |
||
193 | * |
||
194 | * This is a dirty hack until I can fully track down where |
||
195 | * the dual-encoding happens |
||
196 | * |
||
197 | * @param FormBody $formBody The form builder object to fix |
||
198 | * @return string |
||
199 | */ |
||
200 | private function fixBody(FormBody $formBody): string |
||
205 | |||
206 | /** |
||
207 | * Reset the class state for a new request |
||
208 | * |
||
209 | * @return void |
||
210 | */ |
||
211 | private function resetState() |
||
217 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.