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