Common.php
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
namespace Qcloud\Cos;
function region_map($region)
{
$regionmap = array(
'cn-east' => 'ap-shanghai',
'cn-south' => 'ap-guangzhou',
'cn-north' => 'ap-beijing-1',
'cn-south-2' => 'ap-guangzhou-2',
'cn-southwest' => 'ap-chengdu',
'sg' => 'ap-singapore',
'tj' => 'ap-beijing-1',
'bj' => 'ap-beijing',
'sh' => 'ap-shanghai',
'gz' => 'ap-guangzhou',
'cd' => 'ap-chengdu',
'sgp' => 'ap-singapore'
);
if (isset($regionmap[$region])) {
return $regionmap[$region];
}
return $region;
}
function processCosConfig($config)
{
$config['region'] = !empty($config['region']) ? region_map($config['region']) : $config['region'];
$config['secretId'] = trim($config['credentials']['secretId']);
$config['secretKey'] = trim($config['credentials']['secretKey']);
$config['token'] = !empty($config['credentials']['token']) ? trim($config['credentials']['token']) : $config['credentials']['token'];
$config['appId'] = $config['credentials']['appId'];
$config['anonymous'] = $config['credentials']['anonymous'];
unset($config['credentials']);
if (isset($config['schema'])) {
$config['scheme'] = $config['schema'];
unset($config['schema']);
}
if (isset($config['locationWithSchema'])) {
$config['locationWithScheme'] = $config['locationWithSchema'];
unset($config['locationWithSchema']);
}
return $config;
}
function encodeKey($key)
{
return str_replace('%2F', '/', rawurlencode($key));
}
function endWith($haystack, $needle)
{
$length = strlen($needle);
if ($length == 0) {
return true;
}
return (substr($haystack, -$length) === $needle);
}
function startWith($haystack, $needle)
{
$length = strlen($needle);
if ($length == 0) {
return true;
}
return (substr($haystack, 0, $length) === $needle);
}
function headersMap($command, $request)
{
$headermap = array(
'TransferEncoding' => 'Transfer-Encoding',
'ChannelId' => 'x-cos-channel-id'
);
foreach ($headermap as $key => $value) {
if (isset($command[$key])) {
$request = $request->withHeader($value, $command[$key]);
}
}
return $request;
}
if (!function_exists('str_contains')) {
function str_contains($haystack, $needle)
{
return strpos($haystack, $needle) !== false;
}
}