| 1 | <?php |
||
| 9 | final class MemcachedRateLimiter extends AbstractElapsedTimeRateLimiter |
||
| 10 | { |
||
| 11 | private const MEMCACHED_SECONDS_LIMIT = 2592000; // Number of seconds in 30 days |
||
| 12 | |||
| 13 | /** @var Memcached */ |
||
| 14 | private $memcached; |
||
| 15 | |||
| 16 | public function __construct(Memcached $memcached, string $keyPrefix = '') |
||
| 26 | |||
| 27 | protected function getCurrent(string $valueKey): int |
||
| 31 | |||
| 32 | protected function updateCounter(string $valueKey, string $timeKey, int $interval): int |
||
| 42 | |||
| 43 | protected function getElapsedTime(string $timeKey): int |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Interval to Memcached expiration time. |
||
| 50 | * |
||
| 51 | * @see https://www.php.net/manual/en/memcached.expiration.php |
||
| 52 | * |
||
| 53 | * @param int $interval |
||
| 54 | * |
||
| 55 | * @return int |
||
| 56 | */ |
||
| 57 | private function intervalToMemcachedTime(int $interval): int |
||
| 61 | } |
||
| 62 |