1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AlibabaCloud\Client\Traits; |
4
|
|
|
|
5
|
|
|
use AlibabaCloud\Client\Support\Arrays; |
6
|
|
|
use AlibabaCloud\Client\Filter\ClientFilter; |
7
|
|
|
use AlibabaCloud\Client\Exception\ClientException; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Trait HttpTrait |
11
|
|
|
* |
12
|
|
|
* @package AlibabaCloud\Client\Traits |
13
|
|
|
*/ |
14
|
|
|
trait HttpTrait |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var array |
19
|
|
|
*/ |
20
|
|
|
public $options = []; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param int|float $seconds |
24
|
|
|
* |
25
|
|
|
* @return $this |
26
|
|
|
* @throws ClientException |
27
|
|
|
*/ |
28
|
71 |
|
public function timeout($seconds) |
29
|
|
|
{ |
30
|
71 |
|
$this->options['timeout'] = ClientFilter::timeout($seconds); |
31
|
|
|
|
32
|
69 |
|
return $this; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param int $milliseconds |
37
|
|
|
* |
38
|
|
|
* @return $this |
39
|
|
|
* @throws ClientException |
40
|
|
|
*/ |
41
|
2 |
|
public function timeoutMilliseconds($milliseconds) |
42
|
|
|
{ |
43
|
2 |
|
ClientFilter::milliseconds($milliseconds); |
44
|
1 |
|
$seconds = $milliseconds / 1000; |
45
|
|
|
|
46
|
1 |
|
return $this->timeout($seconds); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param int|float $seconds |
51
|
|
|
* |
52
|
|
|
* @return $this |
53
|
|
|
* @throws ClientException |
54
|
|
|
*/ |
55
|
70 |
|
public function connectTimeout($seconds) |
56
|
|
|
{ |
57
|
70 |
|
$this->options['connect_timeout'] = ClientFilter::connectTimeout($seconds); |
58
|
|
|
|
59
|
68 |
|
return $this; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param int $milliseconds |
64
|
|
|
* |
65
|
|
|
* @return $this |
66
|
|
|
* @throws ClientException |
67
|
|
|
*/ |
68
|
2 |
|
public function connectTimeoutMilliseconds($milliseconds) |
69
|
|
|
{ |
70
|
2 |
|
ClientFilter::milliseconds($milliseconds); |
71
|
1 |
|
$seconds = $milliseconds / 1000; |
72
|
|
|
|
73
|
1 |
|
return $this->connectTimeout($seconds); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param bool $debug |
78
|
|
|
* |
79
|
|
|
* @return $this |
80
|
|
|
*/ |
81
|
16 |
|
public function debug($debug) |
82
|
|
|
{ |
83
|
16 |
|
$this->options['debug'] = $debug; |
84
|
|
|
|
85
|
16 |
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @codeCoverageIgnore |
90
|
|
|
* |
91
|
|
|
* @param array $cert |
92
|
|
|
* |
93
|
|
|
* @return $this |
94
|
|
|
*/ |
95
|
|
|
public function cert($cert) |
96
|
|
|
{ |
97
|
|
|
$this->options['cert'] = $cert; |
98
|
|
|
|
99
|
|
|
return $this; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @codeCoverageIgnore |
104
|
|
|
* |
105
|
|
|
* @param array|string $proxy |
106
|
|
|
* |
107
|
|
|
* @return $this |
108
|
|
|
*/ |
109
|
|
|
public function proxy($proxy) |
110
|
|
|
{ |
111
|
|
|
$this->options['proxy'] = $proxy; |
112
|
|
|
|
113
|
|
|
return $this; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @param mixed $verify |
118
|
|
|
* |
119
|
|
|
* @return $this |
120
|
|
|
*/ |
121
|
2 |
|
public function verify($verify) |
122
|
|
|
{ |
123
|
2 |
|
$this->options['verify'] = $verify; |
124
|
|
|
|
125
|
2 |
|
return $this; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @param array $options |
130
|
|
|
* |
131
|
|
|
* @return $this |
132
|
|
|
*/ |
133
|
71 |
|
public function options(array $options) |
134
|
|
|
{ |
135
|
71 |
|
if ($options !== []) { |
136
|
19 |
|
$this->options = Arrays::merge([$this->options, $options]); |
137
|
19 |
|
} |
138
|
|
|
|
139
|
71 |
|
return $this; |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|