1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AlibabaCloud\Client\Credentials\Ini; |
4
|
|
|
|
5
|
|
|
use AlibabaCloud\Client\Clients\Client; |
6
|
|
|
use AlibabaCloud\Client\Exception\ClientException; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Trait OptionsTrait |
10
|
|
|
* |
11
|
|
|
* @package AlibabaCloud\Client\Credentials\Ini |
12
|
|
|
* |
13
|
|
|
* @mixin IniCredential |
14
|
|
|
*/ |
15
|
|
|
trait OptionsTrait |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @param array $configures |
19
|
|
|
* @param Client $client |
20
|
|
|
* |
21
|
|
|
* @throws ClientException |
22
|
|
|
*/ |
23
|
9 |
|
private static function setClientAttributes($configures, Client $client) |
24
|
|
|
{ |
25
|
9 |
|
if (self::isNotEmpty($configures, 'region_id')) { |
26
|
6 |
|
$client->regionId($configures['region_id']); |
27
|
6 |
|
} |
28
|
|
|
|
29
|
9 |
|
if (isset($configures['debug'])) { |
30
|
5 |
|
$client->options( |
31
|
|
|
[ |
32
|
5 |
|
'debug' => (bool)$configures['debug'], |
33
|
|
|
] |
34
|
5 |
|
); |
35
|
5 |
|
} |
36
|
|
|
|
37
|
9 |
|
if (self::isNotEmpty($configures, 'timeout')) { |
38
|
5 |
|
$client->options( |
39
|
|
|
[ |
40
|
5 |
|
'timeout' => $configures['timeout'], |
41
|
|
|
] |
42
|
5 |
|
); |
43
|
5 |
|
} |
44
|
|
|
|
45
|
9 |
|
if (self::isNotEmpty($configures, 'connect_timeout')) { |
46
|
5 |
|
$client->options( |
47
|
|
|
[ |
48
|
5 |
|
'connect_timeout' => $configures['connect_timeout'], |
49
|
|
|
] |
50
|
5 |
|
); |
51
|
5 |
|
} |
52
|
9 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param array $configures |
56
|
|
|
* @param Client $client |
57
|
|
|
*/ |
58
|
9 |
|
private static function setProxy($configures, Client $client) |
59
|
|
|
{ |
60
|
9 |
|
if (self::isNotEmpty($configures, 'proxy')) { |
61
|
5 |
|
$client->options( |
62
|
|
|
[ |
63
|
5 |
|
'proxy' => $configures['proxy'], |
64
|
|
|
] |
65
|
5 |
|
); |
66
|
5 |
|
} |
67
|
9 |
|
$proxy = []; |
68
|
9 |
|
if (self::isNotEmpty($configures, 'proxy_http')) { |
69
|
5 |
|
$proxy['http'] = $configures['proxy_http']; |
70
|
5 |
|
} |
71
|
9 |
|
if (self::isNotEmpty($configures, 'proxy_https')) { |
72
|
5 |
|
$proxy['https'] = $configures['proxy_https']; |
73
|
5 |
|
} |
74
|
9 |
|
if (self::isNotEmpty($configures, 'proxy_no')) { |
75
|
5 |
|
$proxy['no'] = \explode(',', $configures['proxy_no']); |
76
|
5 |
|
} |
77
|
9 |
|
if ($proxy !== []) { |
78
|
5 |
|
$client->options( |
79
|
|
|
[ |
80
|
5 |
|
'proxy' => $proxy, |
81
|
|
|
] |
82
|
5 |
|
); |
83
|
5 |
|
} |
84
|
9 |
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param array $configures |
88
|
|
|
* @param Client $client |
89
|
|
|
*/ |
90
|
11 |
|
private static function setCert($configures, Client $client) |
91
|
|
|
{ |
92
|
11 |
|
if (self::isNotEmpty($configures, 'cert_file') && !self::isNotEmpty($configures, 'cert_password')) { |
93
|
2 |
|
$client->options( |
94
|
|
|
[ |
95
|
2 |
|
'cert' => $configures['cert_file'], |
96
|
|
|
] |
97
|
2 |
|
); |
98
|
2 |
|
} |
99
|
|
|
|
100
|
11 |
|
if (self::isNotEmpty($configures, 'cert_file') && self::isNotEmpty($configures, 'cert_password')) { |
101
|
5 |
|
$client->options( |
102
|
|
|
[ |
103
|
|
|
'cert' => [ |
104
|
5 |
|
$configures['cert_file'], |
105
|
5 |
|
$configures['cert_password'], |
106
|
5 |
|
], |
107
|
|
|
] |
108
|
5 |
|
); |
109
|
5 |
|
} |
110
|
11 |
|
} |
111
|
|
|
} |
112
|
|
|
|