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