1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sulao\Flysystem\BaiduBos; |
4
|
|
|
|
5
|
|
|
use League\Flysystem\Config; |
6
|
|
|
use League\Flysystem\Util; |
7
|
|
|
|
8
|
|
|
trait UtilTrait |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @param string $directory |
12
|
|
|
* @param false $recursive |
13
|
|
|
* |
14
|
|
|
* @return array |
15
|
|
|
*/ |
16
|
|
|
public function buildListDirOptions($directory = '', $recursive = false) |
17
|
|
|
{ |
18
|
|
|
$options = []; |
19
|
|
|
|
20
|
|
|
if (!$recursive) { |
|
|
|
|
21
|
|
|
$options['query']['delimiter'] = '/'; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
$directory = trim($directory, '/'); |
25
|
|
|
if ($directory !== '') { |
26
|
|
|
$directory .= '/'; |
27
|
|
|
$options['query']['prefix'] = $directory; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
return $options; |
31
|
|
|
} |
32
|
|
|
/** |
33
|
|
|
* Extract options from config |
34
|
|
|
* |
35
|
|
|
* @param Config $config |
36
|
|
|
* |
37
|
|
|
* @return array |
38
|
|
|
*/ |
39
|
|
|
protected function extractOptions(Config $config) |
40
|
|
|
{ |
41
|
|
|
$options = []; |
42
|
|
|
|
43
|
|
|
foreach (['headers', 'query', 'body', 'request', 'authorize'] as $key) { |
44
|
|
|
if ($config->has($key)) { |
45
|
|
|
$options[$key] = $config->get($key); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return $options; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Normalize the object meta array. |
54
|
|
|
* |
55
|
|
|
* @param array $meta |
56
|
|
|
* @param string $path |
57
|
|
|
* |
58
|
|
|
* @return array |
59
|
|
|
*/ |
60
|
|
|
protected function normalizeMeta(array $meta, $path) |
61
|
|
|
{ |
62
|
|
|
$result = Util::pathinfo($path); |
63
|
|
|
|
64
|
|
|
if (isset($meta['Last-Modified'])) { |
65
|
|
|
$result['timestamp'] = strtotime($meta['Last-Modified']); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return array_merge($result, Util::map($meta, [ |
69
|
|
|
'Content-Length' => 'size', |
70
|
|
|
'Content-Type' => 'mimetype', |
71
|
|
|
]), ['type' => 'file']); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Normalize the content from list contents of dir. |
76
|
|
|
* |
77
|
|
|
* @param array $content |
78
|
|
|
* |
79
|
|
|
* @return array |
80
|
|
|
*/ |
81
|
|
|
protected function normalizeContent(array $content) |
82
|
|
|
{ |
83
|
|
|
$return = []; |
84
|
|
|
|
85
|
|
|
if (substr($content['key'], -1) === '/') { |
86
|
|
|
$return['type'] = 'dir'; |
87
|
|
|
$return['path'] = rtrim($content['key'], '/'); |
88
|
|
|
} else { |
89
|
|
|
$return['type'] = 'file'; |
90
|
|
|
$return['path'] = $content['key']; |
91
|
|
|
$return['size'] = $content['size']; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$return['timestamp'] = strtotime($content['lastModified']); |
95
|
|
|
|
96
|
|
|
return $return + Util::pathinfo($content['key']); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Extract permissions from acl |
101
|
|
|
* |
102
|
|
|
* @param array $acl |
103
|
|
|
* |
104
|
|
|
* @return array |
105
|
|
|
*/ |
106
|
|
|
protected function extractPermissions(array $acl) |
107
|
|
|
{ |
108
|
|
|
$permissions = []; |
109
|
|
|
foreach ($acl as $row) { |
110
|
|
|
$ids = array_column($row['grantee'], 'id'); |
111
|
|
|
if (in_array('*', $ids)) { |
112
|
|
|
$permissions = $row['permission']; |
113
|
|
|
break; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
return $permissions; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|