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
|
|
|
* Extract options from config |
12
|
|
|
* |
13
|
|
|
* @param Config $config |
14
|
|
|
* |
15
|
|
|
* @return array |
16
|
|
|
*/ |
17
|
|
|
protected function extractOptions(Config $config) |
18
|
|
|
{ |
19
|
|
|
$options = []; |
20
|
|
|
|
21
|
|
|
foreach (['headers', 'query', 'body', 'request', 'authorize'] as $key) { |
22
|
|
|
if ($config->has($key)) { |
23
|
|
|
$options[$key] = $config->get($key); |
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
return $options; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Normalize the object meta array. |
32
|
|
|
* |
33
|
|
|
* @param array $meta |
34
|
|
|
* @param string $path |
35
|
|
|
* |
36
|
|
|
* @return array |
37
|
|
|
*/ |
38
|
|
|
protected function normalizeMeta(array $meta, $path) |
39
|
|
|
{ |
40
|
|
|
$result = Util::pathinfo($path); |
41
|
|
|
|
42
|
|
|
if (isset($meta['Last-Modified'])) { |
43
|
|
|
$result['timestamp'] = strtotime($meta['Last-Modified']); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
return array_merge($result, Util::map($meta, [ |
47
|
|
|
'Content-Length' => 'size', |
48
|
|
|
'Content-Type' => 'mimetype', |
49
|
|
|
]), ['type' => 'file']); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Normalize the content from list contents of dir. |
54
|
|
|
* |
55
|
|
|
* @param array $content |
56
|
|
|
* |
57
|
|
|
* @return array |
58
|
|
|
*/ |
59
|
|
|
protected function normalizeContent(array $content) |
60
|
|
|
{ |
61
|
|
|
$return = []; |
62
|
|
|
|
63
|
|
|
if (substr($content['key'], -1) === '/') { |
64
|
|
|
$return['type'] = 'dir'; |
65
|
|
|
$return['path'] = rtrim($content['key'], '/'); |
66
|
|
|
} else { |
67
|
|
|
$return['type'] = 'file'; |
68
|
|
|
$return['path'] = $content['key']; |
69
|
|
|
$return['size'] = $content['size']; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$return['timestamp'] = strtotime($content['lastModified']); |
73
|
|
|
|
74
|
|
|
return $return + Util::pathinfo($content['key']); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Extract permissions from acl |
79
|
|
|
* |
80
|
|
|
* @param array $acl |
81
|
|
|
* |
82
|
|
|
* @return array |
83
|
|
|
*/ |
84
|
|
|
protected function extractPermissions(array $acl) |
85
|
|
|
{ |
86
|
|
|
$permissions = []; |
87
|
|
|
foreach ($acl as $row) { |
88
|
|
|
$ids = array_column($row['grantee'], 'id'); |
89
|
|
|
if (in_array('*', $ids)) { |
90
|
|
|
$permissions = $row['permission']; |
91
|
|
|
break; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return $permissions; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|