Spork Code Libraries

Db

Stores limit data in database table

Example MySQL table CREATE TABLE IF NOT EXISTS limit ( type varchar(32) NOT NULL, ip varchar(45) NOT NULL, timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, KEY type (type,ip), KEY timestamp (timestamp) ) ENGINE=InnoDB DEFAULT CHARSET=ascii;

Implements
\Spork\Mvc\Listener\Limit\Storage\StorageInterface

Properties

$cleanOnCheck

$cleanOnCheck : boolean

Should storage be cleaned when it is checked

Type

boolean

$cleanInterval

$cleanInterval : \Spork\DateTime\DateInterval

Remove data after this amount of time.

Type

\Spork\DateTime\DateInterval — | string

$dbAdapter

$dbAdapter : \Zend\Db\Adapter\Adapter

Database adapter

Type

\Zend\Db\Adapter\Adapter

$table

$table : string

Name of database table

Type

string

$typeColumn

$typeColumn : string

Name of type column

Type

string

$timestampColumn

$timestampColumn : string

Name of timestamp column

Type

string

$ipColumn

$ipColumn : string

Name of ip column

Type

string

Methods

__construct()

__construct(array  $options = array()) 

Configure instance

Parameters

array $options

setServiceLocator()

setServiceLocator(\Zend\ServiceManager\ServiceLocatorInterface  $serviceManager) 

Use Service Manager to inject database adapter

Parameters

\Zend\ServiceManager\ServiceLocatorInterface $serviceManager
See also

getServiceLocator()

getServiceLocator() 

Not Implemented

Throws

\Exception
See also

getCleanOnCheck()

getCleanOnCheck() : boolean

Get clean on check flag

Returns

boolean

setCleanOnCheck()

setCleanOnCheck(boolean  $flag) 

Set clean on check flag

Parameters

boolean $flag

setCleanInterval()

setCleanInterval(\Spork\Mvc\Listener\Limit\Storage\unknown  $interval) 

Set interval

Parameters

\Spork\Mvc\Listener\Limit\Storage\unknown $interval

getDbAdapter()

getDbAdapter() : \Zend\Db\Adapter\Adapter

Get database adapter

Returns

\Zend\Db\Adapter\Adapter

setDbAdapter()

setDbAdapter(\Zend\Db\Adapter\Adapter|string  $dbAdapter) : \Spork\Mvc\Listener\Limit\Storage\Db

Set database adapter or service name

Parameters

\Zend\Db\Adapter\Adapter|string $dbAdapter

Returns

\Spork\Mvc\Listener\Limit\Storage\Db

getTable()

getTable() : string

Get table name

Returns

string

getTypeColumn()

getTypeColumn() : string

Get type column name

Returns

string

setTypeColumn()

setTypeColumn(string  $typeColumn) : \Spork\Mvc\Listener\Limit\Storage\Db

Set type column name

Parameters

string $typeColumn

Returns

\Spork\Mvc\Listener\Limit\Storage\Db

getTimestampColumn()

getTimestampColumn() : string

Get timestamp column name

Returns

string

setTimestampColumn()

setTimestampColumn(string  $timestampColumn) : \Spork\Mvc\Listener\Limit\Storage\Db

Set timestamp column name

Parameters

string $timestampColumn

Returns

\Spork\Mvc\Listener\Limit\Storage\Db

getIpColumn()

getIpColumn() : string

Set IP column name

Returns

string

increment()

increment(\Spork\Mvc\Listener\Limit\Storage\unknown  $ip, \Spork\Mvc\Listener\Limit\Storage\unknown  $type) 

Add record to database

Parameters

\Spork\Mvc\Listener\Limit\Storage\unknown $ip
\Spork\Mvc\Listener\Limit\Storage\unknown $type
See also

check()

check(string  $ip, \Spork\Mvc\Listener\Limit\Limit  $limit) : boolean

Check if the number or records in the database exceeds the set limit

Parameters

string $ip
\Spork\Mvc\Listener\Limit\Limit $limit

Returns

boolean
See also

clean()

clean() 

Remove expired records from database

See also

assertReady()

assertReady() 

Assert database adapter is ready

Throws

\Exception

on database adapter not ready