Configuration.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace Aws\EndpointDiscovery;
  3. class Configuration implements ConfigurationInterface
  4. {
  5. private $cacheLimit;
  6. private $enabled;
  7. public function __construct($enabled, $cacheLimit = 1000)
  8. {
  9. $this->cacheLimit = filter_var($cacheLimit, FILTER_VALIDATE_INT);
  10. if ($this->cacheLimit == false || $this->cacheLimit < 1) {
  11. throw new \InvalidArgumentException(
  12. "'cache_limit' value must be a positive integer."
  13. );
  14. }
  15. // Unparsable $enabled flag errs on the side of disabling endpoint discovery
  16. $this->enabled = filter_var($enabled, FILTER_VALIDATE_BOOLEAN);
  17. }
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public function isEnabled()
  22. {
  23. return $this->enabled;
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function getCacheLimit()
  29. {
  30. return $this->cacheLimit;
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function toArray()
  36. {
  37. return [
  38. 'enabled' => $this->isEnabled(),
  39. 'cache_limit' => $this->getCacheLimit()
  40. ];
  41. }
  42. }