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