PHP Class Inspekt\Cage

Inheritance: implements IteratorAggregate, implements ArrayAccess, implements Countable
Show file Open project: funkatron/inspekt Class Usage Examples

Public Properties

Property Type Description
$autofilter_conf array the holding property for autofilter config
$purifier HTMLPurifer
$user_accessors array where we store user-defined methods

Protected Properties

Property Type Description
$source ArrayObject Don't try to access this. ever. Now that we're safely on PHP5, we'll enforce this with the "protected" keyword.

Public Methods

Method Description
__call ( $name, $args ) : boolean | mixed
__construct ( ) : Cage
addAccessor ( string $accessor_name ) : void This method lets the developer add new accessor methods to a cage object Note that calling these will be quite a bit slower, because we have to use call_user_func()
count ( ) : integer Returns the number of elements in $this->source.
escMySQL ( string $key, resource $conn ) : boolean | mixed
escPgSQL ( $key, null $conn = null ) : boolean | mixed
escPgSQLBytea ( $key, null $conn = null ) : boolean | mixed
factory ( array &$source, string $conf_file = null, string $conf_section = null, boolean $strict = true ) : Cage Takes an array and wraps it inside an object. If $strict is not set to FALSE, the original array will be destroyed, and the data can only be accessed via the object's accessor methods
getAlnum ( mixed $key ) : mixed Returns only the alphabetic characters and digits in value.
getAlpha ( mixed $key ) : mixed Returns only the alphabetic characters in value.
getDigits ( mixed $key ) : mixed Returns only the digits in value. This differs from getInt().
getDir ( mixed $key ) : mixed Returns dirname(value).
getHTMLPurifier ( ) : HTMLPurifier
getInt ( mixed $key ) : integer Returns (int) value.
getIterator ( ) : ArrayIterator Returns an iterator for looping through an ArrayObject.
getPath ( mixed $key ) : mixed Returns realpath(value).
getPurifiedHTML ( string $key ) : mixed This returns the value of the given key passed through the HTMLPurifer object, if it is instantiated with Cage::loadHTMLPurifer
getROT13 ( string $key ) : mixed Returns ROT13-encoded version
getRaw ( string $key ) : mixed Returns value.
getValue ( string $key ) : mixed Retrieves a value from the source array. This should NOT be called directly, but needs to be public for use by AccessorAbstract. Maybe a different approach should be considered
keyExists ( mixed $key ) : boolean Checks if a key exists
loadHTMLPurifier ( mixed $opts = null ) Load the HTMLPurifier library and instantiate the object
noPath ( mixed $key ) : mixed Returns basename(value).
noTags ( mixed $key ) : mixed Returns value with all tags removed.
noTagsOrSpecial ( $key ) : array | boolean | mixed | string
offsetExists ( mixed $offset ) : boolean Returns whether the $offset exists in $this->source.
offsetGet ( mixed $offset ) : mixed Returns the value at $offset from $this->source.
offsetSet ( mixed $offset, mixed $value ) : void Sets the value at the specified $offset to value$ in $this->source.
offsetUnset ( mixed $offset ) : void Unsets the value in $this->source at $offset.
setHTMLPurifier ( HTMLPurifier $pobj )
testAlnum ( mixed $key ) : mixed Returns value if every character is alphabetic or a digit, FALSE otherwise.
testAlpha ( mixed $key ) : mixed Returns value if every character is alphabetic, FALSE otherwise.
testBetween ( mixed $key, mixed $min, mixed $max, boolean $inc = true ) : mixed Returns value if it is greater than or equal to $min and less than or equal to $max, FALSE otherwise. If $inc is set to FALSE, then the value must be strictly greater than $min and strictly less than $max.
testCcnum ( mixed $key, mixed $type = null ) : mixed Returns value if it is a valid credit card number format. The optional second argument allows developers to indicate the type.
testDate ( mixed $key ) : mixed Returns $value if it is a valid date, FALSE otherwise. The date is required to be in ISO 8601 format.
testDigits ( mixed $key ) : mixed Returns value if every character is a digit, FALSE otherwise.
testEmail ( mixed $key ) : mixed Returns value if it is a valid email format, FALSE otherwise.
testFloat ( mixed $key ) : mixed Returns value if it is a valid float value, FALSE otherwise.
testGreaterThan ( mixed $key, mixed $min = null ) : mixed Returns value if it is greater than $min, FALSE otherwise.
testHex ( mixed $key ) : mixed Returns value if it is a valid hexadecimal format, FALSE otherwise.
testHostname ( mixed $key, integer $allow = Inspekt::ISPK_HOST_ALLOW_ALL ) : mixed Returns value if it is a valid hostname, FALSE otherwise.
testInt ( mixed $key ) : mixed Returns value if it is a valid integer value, FALSE otherwise.
testIp ( mixed $key ) : mixed Returns value if it is a valid IP format, FALSE otherwise.
testLessThan ( mixed $key, mixed $max = null ) : mixed Returns value if it is less than $max, FALSE otherwise.
testOneOf ( mixed $key, null $allowed = null ) : mixed Returns value if it is one of $allowed, FALSE otherwise.
testPhone ( mixed $key, string $country = 'US' ) : mixed Returns value if it is a valid phone number format, FALSE otherwise. The optional second argument indicates the country.
testRegex ( mixed $key, mixed $pattern ) : mixed Returns value if it matches $pattern, FALSE otherwise. Uses preg_match() for the matching.
testUri ( string $key ) : boolean | string Enter description here.
testZip ( mixed $key ) : mixed Returns value if it is a valid US ZIP, FALSE otherwise.

