utilityInputManager

The input manager aggregates a collection of utilityInputFilter instances into a single interface. It is used to filter GET and POST data and returns an array of filtered data. It relies on the PHP filter extension that is included by default in PHP >5.2.0.

The input manager can access data from GET, POST and data that is passed into the filtering method. The data source is set by calling utilityInputManager::setLookupGlobals(). For convenience, the various data types are available as class constants.

The filters can accept any flags as supported by the PHP filter extension.

The filtered data will always contain array keys matching the registered filters regardless of whether there was any data to filter.

Please note that in Scorpio data filtering is a separate step to data validation. While some of the filters can validate, the results should not be relied on. See utilityValidator for the validation solution.

Examples to filter $_GET data

$oManger = new utilityInputManager(utilityInputManager::LOOKUPGLOBALS_GET);
$oManger->addFilter("goto",utilityInputFilter::filterInt());
$filteredData = $oManger->doFilter();

Example to filter arbitrary data

$testData = array(
		'integer' => 123,
		'integerFalse' => 'adsf',
		'string' => 'asdf',
		'ip' => '192.168.0.212',
		'ipFalse' => '125.126.2.266',
		'nothing' => 'nothing',
);
$oManger = new utilityInputManager(utilityInputManager::LOOKUPGLOBALS_DATA);
$oManger->addFilter("integer",utilityInputFilter::filterInt());
$oManger->addFilter("integerFalse",utilityInputFilter::filterInt());
$oManger->addFilter("email",utilityInputFilter::filterValidateEmail());
$oManger->addFilter("emailFalse",utilityInputFilter::filterValidateEmail());
$oManger->addFilter("ip",utilityInputFilter::filterValidateIp());
$oManger->addFilter("ipFalse",utilityInputFilter::filterValidateIp());
$oManger->setData($testData);
$filteredData = $oManger->doFilter();

Methods

public __construct($inLookupGlobals)

Returns new utilityInputManager

private getLookupArray()

Returns data if current request is for LOOKUPGLOBALS_DATA

public doFilter([$inData = null])

filter filters the lookup globals or data

private _doFilterXml($inData)

looks through array and removes all the data

public getLookupGlobals()

Returns the current value of lookupGlobals

public setLookupGlobals($inlookupGlobals)

Set data type to filter on

public getFilter([$inKey = null])

Returns a filter for $inKey or false if none found

public setFilter($inKey, $inFilter)

Add a filter to mananger

public addFilter($inKey, $inFilter)

Add filter

public removeFilter($inKey)

Remove filter for $inKey

public clearFilters()

Removes all filters, resetting internal array

public getFilterCount()

Returns current number of filters in manager

public getData()

Returns data

public setData($indata)

Set data source

public getFilterAsXml()

Returns filtered XML data

public setFilterAsXml($inFilterXml)

Set XMl data to filter

<  1  >