MultiRequestProtection
in package
Class to prevent duplicated petitions.
Table of Contents
Constants
- CACHE_KEY = 'MultiRequestProtection'
- MAX_TOKEN_AGE = 4
- MAX_TOKENS = 500
- RANDOM_STRING_LENGTH = 6
Properties
- $seed : string
Methods
- __construct() : mixed
- addSeed() : void
- clearSeed() : void
- newToken() : string
- Generates a random token.
- tokenExist() : bool
- Validates if a petition token exist, otherwise save it.
- validate() : bool
- getRandomStr() : string
- getTokens() : array<string|int, mixed>
- saveToken() : bool
- Saves the new token to cache.
Constants
CACHE_KEY
public
mixed
CACHE_KEY
= 'MultiRequestProtection'
MAX_TOKEN_AGE
public
mixed
MAX_TOKEN_AGE
= 4
MAX_TOKENS
public
mixed
MAX_TOKENS
= 500
RANDOM_STRING_LENGTH
public
mixed
RANDOM_STRING_LENGTH
= 6
Properties
$seed
protected
static string
$seed
Methods
__construct()
public
__construct() : mixed
addSeed()
public
addSeed(string $seed) : void
Parameters
- $seed : string
clearSeed()
public
clearSeed() : void
newToken()
Generates a random token.
public
newToken() : string
Return values
stringtokenExist()
Validates if a petition token exist, otherwise save it.
public
tokenExist(string $token) : bool
Parameters
- $token : string
Return values
boolvalidate()
public
validate(string $token) : bool
Parameters
- $token : string
Return values
boolgetRandomStr()
protected
getRandomStr() : string
Return values
stringgetTokens()
protected
getTokens() : array<string|int, mixed>
Return values
array<string|int, mixed>saveToken()
Saves the new token to cache.
protected
saveToken(string $token) : bool
Parameters
- $token : string