Protected Methods

Method Description
applyAutoFilters ( )
buildHTMLPurifierConfig ( $opts ) : HTMLPurifier_Config
getValueOrNull ( $key ) : mixed
getValueRecursive ( $keys, $data_array, integer $level ) : boolean
keyExistsRecursive ( $keys, $data_array ) : boolean
parseAndApplyAutoFilters ( $conf_file, $conf_section )
setValue ( mixed $key, mixed $val ) : mixed Sets a value in the source array. Used by applyAutoFilters.
setValueRecursive ( $keys, $val, $data_array, integer $level ) : boolean

Private Methods

Method Description
setSource ( array &$newsource ) {@internal we use this to set the data array in factory()}}

Method Details

__call() public method

public __call ( $name, $args ) : boolean | mixed
$name
$args
return boolean | mixed

__construct() public method

public __construct ( ) : Cage
return Cage

addAccessor() public method

The dev needs to define a procedural function like so: function foo_bar($cage_object, $arg2, $arg3, $arg4, $arg5...) { ... }
Author: Ed Finkler
public addAccessor ( string $accessor_name ) : void
$accessor_name string
return void

applyAutoFilters() protected method

See also: Cage::parseAndApplyAutoFilters
protected applyAutoFilters ( )

buildHTMLPurifierConfig() protected method

protected buildHTMLPurifierConfig ( $opts ) : HTMLPurifier_Config
$opts
return HTMLPurifier_Config

count() public method

Returns the number of elements in $this->source.
public count ( ) : integer
return integer

escMySQL() public method

public escMySQL ( string $key, resource $conn ) : boolean | mixed
$key string
$conn resource a connection resource
return boolean | mixed

escPgSQL() public method

public escPgSQL ( $key, null $conn = null ) : boolean | mixed
$key
$conn null
return boolean | mixed

escPgSQLBytea() public method

public escPgSQLBytea ( $key, null $conn = null ) : boolean | mixed
$key
$conn null
return boolean | mixed

factory() public static method

Takes an array and wraps it inside an object. If $strict is not set to FALSE, the original array will be destroyed, and the data can only be accessed via the object's accessor methods
public static factory ( array &$source, string $conf_file = null, string $conf_section = null, boolean $strict = true ) : Cage
$source array
$conf_file string
$conf_section string
$strict boolean
return Cage

getAlnum() public method

Returns only the alphabetic characters and digits in value.
public getAlnum ( mixed $key ) : mixed
$key mixed
return mixed

getAlpha() public method

