OptionsTrait.php 2.9 KB

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