RequestOptions.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace Qiniu\Http;
  3. use Qiniu\Http\Middleware\Middleware;
  4. final class RequestOptions
  5. {
  6. /**
  7. * @var int|null
  8. * http 请求的超时时间,单位:秒,默认:0,不超时
  9. */
  10. public $connection_timeout;
  11. /**
  12. * @var int|null
  13. * http 请求的超时时间,单位:毫秒,默认:0,不超时
  14. */
  15. public $connection_timeout_ms;
  16. /**
  17. * @var int|null
  18. * http 请求的超时时间,单位:秒,默认:0,不超时
  19. */
  20. public $timeout;
  21. /**
  22. * @var int|null
  23. * http 请求的超时时间,单位:毫秒,默认:0,不超时
  24. */
  25. public $timeout_ms;
  26. /**
  27. * @var string|null
  28. * 代理URL,默认:空
  29. */
  30. public $proxy;
  31. /**
  32. * @var int|null
  33. * 代理鉴权方式,默认:空
  34. */
  35. public $proxy_auth;
  36. /**
  37. * @var string|null
  38. * 代理鉴权参数,默认:空
  39. */
  40. public $proxy_user_password;
  41. /**
  42. * @var array<Middleware>
  43. */
  44. public $middlewares;
  45. public function __construct(
  46. $connection_timeout = null,
  47. $connection_timeout_ms = null,
  48. $timeout = null,
  49. $timeout_ms = null,
  50. $middlewares = array(),
  51. $proxy = null,
  52. $proxy_auth = null,
  53. $proxy_user_password = null
  54. ) {
  55. $this->connection_timeout = $connection_timeout;
  56. $this->connection_timeout_ms = $connection_timeout_ms;
  57. $this->timeout = $timeout;
  58. $this->timeout_ms = $timeout_ms;
  59. $this->proxy = $proxy;
  60. $this->proxy_auth = $proxy_auth;
  61. $this->proxy_user_password = $proxy_user_password;
  62. $this->middlewares = $middlewares;
  63. }
  64. public function getCurlOpt()
  65. {
  66. $result = array();
  67. if ($this->connection_timeout != null) {
  68. $result[CURLOPT_CONNECTTIMEOUT] = $this->connection_timeout;
  69. }
  70. if ($this->connection_timeout_ms != null) {
  71. $result[CURLOPT_CONNECTTIMEOUT_MS] = $this->connection_timeout_ms;
  72. }
  73. if ($this->timeout != null) {
  74. $result[CURLOPT_TIMEOUT] = $this->timeout;
  75. }
  76. if ($this->timeout_ms != null) {
  77. $result[CURLOPT_TIMEOUT_MS] = $this->timeout_ms;
  78. }
  79. if ($this->proxy != null) {
  80. $result[CURLOPT_PROXY] = $this->proxy;
  81. }
  82. if ($this->proxy_auth != null) {
  83. $result[CURLOPT_PROXYAUTH] = $this->proxy_auth;
  84. }
  85. if ($this->proxy_user_password != null) {
  86. $result[CURLOPT_PROXYUSERPWD] = $this->proxy_user_password;
  87. }
  88. return $result;
  89. }
  90. }