Returns only the alphabetic characters in value.
public getAlpha ( mixed $key ) : mixed
$key mixed
return mixed

getDigits() public method

Returns only the digits in value. This differs from getInt().
public getDigits ( mixed $key ) : mixed
$key mixed
return mixed

getDir() public method

Returns dirname(value).
public getDir ( mixed $key ) : mixed
$key mixed
return mixed

getHTMLPurifier() public method

public getHTMLPurifier ( ) : HTMLPurifier
return HTMLPurifier

getInt() public method

Returns (int) value.
public getInt ( mixed $key ) : integer
$key mixed
return integer

getIterator() public method

Returns an iterator for looping through an ArrayObject.

getPath() public method

Returns realpath(value).
public getPath ( mixed $key ) : mixed
$key mixed
return mixed

getPurifiedHTML() public method

This returns the value of the given key passed through the HTMLPurifer object, if it is instantiated with Cage::loadHTMLPurifer
public getPurifiedHTML ( string $key ) : mixed
$key string
return mixed purified HTML version of input

getROT13() public method

Returns ROT13-encoded version
public getROT13 ( string $key ) : mixed
$key string
return mixed

getRaw() public method

Returns value.
public getRaw ( string $key ) : mixed
$key string
return mixed

getValue() public method

Retrieves a value from the source array. This should NOT be called directly, but needs to be public for use by AccessorAbstract. Maybe a different approach should be considered
public getValue ( string $key ) : mixed
$key string
return mixed

getValueOrNull() protected method

protected getValueOrNull ( $key ) : mixed
$key
return mixed

getValueRecursive() protected method

protected getValueRecursive ( $keys, $data_array, integer $level ) : boolean
$keys
$data_array
$level integer
return boolean

keyExists() public method

Checks if a key exists
public keyExists ( mixed $key ) : boolean
$key mixed
return boolean

keyExistsRecursive() protected method

protected keyExistsRecursive ( $keys, $data_array ) : boolean
$keys
$data_array
return boolean

loadHTMLPurifier() public method

Load the HTMLPurifier library and instantiate the object
public loadHTMLPurifier ( mixed $opts = null )
$opts mixed options that are sent to HTMLPurifier. Optional

noPath() public method

Returns basename(value).
public noPath ( mixed $key ) : mixed
$key mixed
return mixed

noTags() public method

Returns value with all tags removed.
public noTags ( mixed $key ) : mixed
$key mixed
return mixed

noTagsOrSpecial() public method

public noTagsOrSpecial ( $key ) : array | boolean | mixed | string
$key
return array | boolean | mixed | string

offsetExists() public method

Returns whether the $offset exists in $this->source.
public offsetExists ( mixed $offset ) : boolean
$offset mixed
return boolean

offsetGet() public method

Returns the value at $offset from $this->source.
public offsetGet ( mixed $offset ) : mixed
$offset mixed
return mixed

offsetSet() public method

Sets the value at the specified $offset to value$ in $this->source.
public offsetSet ( mixed $offset, mixed $value ) : void
$offset mixed
$value mixed
return void

offsetUnset() public method

Unsets the value in $this->source at $offset.
public offsetUnset ( mixed $offset ) : void
$offset mixed
return void

parseAndApplyAutoFilters() protected method

See also: Cage::factory
protected parseAndApplyAutoFilters ( $conf_file, $conf_section )
$conf_file
$conf_section

setHTMLPurifier() public method

public setHTMLPurifier ( HTMLPurifier $pobj )
$pobj HTMLPurifier an HTMLPurifer Object

setValue() protected method

Sets a value in the source array. Used by applyAutoFilters.
See also: Cage::applyAutoFilters
protected setValue ( mixed $key, mixed $val ) : mixed
$key mixed
$val mixed
return mixed

setValueRecursive() protected method

See also: Cage::setValue
protected setValueRecursive ( $keys, $val, $data_array, integer $level ) : boolean
$keys
$val
$data_array
$level integer
return boolean

testAlnum() public method

Returns value if every character is alphabetic or a digit, FALSE otherwise.
public testAlnum ( mixed $key ) : mixed
$key mixed
return mixed

