| 1 |
<?php |
| 2 |
|
| 3 |
namespace Dudlewebs\WPMCS\s3\Aws\Retry; |
| 4 |
|
| 5 |
use Dudlewebs\WPMCS\s3\Aws\Retry\Exception\ConfigurationException; |
| 6 |
class Configuration implements ConfigurationInterface |
| 7 |
{ |
| 8 |
private $mode; |
| 9 |
private $maxAttempts; |
| 10 |
private $validModes = ['legacy', 'standard', 'adaptive']; |
| 11 |
public function __construct($mode = 'legacy', $maxAttempts = 3) |
| 12 |
{ |
| 13 |
$mode = \strtolower($mode); |
| 14 |
if (!\in_array($mode, $this->validModes)) { |
| 15 |
throw new ConfigurationException("'{$mode}' is not a valid mode." . " The mode has to be 'legacy', 'standard', or 'adaptive'."); |
| 16 |
} |
| 17 |
if (!\is_numeric($maxAttempts) || \intval($maxAttempts) != $maxAttempts || $maxAttempts < 1) { |
| 18 |
throw new ConfigurationException("The 'maxAttempts' parameter has" . " to be an integer >= 1."); |
| 19 |
} |
| 20 |
$this->mode = $mode; |
| 21 |
$this->maxAttempts = \intval($maxAttempts); |
| 22 |
} |
| 23 |
/** |
| 24 |
* {@inheritdoc} |
| 25 |
*/ |
| 26 |
public function getMode() |
| 27 |
{ |
| 28 |
return $this->mode; |
| 29 |
} |
| 30 |
/** |
| 31 |
* {@inheritdoc} |
| 32 |
*/ |
| 33 |
public function getMaxAttempts() |
| 34 |
{ |
| 35 |
return $this->maxAttempts; |
| 36 |
} |
| 37 |
/** |
| 38 |
* {@inheritdoc} |
| 39 |
*/ |
| 40 |
public function toArray() |
| 41 |
{ |
| 42 |
return ['mode' => $this->getMode(), 'max_attempts' => $this->getMaxAttempts()]; |
| 43 |
} |
| 44 |
} |
| 45 |
|