TrafficLimiter
extends AbstractPersistence
in package
TrafficLimiter
Handles traffic limiting, so no user does more than one call per 10 seconds.
Table of Contents
Properties
- $_store : AbstractData
- data storage to use to persist something
- $_creators : string|null
- listed IPs are the only ones allowed to create, defaults to null
- $_exempted : string|null
- listed IPs are exempted from limits, defaults to null
- $_ipKey : string
- key to fetch IP address
- $_limit : int
- time limit in seconds, defaults to 10s
Methods
- canPass() : true
- make sure the IP address is allowed to perfom a request
- getHash() : string
- get a HMAC of the current visitors IP address
- setConfiguration() : mixed
- set configuration options of the traffic limiter
- setCreators() : mixed
- set a list of creator IP(-ranges) as string
- setExempted() : mixed
- set a list of exempted IP(-ranges) as string
- setLimit() : mixed
- set the time limit in seconds
- setStore() : mixed
- set the path
- matchIp() : bool
- validate $_ipKey against configured ipranges. If matched we will ignore the ip
Properties
$_store
data storage to use to persist something
protected
static AbstractData
$_store
Tags
$_creators
listed IPs are the only ones allowed to create, defaults to null
private
static string|null
$_creators
= null
Tags
$_exempted
listed IPs are exempted from limits, defaults to null
private
static string|null
$_exempted
= null
Tags
$_ipKey
key to fetch IP address
private
static string
$_ipKey
= 'REMOTE_ADDR'
Tags
$_limit
time limit in seconds, defaults to 10s
private
static int
$_limit
= 10
Tags
Methods
canPass()
make sure the IP address is allowed to perfom a request
public
static canPass() : true
Tags
Return values
truegetHash()
get a HMAC of the current visitors IP address
public
static getHash([string $algo = 'sha512' ]) : string
Parameters
- $algo : string = 'sha512'
Tags
Return values
stringsetConfiguration()
set configuration options of the traffic limiter
public
static setConfiguration(Configuration $conf) : mixed
Parameters
- $conf : Configuration
Tags
setCreators()
set a list of creator IP(-ranges) as string
public
static setCreators(string $creators) : mixed
Parameters
- $creators : string
Tags
setExempted()
set a list of exempted IP(-ranges) as string
public
static setExempted(string $exempted) : mixed
Parameters
- $exempted : string
Tags
setLimit()
set the time limit in seconds
public
static setLimit(int $limit) : mixed
Parameters
- $limit : int
Tags
setStore()
set the path
public
static setStore(AbstractData $store) : mixed
Parameters
- $store : AbstractData
Tags
matchIp()
validate $_ipKey against configured ipranges. If matched we will ignore the ip
private
static matchIp([string $ipRange = null ]) : bool
Parameters
- $ipRange : string = null