testAlpha() public method

Returns value if every character is alphabetic, FALSE otherwise.
public testAlpha ( mixed $key ) : mixed
$key mixed
return mixed

testBetween() public method

Returns value if it is greater than or equal to $min and less than or equal to $max, FALSE otherwise. If $inc is set to FALSE, then the value must be strictly greater than $min and strictly less than $max.
public testBetween ( mixed $key, mixed $min, mixed $max, boolean $inc = true ) : mixed
$key mixed
$min mixed
$max mixed
$inc boolean
return mixed

testCcnum() public method

Returns value if it is a valid credit card number format. The optional second argument allows developers to indicate the type.
public testCcnum ( mixed $key, mixed $type = null ) : mixed
$key mixed
$type mixed
return mixed

testDate() public method

Returns $value if it is a valid date, FALSE otherwise. The date is required to be in ISO 8601 format.
public testDate ( mixed $key ) : mixed
$key mixed
return mixed

testDigits() public method

This is just like isInt(), except there is no upper limit.
public testDigits ( mixed $key ) : mixed
$key mixed
return mixed

testEmail() public method

Returns value if it is a valid email format, FALSE otherwise.
public testEmail ( mixed $key ) : mixed
$key mixed
return mixed

testFloat() public method

Returns value if it is a valid float value, FALSE otherwise.
public testFloat ( mixed $key ) : mixed
$key mixed
return mixed

testGreaterThan() public method

Returns value if it is greater than $min, FALSE otherwise.
public testGreaterThan ( mixed $key, mixed $min = null ) : mixed
$key mixed
$min mixed
return mixed

testHex() public method

Returns value if it is a valid hexadecimal format, FALSE otherwise.
public testHex ( mixed $key ) : mixed
$key mixed
return mixed

testHostname() public method

Depending upon the value of $allow, Internet domain names, IP addresses, and/or local network names are considered valid. The default is HOST_ALLOW_ALL, which considers all of the above to be valid.
public testHostname ( mixed $key, integer $allow = Inspekt::ISPK_HOST_ALLOW_ALL ) : mixed
$key mixed
$allow integer bitfield for HOST_ALLOW_DNS, HOST_ALLOW_IP, HOST_ALLOW_LOCAL
return mixed

testInt() public method

Returns value if it is a valid integer value, FALSE otherwise.
public testInt ( mixed $key ) : mixed
$key mixed
return mixed

testIp() public method

Returns value if it is a valid IP format, FALSE otherwise.
public testIp ( mixed $key ) : mixed
$key mixed
return mixed

testLessThan() public method

Returns value if it is less than $max, FALSE otherwise.
public testLessThan ( mixed $key, mixed $max = null ) : mixed
$key mixed
$max mixed
return mixed

testOneOf() public method

Returns value if it is one of $allowed, FALSE otherwise.
public testOneOf ( mixed $key, null $allowed = null ) : mixed
$key mixed
$allowed null
return mixed

testPhone() public method

Returns value if it is a valid phone number format, FALSE otherwise. The optional second argument indicates the country.
public testPhone ( mixed $key, string $country = 'US' ) : mixed
$key mixed
$country string
return mixed

testRegex() public method

Returns value if it matches $pattern, FALSE otherwise. Uses preg_match() for the matching.
public testRegex ( mixed $key, mixed $pattern ) : mixed
$key mixed
$pattern mixed
return mixed

testUri() public method

..
public testUri ( string $key ) : boolean | string
$key string
return boolean | string

testZip() public method

Returns value if it is a valid US ZIP, FALSE otherwise.
public testZip ( mixed $key ) : mixed
$key mixed
return mixed

Property Details

$autofilter_conf public property

the holding property for autofilter config
public array $autofilter_conf
return array

$purifier public property

public HTMLPurifer $purifier
return HTMLPurifer

$source protected property

Don't try to access this. ever. Now that we're safely on PHP5, we'll enforce this with the "protected" keyword.
protected ArrayObject $source
return ArrayObject

$user_accessors public property

where we store user-defined methods
public array $user_accessors
return array