Skip to content

Commit

Permalink
Replaced mb-string extension with polyfill, added changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
norberttech committed Nov 22, 2020
1 parent b1602e7 commit 3944b3c
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 4 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

## [0.1.0] - 2020-11-22
### First release :tada:
- initial release
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"prefer-stable": true,
"require": {
"php": ">=7.4.2",
"ext-mbstring": "*",
"ext-json": "*",
"aeon-php/calendar": ">=0.11.0",
"aeon-php/sleep": ">=0.5.0",
"psr/cache": "^1.0"
"psr/cache": "^1.0",
"symfony/polyfill-mbstring": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^9.4",
Expand Down
83 changes: 81 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/Aeon/RateLimiter/RateLimiter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,35 @@ public function __construct(Algorithm $algorithm, Storage $storage)
}

/**
* Record next hit, throws an extension where there are no available hits left according to the selected algorithm.
*
* @throws RateLimitException
*/
public function hit(string $id) : void
{
$this->algorithm->hit($id, $this->storage);
}

/**
* Estimate time required to the next hit. If current capacity is greater than 0, time will be 0.
*/
public function estimate(string $id) : TimeUnit
{
return $this->algorithm->estimate($id, $this->storage);
}

/**
* Returns current capacity according to the selected algorithm, when there are no available hits left, it will return 0.
* Use RateLimiter::estimate method to find out when next hit will be possible.
*/
public function capacity(string $id) : int
{
return $this->algorithm->capacity($id, $this->storage);
}

/**
* Try to record next hit, in case of rate limit exception take the cooldown time and sleep current process.
*/
public function throttle(string $id, Process $process) : void
{
try {
Expand Down

0 comments on commit 3944b3c

Please sign in to comment.