1
0
mirror of https://github.com/delight-im/PHP-Auth.git synced 2025-08-04 15:17:28 +02:00

Allow for 'Auth#throttle' to be used even when throttling is disabled

This commit is contained in:
Marco
2021-04-21 16:39:10 +02:00
parent df16db9b2b
commit 7bce546def
2 changed files with 8 additions and 2 deletions

View File

@@ -872,6 +872,8 @@ Allowing short bursts of activity during peak demand is possible by specifying a
In some cases, you may just want to *simulate* the throttling or rate limiting. This lets you check whether an action would be permitted without actually modifying the activity tracker. To do so, simply pass `true` as the fifth argument.
**Note:** When you disable throttling on the instance (using the [`$throttling` parameter](#creating-a-new-instance) passed to the constructor), this turns off both the automatic internal protection and the effect of any calls to `Auth#throttle` in your own application code unless you also set the optional `$force` parameter to `true` in specific `Auth#throttle` calls.
### Administration (managing users)
The administrative interface is available via `$auth->admin()`. You can call various method on this interface, as documented below.

View File

@@ -1728,12 +1728,16 @@ final class Auth extends UserManager {
* @param int|null $burstiness (optional) the permitted degree of variation or unevenness during peaks (>= 1)
* @param bool|null $simulated (optional) whether to simulate a dry run instead of actually consuming the requested units
* @param int|null $cost (optional) the number of units to request (>= 1)
* @param bool|null $force (optional) whether to apply throttling locally (with this call) even when throttling has been disabled globally (on the instance, via the constructor option)
* @return float the number of units remaining from the supply
* @throws TooManyRequestsException if the actual demand has exceeded the designated supply
* @throws AuthError if an internal problem occurred (do *not* catch)
*/
public function throttle(array $criteria, $supply, $interval, $burstiness = null, $simulated = null, $cost = null) {
if (!$this->throttling) {
public function throttle(array $criteria, $supply, $interval, $burstiness = null, $simulated = null, $cost = null, $force = null) {
// validate the supplied parameters and set appropriate defaults where necessary
$force = ($force !== null) ? (bool) $force : false;
if (!$this->throttling && !$force) {
return $supply;
}