OTSClientConfig.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace Aliyun\OTS;
  3. use Aliyun\OTS\Retry\DefaultRetryPolicy as DefaultRetryPolicy;
  4. /**
  5. * OTSClientConfig 是用来封装OTS SDK端配置的类,OTSClient对象构造时会创建OTSClientConfig对象。
  6. * 当你在构造OTSClient对象时传入的参数会用来构造OTSClientConfig对象。
  7. */
  8. class OTSClientConfig
  9. {
  10. public $endPoint;
  11. public $accessKeyID;
  12. public $accessKeySecret;
  13. public $instanceName;
  14. public $connectionTimeout = 2.0;
  15. public $socketTimeout = 2.0;
  16. /**
  17. * Error级别日志处理函数,默认处理函数为 defaultOTSErrorLogHandler,行为是打印到屏幕
  18. */
  19. public $errorLogHandler;
  20. /**
  21. * Debug级别日志处理函数,默认处理函数为 defaultOTSDebugLogHandler,行为是打印到屏幕
  22. */
  23. public $debugLogHandler;
  24. /**
  25. * @var \Aliyun\OTS\Retry\RetryPolicy
  26. * 重试策略,默认为 \Aliyun\OTS\Retry\DefaultRetryPolicy。
  27. */
  28. public $retryPolicy;
  29. /**
  30. * OTSClientConfig的构造函数。
  31. * 它的参数从 OTSClient 的构造函数中传入。具体参数说明请见 OTSClient 的构造函数。
  32. */
  33. public function __construct(array $args)
  34. {
  35. if (!isset($args['EndPoint'])) {
  36. throw new OTSClientException("Missing EndPoint in client config.");
  37. }
  38. if (!isset($args['AccessKeyID'])) {
  39. throw new OTSClientException("Missing AccessKeyID in client config.");
  40. }
  41. if (!isset($args['AccessKeySecret'])) {
  42. throw new OTSClientException("Missing AccessKeySecret in client config.");
  43. }
  44. if (!isset($args['InstanceName'])) {
  45. throw new OTSClientException("Missing InstanceName in client config.");
  46. }
  47. $this->endPoint = $args['EndPoint'];
  48. $this->accessKeyID = $args['AccessKeyID'];
  49. $this->accessKeySecret = $args['AccessKeySecret'];
  50. $this->instanceName = $args['InstanceName'];
  51. if (isset($args['ConnectionTimeout'])) {
  52. $this->connectionTimeout = $args['ConnectionTimeout'];
  53. }
  54. if (isset($args['SocketTimeout'])) {
  55. $this->socketTimeout = $args['SocketTimeout'];
  56. }
  57. if (!isset($args['RetryPolicy'])) {
  58. $this->retryPolicy = new DefaultRetryPolicy();
  59. } else {
  60. $this->retryPolicy = $args['RetryPolicy'];
  61. }
  62. if (!isset($args['ErrorLogHandler'])) {
  63. $this->errorLogHandler = "defaultOTSErrorLogHandler";
  64. } else {
  65. $this->errorLogHandler = $args['ErrorLogHandler'];
  66. }
  67. if (!isset($args['DebugLogHandler'])) {
  68. $this->debugLogHandler = 'defaultOTSDebugLogHandler';
  69. } else {
  70. $this->debugLogHandler = $args['DebugLogHandler'];
  71. }
  72. }
  73. public function getEndPoint()
  74. {
  75. return $this->endPoint;
  76. }
  77. public function getAccessKeyID()
  78. {
  79. return $this->accessKeyID;
  80. }
  81. public function getAccessKeySecret()
  82. {
  83. return $this->accessKeySecret;
  84. }
  85. public function getInstanceName()
  86. {
  87. return $this->instanceName;
  88. }
  89. }