AbstractStrategy.php 929 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace STS\Backoff\Strategies;
  3. /**
  4. * Class AbstractStrategy
  5. * @package STS\Backoff\Strategies
  6. */
  7. abstract class AbstractStrategy
  8. {
  9. /**
  10. * Base wait time in ms
  11. * @var int
  12. */
  13. protected $base = 100;
  14. /**
  15. * @var bool
  16. */
  17. protected $jitter = true;
  18. /**
  19. * AbstractStrategy constructor.
  20. *
  21. * @param int $base
  22. */
  23. public function __construct($base = null)
  24. {
  25. if(is_int($base)) {
  26. $this->base = $base;
  27. }
  28. }
  29. /**
  30. * @param int $attempt
  31. *
  32. * @return int Time to wait in ms
  33. */
  34. abstract public function getWaitTime($attempt);
  35. /**
  36. * @param int $attempt
  37. *
  38. * @return int
  39. */
  40. public function __invoke($attempt)
  41. {
  42. return $this->getWaitTime($attempt);
  43. }
  44. /**
  45. * @return int
  46. */
  47. public function getBase()
  48. {
  49. return $this->base;
  50. }
  51. }