UserFrosting API

Throttler

Handles throttling (rate limiting) of specific types of requests.

Tags
author

Alex Weissman (https://alexanderweissman.com)

Table of Contents

$classMapper ClassMapper
$throttleRules \UserFrosting\Sprinkle\Core\Throttle\ThrottleRule[]
__construct() Create a new Throttler object. mixed
addThrottleRule() Add a throttling rule for a particular throttle event type. mixed
getDelay() Check the current request against a specified throttle rule. bool
getRule() Get a registered rule of a particular type. \UserFrosting\Sprinkle\Core\Throttle\ThrottleRule[]
getThrottleRules() Get the current throttling rules. \UserFrosting\Sprinkle\Core\Throttle\ThrottleRule[]
logEvent() Log a throttleable event to the database. mixed
computeDelay() Returns the current delay for a specified throttle rule. int

Properties

$throttleRules

protected \UserFrosting\Sprinkle\Core\Throttle\ThrottleRule[] $throttleRules

Methods

__construct()

Create a new Throttler object.

public __construct( $classMapper : ClassMapper ) : mixed
Parameters
$classMapper : ClassMapper

Maps generic class identifiers to specific class names.

Return values
mixed

addThrottleRule()

Add a throttling rule for a particular throttle event type.

public addThrottleRule( $type : string [, $rule : ThrottleRule|null = null ] ) : mixed
Parameters
$type : string

The type of throttle event to check against.

$rule : ThrottleRule|null = null

The rule to use when throttling this type of event.

Return values
mixed

getDelay()

Check the current request against a specified throttle rule.

public getDelay( $type : string [, $requestData : array = [] ] ) : bool
Parameters
$type : string

The type of throttle event to check against.

$requestData : array = []

Any additional request parameters to use in checking the throttle.

Return values
bool

getRule()

Get a registered rule of a particular type.

public getRule( $type : string ) : \UserFrosting\Sprinkle\Core\Throttle\ThrottleRule[]
Parameters
$type : string
Tags
throws
ThrottlerException
Return values
\UserFrosting\Sprinkle\Core\Throttle\ThrottleRule[]

getThrottleRules()

Get the current throttling rules.

public getThrottleRules( ) : \UserFrosting\Sprinkle\Core\Throttle\ThrottleRule[]
Return values
\UserFrosting\Sprinkle\Core\Throttle\ThrottleRule[]

logEvent()

Log a throttleable event to the database.

public logEvent( $type : string [, $requestData : string[] = [] ] ) : mixed
Parameters
$type : string

the type of event

$requestData : string[] = []

an array of field names => values that are relevant to throttling for this event (e.g. username, email, etc).

Return values
mixed

computeDelay()

Returns the current delay for a specified throttle rule.

protected computeDelay( $events : Collection , $throttleRule : ThrottleRule ) : int
Parameters
$events : Collection

a Collection of throttle events.

$throttleRule : ThrottleRule

a rule representing the strategy to use for throttling a particular type of event.

Return values
int

seconds remaining until a particular event is permitted to be attempted again.

Search results