|
11 | 11 | use InvalidArgumentException, TypeError; |
12 | 12 | use Psr\Http\Message\{MessageInterface, RequestInterface, ResponseInterface, UploadedFileInterface, UriInterface}; |
13 | 13 |
|
14 | | -use function array_combine, array_filter, array_keys, array_map, array_merge, array_values, call_user_func_array, count, explode, |
15 | | - gzdecode, gzinflate, gzuncompress, implode, is_array, is_bool, is_iterable, is_numeric, is_scalar, is_string, |
16 | | - json_decode, json_encode, parse_str, parse_url, rawurldecode, rawurlencode, simplexml_load_string, sort, strtolower, trim, |
17 | | - ucfirst, uksort; |
18 | | - |
19 | | -use const PHP_URL_QUERY, SORT_STRING; |
| 14 | +use function array_filter, array_keys, array_map, array_values, count, explode, |
| 15 | + gzdecode, gzinflate, gzuncompress, implode, is_array, is_numeric, is_scalar, is_string, |
| 16 | + json_decode, json_encode, rawurldecode, rawurlencode, simplexml_load_string, strtolower, trim, |
| 17 | + ucfirst; |
20 | 18 |
|
21 | 19 | const PSR7_INCLUDES = true; |
22 | 20 |
|
@@ -215,129 +213,6 @@ function r_rawurlencode($data){ |
215 | 213 | return rawurlencode((string)$data); |
216 | 214 | } |
217 | 215 |
|
218 | | -/** |
219 | | - * from https://github.com/abraham/twitteroauth/blob/master/src/Util.php |
220 | | - */ |
221 | | -function build_http_query(array $params, bool $urlencode = null, string $delimiter = null, string $enclosure = null):string{ |
222 | | - |
223 | | - if(empty($params)){ |
224 | | - return ''; |
225 | | - } |
226 | | - |
227 | | - // urlencode both keys and values |
228 | | - if($urlencode ?? true){ |
229 | | - $params = array_combine( |
230 | | - r_rawurlencode(array_keys($params)), |
231 | | - r_rawurlencode(array_values($params)) |
232 | | - ); |
233 | | - } |
234 | | - |
235 | | - // Parameters are sorted by name, using lexicographical byte value ordering. |
236 | | - // Ref: Spec: 9.1.1 (1) |
237 | | - uksort($params, 'strcmp'); |
238 | | - |
239 | | - $pairs = []; |
240 | | - $enclosure = $enclosure ?? ''; |
241 | | - |
242 | | - foreach($params as $parameter => $value){ |
243 | | - |
244 | | - if(is_array($value)){ |
245 | | - // If two or more parameters share the same name, they are sorted by their value |
246 | | - // Ref: Spec: 9.1.1 (1) |
247 | | - // June 12th, 2010 - changed to sort because of issue 164 by hidetaka |
248 | | - sort($value, SORT_STRING); |
249 | | - |
250 | | - foreach($value as $duplicateValue){ |
251 | | - $pairs[] = $parameter.'='.$enclosure.$duplicateValue.$enclosure; |
252 | | - } |
253 | | - |
254 | | - } |
255 | | - else{ |
256 | | - $pairs[] = $parameter.'='.$enclosure.$value.$enclosure; |
257 | | - } |
258 | | - |
259 | | - } |
260 | | - |
261 | | - // For each parameter, the name is separated from the corresponding value by an '=' character (ASCII code 61) |
262 | | - // Each name-value pair is separated by an '&' character (ASCII code 38) |
263 | | - return implode($delimiter ?? '&', $pairs); |
264 | | -} |
265 | | - |
266 | | -const BOOLEANS_AS_BOOL = 0; |
267 | | -const BOOLEANS_AS_INT = 1; |
268 | | -const BOOLEANS_AS_STRING = 2; |
269 | | -const BOOLEANS_AS_INT_STRING = 3; |
270 | | - |
271 | | -/** |
272 | | - * @param iterable $params |
273 | | - * @param int|null $bool_cast converts booleans to a type determined like following: |
274 | | - * BOOLEANS_AS_BOOL : unchanged boolean value (default) |
275 | | - * BOOLEANS_AS_INT : integer values 0 or 1 |
276 | | - * BOOLEANS_AS_STRING : "true"/"false" strings |
277 | | - * BOOLEANS_AS_INT_STRING: "0"/"1" |
278 | | - * |
279 | | - * @param bool|null $remove_empty remove empty and NULL values |
280 | | - * |
281 | | - * @return array |
282 | | - */ |
283 | | -function clean_query_params(iterable $params, int $bool_cast = null, bool $remove_empty = null):array{ |
284 | | - $p = []; |
285 | | - $bool_cast = $bool_cast ?? BOOLEANS_AS_BOOL; |
286 | | - $remove_empty = $remove_empty ?? true; |
287 | | - |
288 | | - foreach($params as $key => $value){ |
289 | | - |
290 | | - if(is_bool($value)){ |
291 | | - |
292 | | - if($bool_cast === BOOLEANS_AS_BOOL){ |
293 | | - $p[$key] = $value; |
294 | | - } |
295 | | - elseif($bool_cast === BOOLEANS_AS_INT){ |
296 | | - $p[$key] = (int)$value; |
297 | | - } |
298 | | - elseif($bool_cast === BOOLEANS_AS_STRING){ |
299 | | - $p[$key] = $value ? 'true' : 'false'; |
300 | | - } |
301 | | - elseif($bool_cast === BOOLEANS_AS_INT_STRING){ |
302 | | - $p[$key] = (string)(int)$value; |
303 | | - } |
304 | | - |
305 | | - } |
306 | | - elseif(is_iterable($value)){ |
307 | | - $p[$key] = call_user_func_array(__FUNCTION__, [$value, $bool_cast, $remove_empty]); |
308 | | - } |
309 | | - elseif($remove_empty === true && ($value === null || (!is_numeric($value) && empty($value)))){ |
310 | | - continue; |
311 | | - } |
312 | | - else{ |
313 | | - $p[$key] = $value; |
314 | | - } |
315 | | - } |
316 | | - |
317 | | - return $p; |
318 | | -} |
319 | | - |
320 | | -/** |
321 | | - * merges additional query parameters into an existing query string |
322 | | - * |
323 | | - * @param string $uri |
324 | | - * @param array $query |
325 | | - * |
326 | | - * @return string |
327 | | - */ |
328 | | -function merge_query(string $uri, array $query):string{ |
329 | | - parse_str(parse_url($uri, PHP_URL_QUERY), $parsedquery); |
330 | | - |
331 | | - $requestURI = explode('?', $uri)[0]; |
332 | | - $params = array_merge($parsedquery, $query); |
333 | | - |
334 | | - if(!empty($params)){ |
335 | | - $requestURI .= '?'.build_http_query($params); |
336 | | - } |
337 | | - |
338 | | - return $requestURI; |
339 | | -} |
340 | | - |
341 | 216 | /** |
342 | 217 | * Return an UploadedFile instance array. |
343 | 218 | * |
|
0 commit comments