PHP Class Tools\Model\Table\TokensTable

Author: Mark Scherer
Inheritance: extends Table
Show file Open project: dereuromark/cakephp-tools Class Usage Examples

Public Properties

Property Type Description
$defaultLength integer
$displayField string
$order array
$validate array
$validity integer

Public Methods

Method Description
garbageCollector ( ) : boolean Remove old/invalid keys does not remove recently used ones (for proper feedback)!
generateKey ( integer | null $length = null ) : string Generator of secure random tokens.
newKey ( string $type, string | null $key = null, mixed | null $uid = null, string | array | null $content = null ) : string Stores new key in DB
spendKey ( integer $id ) : boolean Sets Key to "used" (only once!) - directly by ID
stats ( ) : array Get admin stats
useKey ( string $type, string $key, mixed | null $uid = null, boolean $treatUsedAsInvalid = false ) : array | false UsesKey (only once!) - by KEY

Method Details

garbageCollector() public method

Remove old/invalid keys does not remove recently used ones (for proper feedback)!
public garbageCollector ( ) : boolean
return boolean success

generateKey() public method

Note that it is best to use an even number for the length.
public generateKey ( integer | null $length = null ) : string
$length integer | null (defaults to defaultLength)
return string Key

newKey() public method

Stores new key in DB
public newKey ( string $type, string | null $key = null, mixed | null $uid = null, string | array | null $content = null ) : string
$type string Type: necessary
$key string | null Key: optional key, otherwise a key will be generated
$uid mixed | null Uid: optional (if used, only this user can use this key)
$content string | array | null Content: up to 255 characters of content may be added (optional) NOW: checks if this key is already used (should be unique in table)
return string key on SUCCESS, boolean false otherwise

spendKey() public method

Sets Key to "used" (only once!) - directly by ID
public spendKey ( integer $id ) : boolean
$id integer Id of key to spend: necessary
return boolean Success

stats() public method

Get admin stats
public stats ( ) : array
return array

useKey() public method

UsesKey (only once!) - by KEY
public useKey ( string $type, string $key, mixed | null $uid = null, boolean $treatUsedAsInvalid = false ) : array | false
$type string : necessary
$key string : necessary
$uid mixed | null : needs to be provided if this key has a user_id stored
$treatUsedAsInvalid boolean
return array | false Content - if successfully used or if already used (used=1), FALSE else

Property Details

$defaultLength public property

public int $defaultLength
return integer

$displayField public property

public string $displayField
return string

$order public property

public array $order
return array

$validate public property

public array $validate
return array

$validity public property

public int $validity
return integer