1 | <?php |
||
2 | |||
3 | namespace Qiniu\Http; |
||
4 | |||
5 | use Qiniu\Http\Middleware\Middleware; |
||
6 | |||
7 | final class RequestOptions |
||
8 | { |
||
9 | |||
10 | /** |
||
11 | * @var int|null |
||
12 | * http 请求的超时时间,单位:秒,默认:0,不超时 |
||
13 | */ |
||
14 | public $connection_timeout; |
||
15 | |||
16 | /** |
||
17 | * @var int|null |
||
18 | * http 请求的超时时间,单位:毫秒,默认:0,不超时 |
||
19 | */ |
||
20 | public $connection_timeout_ms; |
||
21 | |||
22 | /** |
||
23 | * @var int|null |
||
24 | * http 请求的超时时间,单位:秒,默认:0,不超时 |
||
25 | */ |
||
26 | public $timeout; |
||
27 | |||
28 | |||
29 | /** |
||
30 | * @var int|null |
||
31 | * http 请求的超时时间,单位:毫秒,默认:0,不超时 |
||
32 | */ |
||
33 | public $timeout_ms; |
||
34 | |||
35 | /** |
||
36 | * @var array<Middleware> |
||
37 | */ |
||
38 | public $middlewares; |
||
39 | |||
40 | public function __construct( |
||
41 | $connection_timeout = null, |
||
42 | $connection_timeout_ms = null, |
||
43 | $timeout = null, |
||
44 | $timeout_ms = null, |
||
45 | $middlewares = array() |
||
46 | ) { |
||
47 | $this->connection_timeout = $connection_timeout; |
||
48 | $this->connection_timeout_ms = $connection_timeout_ms; |
||
49 | $this->timeout = $timeout; |
||
50 | $this->timeout_ms = $timeout_ms; |
||
51 | $this->middlewares = $middlewares; |
||
52 | } |
||
53 | |||
54 | public function getCurlOpt() |
||
55 | { |
||
56 | $result = array(); |
||
57 | if ($this->connection_timeout != null) { |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
58 | $result[CURLOPT_CONNECTTIMEOUT] = $this->connection_timeout; |
||
59 | } |
||
60 | if ($this->connection_timeout_ms != null) { |
||
0 ignored issues
–
show
|
|||
61 | $result[CURLOPT_CONNECTTIMEOUT_MS] = $this->connection_timeout_ms; |
||
62 | } |
||
63 | if ($this->timeout != null) { |
||
0 ignored issues
–
show
|
|||
64 | $result[CURLOPT_TIMEOUT] = $this->timeout; |
||
65 | } |
||
66 | if ($this->timeout_ms != null) { |
||
0 ignored issues
–
show
|
|||
67 | $result[CURLOPT_TIMEOUT_MS] = $this->timeout_ms; |
||
68 | } |
||
69 | return $result; |
||
70 | } |
||
71 | } |
||
72 |