PHP Class Dingo\Api\Http\RateLimit\Handler

Show file Open project: dingo/api Class Usage Examples

Protected Properties

Property Type Description
$cache Illuminate\Cache\CacheManager Cache instance.
$container Illuminate\Container\Container Container instance.
$keyPrefix string The key prefix used when throttling route specific requests.
$limiter callback A callback used to define the limiter.
$request Dingo\Api\Http\Request Request instance being throttled.
$throttle Dingo\Api\Contract\Http\RateLimit\Throttle Throttle used for rate limiting.
$throttles Illuminate\Support\Collection Registered throttles.

Public Methods

Method Description
__construct ( Illuminate\Container\Container $container, Illuminate\Cache\CacheManager $cache, array $throttles ) : void Create a new rate limit handler instance.
exceededRateLimit ( ) : boolean Determine if the rate limit has been exceeded.
extend ( callable | Dingo\Api\Http\RateLimit\Throttle $throttle ) : void Extend the rate limiter by adding a new throttle.
getRateLimitReset ( ) : integer Get the timestamp for when the current rate limiting will expire.
getRateLimiter ( ) : string Get the rate limiter.
getRemainingLimit ( ) : integer Get the remaining limit before the consumer is rate limited.
getThrottle ( ) : Dingo\Api\Contract\Http\RateLimit\Throttle Get the throttle used to rate limit the request.
getThrottleLimit ( ) : integer Get the limit of the throttle used.
rateLimitRequest ( Dingo\Api\Http\Request $request, integer $limit, integer $expires ) : void Execute the rate limiting for the given request.
requestWasRateLimited ( ) : boolean Determine if the request was rate limited.
setRateLimiter ( callable $limiter ) : void Set the rate limiter.
setThrottle ( string | Dingo\Api\Contract\Http\RateLimit\Throttle $throttle ) : void Set the throttle to use for rate limiting.

Protected Methods

Method Description
cache ( string $key, mixed $value, integer $minutes ) : void Cache a value under a given key for a certain amount of minutes.
forget ( string $key ) : void Forget a key in the cache.
getMatchingThrottles ( ) : Collection Get matching throttles after executing the condition of each throttle.
increment ( string $key ) : void Increment a key in the cache.
key ( string $key ) : string Namespace a cache key.
prepareCacheStore ( ) : void Prepare the cache store.
retrieve ( string $key ) : mixed Retrieve a value from the cache store.

Method Details

__construct() public method

Create a new rate limit handler instance.
public __construct ( Illuminate\Container\Container $container, Illuminate\Cache\CacheManager $cache, array $throttles ) : void
$container Illuminate\Container\Container
$cache Illuminate\Cache\CacheManager
$throttles array
return void

cache() protected method

Cache a value under a given key for a certain amount of minutes.
protected cache ( string $key, mixed $value, integer $minutes ) : void
$key string
$value mixed
$minutes integer
return void

exceededRateLimit() public method

Determine if the rate limit has been exceeded.
public exceededRateLimit ( ) : boolean
return boolean

extend() public method

Extend the rate limiter by adding a new throttle.
public extend ( callable | Dingo\Api\Http\RateLimit\Throttle $throttle ) : void
$throttle callable | Dingo\Api\Http\RateLimit\Throttle
return void

forget() protected method

Forget a key in the cache.
protected forget ( string $key ) : void
$key string
return void

getMatchingThrottles() protected method

Get matching throttles after executing the condition of each throttle.
protected getMatchingThrottles ( ) : Collection
return Illuminate\Support\Collection

getRateLimitReset() public method

Get the timestamp for when the current rate limiting will expire.
public getRateLimitReset ( ) : integer
return integer

getRateLimiter() public method

Get the rate limiter.
public getRateLimiter ( ) : string
return string

getRemainingLimit() public method

Get the remaining limit before the consumer is rate limited.
public getRemainingLimit ( ) : integer
return integer

getThrottle() public method

Get the throttle used to rate limit the request.
public getThrottle ( ) : Dingo\Api\Contract\Http\RateLimit\Throttle
return Dingo\Api\Contract\Http\RateLimit\Throttle

getThrottleLimit() public method

Get the limit of the throttle used.
public getThrottleLimit ( ) : integer
return integer

increment() protected method

Increment a key in the cache.
protected increment ( string $key ) : void
$key string
return void

key() protected method

Namespace a cache key.
protected key ( string $key ) : string
$key string
return string

prepareCacheStore() protected method

Prepare the cache store.
protected prepareCacheStore ( ) : void
return void

rateLimitRequest() public method

Execute the rate limiting for the given request.
public rateLimitRequest ( Dingo\Api\Http\Request $request, integer $limit, integer $expires ) : void
$request Dingo\Api\Http\Request
$limit integer
$expires integer
return void

requestWasRateLimited() public method

Determine if the request was rate limited.
public requestWasRateLimited ( ) : boolean
return boolean

retrieve() protected method

Retrieve a value from the cache store.
protected retrieve ( string $key ) : mixed
$key string
return mixed

setRateLimiter() public method

Set the rate limiter.
public setRateLimiter ( callable $limiter ) : void
$limiter callable
return void

setThrottle() public method

Set the throttle to use for rate limiting.
public setThrottle ( string | Dingo\Api\Contract\Http\RateLimit\Throttle $throttle ) : void
$throttle string | Dingo\Api\Contract\Http\RateLimit\Throttle
return void

Property Details

$cache protected property

Cache instance.
protected CacheManager,Illuminate\Cache $cache
return Illuminate\Cache\CacheManager

$container protected property

Container instance.
protected Container,Illuminate\Container $container
return Illuminate\Container\Container

$keyPrefix protected property

The key prefix used when throttling route specific requests.
protected string $keyPrefix
return string

$limiter protected property

A callback used to define the limiter.
protected callback $limiter
return callback

$request protected property

Request instance being throttled.
protected Request,Dingo\Api\Http $request
return Dingo\Api\Http\Request

$throttle protected property

Throttle used for rate limiting.
protected Throttle,Dingo\Api\Contract\Http\RateLimit $throttle
return Dingo\Api\Contract\Http\RateLimit\Throttle

$throttles protected property

Registered throttles.
protected Collection,Illuminate\Support $throttles
return Illuminate\Support\Collection