|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AlphaSnow\AliyunOss; |
|
4
|
|
|
|
|
5
|
|
|
use League\Flysystem\Config; |
|
6
|
|
|
use OSS\OssClient; |
|
7
|
|
|
|
|
8
|
|
|
class AliyunOssUtil |
|
9
|
|
|
{ |
|
10
|
|
|
public static $resultMap = [ |
|
11
|
|
|
'Body' => 'raw_contents', |
|
12
|
|
|
'Content-Length' => 'size', |
|
13
|
|
|
'ContentType' => 'mimetype', |
|
14
|
|
|
'Size' => 'size', |
|
15
|
|
|
'StorageClass' => 'storage_class', |
|
16
|
|
|
]; |
|
17
|
|
|
/** |
|
18
|
|
|
* @var array |
|
19
|
|
|
*/ |
|
20
|
|
|
public static $metaOptions = [ |
|
21
|
|
|
'CacheControl', |
|
22
|
|
|
'Expires', |
|
23
|
|
|
'ServerSideEncryption', |
|
24
|
|
|
'Metadata', |
|
25
|
|
|
'ACL', |
|
26
|
|
|
'ContentType', |
|
27
|
|
|
'ContentDisposition', |
|
28
|
|
|
'ContentLanguage', |
|
29
|
|
|
'ContentEncoding', |
|
30
|
|
|
]; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var string[] |
|
34
|
|
|
*/ |
|
35
|
|
|
public static $metaMap = [ |
|
36
|
|
|
'CacheControl' => 'Cache-Control', |
|
37
|
|
|
'Expires' => 'Expires', |
|
38
|
|
|
'ServerSideEncryption' => 'x-oss-server-side-encryption', |
|
39
|
|
|
'Metadata' => 'x-oss-metadata-directive', |
|
40
|
|
|
'ACL' => 'x-oss-object-acl', |
|
41
|
|
|
'ContentType' => 'Content-Type', |
|
42
|
|
|
'ContentDisposition' => 'Content-Disposition', |
|
43
|
|
|
'ContentLanguage' => 'response-content-language', |
|
44
|
|
|
'ContentEncoding' => 'Content-Encoding', |
|
45
|
|
|
]; |
|
46
|
|
|
|
|
47
|
|
|
public static $metaHeaders = [ |
|
48
|
|
|
'storage', |
|
49
|
|
|
OssClient::OSS_ACL, |
|
50
|
|
|
OssClient::OSS_OBJECT_ACL, |
|
51
|
|
|
OssClient::OSS_OBJECT_GROUP, |
|
52
|
|
|
OssClient::OSS_OBJECT_COPY_SOURCE, |
|
53
|
|
|
OssClient::OSS_OBJECT_COPY_SOURCE_RANGE, |
|
54
|
|
|
OssClient::OSS_PROCESS, |
|
55
|
|
|
OssClient::OSS_CALLBACK, |
|
56
|
|
|
OssClient::OSS_CALLBACK_VAR, |
|
57
|
|
|
OssClient::OSS_REQUEST_PAYER, |
|
58
|
|
|
OssClient::OSS_TRAFFIC_LIMIT, |
|
59
|
|
|
OssClient::OSS_SECURITY_TOKEN |
|
60
|
|
|
]; |
|
61
|
|
|
|
|
62
|
4 |
|
public static function getHeadersFromConfig(Config $config) |
|
63
|
|
|
{ |
|
64
|
4 |
|
$headers = []; |
|
65
|
4 |
|
foreach (static::$metaOptions as $option) { |
|
66
|
4 |
|
if (!$config->has($option)) { |
|
67
|
4 |
|
continue; |
|
68
|
|
|
} |
|
69
|
|
|
$headers[static::$metaMap[$option]] = $config->get($option); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
4 |
|
foreach (static::$metaHeaders as $header) { |
|
73
|
4 |
|
if (!$config->has($header)) { |
|
74
|
4 |
|
continue; |
|
75
|
|
|
} |
|
76
|
|
|
$headers[$header] = $config->get($header); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
4 |
|
return $headers; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|