1 | <?php |
||
4 | class Util |
||
5 | { |
||
6 | public static function trim($str) |
||
14 | |||
15 | 8 | public static function getHeaderParams($headers, $otherParams = array()) |
|
16 | { |
||
17 | 8 | $params = []; |
|
18 | 8 | $otherParams = array_map('strtolower', $otherParams); |
|
19 | 8 | foreach ($headers as $header => $value) { |
|
20 | 8 | $header = strtolower($header); |
|
21 | 8 | if (strpos($header, 'x-upyun-') !== false) { |
|
22 | 2 | $params[$header] = $value[0]; |
|
23 | 8 | } else if (in_array($header, $otherParams)) { |
|
24 | $params[$header] = $value[0]; |
||
25 | } |
||
26 | 8 | } |
|
27 | 8 | return $params; |
|
28 | } |
||
29 | |||
30 | public static function parseDir($body) |
||
31 | { |
||
32 | $files = array(); |
||
33 | if (!$body) { |
||
34 | return array(); |
||
35 | } |
||
36 | |||
37 | $lines = explode("\n", $body); |
||
38 | foreach ($lines as $line) { |
||
39 | $file = []; |
||
40 | list($file['name'], $file['type'], $file['size'], $file['time']) = explode("\t", $line, 4); |
||
41 | $files[] = $file; |
||
42 | } |
||
43 | |||
44 | return $files; |
||
45 | } |
||
46 | |||
47 | 2 | public static function base64Json($params) |
|
51 | |||
52 | public static function stringifyHeaders($headers) |
||
60 | |||
61 | public static function md5Hash($resource) |
||
69 | |||
70 | /** |
||
71 | * GuzzleHttp\Psr\Uri use `parse_url`,not good for utf-8, |
||
72 | * So should `encodeURI` first, before `new Psr7\Request` |
||
73 | * @see http://stackoverflow.com/questions/4929584/encodeuri-in-php |
||
74 | */ |
||
75 | 13 | public static function encodeURI($url) |
|
90 | } |
||
91 |