Configuration.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace Aws\DefaultsMode;
  3. use Aws\DefaultsMode\Exception\ConfigurationException;
  4. class Configuration implements ConfigurationInterface
  5. {
  6. private $mode;
  7. private $retryMode;
  8. private $stsRegionalEndpoints;
  9. private $s3UsEast1RegionalEndpoints;
  10. private $connectTimeoutInMillis;
  11. private $httpRequestTimeoutInMillis;
  12. private $validModes = [
  13. 'legacy',
  14. 'standard',
  15. 'cross-region',
  16. 'in-region',
  17. 'mobile',
  18. 'auto',
  19. ];
  20. public function __construct($mode = 'legacy')
  21. {
  22. $mode = strtolower($mode);
  23. if (!in_array($mode, $this->validModes)) {
  24. throw new \InvalidArgumentException("'{$mode}' is not a valid mode."
  25. . " The mode has to be 'legacy', 'standard', 'cross-region', 'in-region',"
  26. . " 'mobile', or 'auto'.");
  27. }
  28. $this->mode = $mode;
  29. if ($this->mode == 'legacy') {
  30. return;
  31. }
  32. $data = \Aws\load_compiled_json(
  33. __DIR__ . '/../data/sdk-default-configuration.json'
  34. );
  35. $this->retryMode = $data['base']['retryMode'];
  36. $this->stsRegionalEndpoints = $data['base']['stsRegionalEndpoints'];
  37. $this->s3UsEast1RegionalEndpoints = $data['base']['s3UsEast1RegionalEndpoints'];
  38. $this->connectTimeoutInMillis = $data['base']['connectTimeoutInMillis'];
  39. if (isset($data['modes'][$mode])) {
  40. $modeData = $data['modes'][$mode];
  41. foreach ($modeData as $settingName => $settingValue) {
  42. if (isset($this->$settingName)) {
  43. if (isset($settingValue['override'])) {
  44. $this->$settingName = $settingValue['override'];
  45. } else if (isset($settingValue['multiply'])) {
  46. $this->$settingName *= $settingValue['multiply'];
  47. } else if (isset($settingValue['add'])) {
  48. $this->$settingName += $settingValue['add'];
  49. }
  50. } else {
  51. if (isset($settingValue['override'])) {
  52. if (property_exists($this, $settingName)) {
  53. $this->$settingName = $settingValue['override'];
  54. }
  55. }
  56. }
  57. }
  58. }
  59. }
  60. /**
  61. * {@inheritdoc}
  62. */
  63. public function getMode()
  64. {
  65. return $this->mode;
  66. }
  67. /**
  68. * {@inheritdoc}
  69. */
  70. public function getRetryMode()
  71. {
  72. return $this->retryMode;
  73. }
  74. /**
  75. * {@inheritdoc}
  76. */
  77. public function getStsRegionalEndpoints()
  78. {
  79. return $this->stsRegionalEndpoints;
  80. }
  81. /**
  82. * {@inheritdoc}
  83. */
  84. public function getS3UsEast1RegionalEndpoints()
  85. {
  86. return $this->s3UsEast1RegionalEndpoints;
  87. }
  88. /**
  89. * {@inheritdoc}
  90. */
  91. public function getConnectTimeoutInMillis()
  92. {
  93. return $this->connectTimeoutInMillis;
  94. }
  95. /**
  96. * {@inheritdoc}
  97. */
  98. public function getHttpRequestTimeoutInMillis()
  99. {
  100. return $this->httpRequestTimeoutInMillis;
  101. }
  102. /**
  103. * {@inheritdoc}
  104. */
  105. public function toArray()
  106. {
  107. return [
  108. 'mode' => $this->getMode(),
  109. 'retry_mode' => $this->getRetryMode(),
  110. 'sts_regional_endpoints' => $this->getStsRegionalEndpoints(),
  111. 's3_us_east_1_regional_endpoint' => $this->getS3UsEast1RegionalEndpoints(),
  112. 'connect_timeout_in_milliseconds' => $this->getConnectTimeoutInMillis(),
  113. 'http_request_timeout_in_milliseconds' => $this->getHttpRequestTimeoutInMillis(),
  114. ];
  115. }
  116. }