RequestCleaner

Created by on 2009–02-14. Copyright© 2009 Clove Technologies, Inc. All rights reserved. Licensed for general use under current version of GNU Public License

Usage

Create a new request cleaner:

$rc = new RequestCleaner(sources, use_modes, error_mode) – where:

For example:

$rc = new RequestCleaner(‘POST’, RequestCleaner::USE_HTMLENTITIES | RequestCleaner::USE_NL2BR,
RequestCleaner::THROW_EXCEPTION);

To get a ‘cleaned’ query parameter, use ’$rc->parm’, where parm is the parameter name. For example, if ‘foo’ is a POST parameter, then ’$rc->foo’ will return the value of ‘foo’ from after running the ‘cleaning’ routines on it.

Fine points

All Cleaned data is cached in a RequestCleaner Class Variable, as are the sources, use and error modes. This means that a top level PHP program can set up the method of cleaning and allowed sources and all included code which uses any instance of a RequestCleaner will use the same methods and cache.

Consequently, you can either create a RequestCleaner instance at top level OR in any included or required file which needs to access query parameters. It doesn’t matter.

Attempts to access undefined attributes generate an error – as specified by error_mode.

Query parameters which return arrays – as in <input type=... name=“foo[]” ...> – are turned into arrays of cleaned strings which can be processed using normal loops and array_…() functions.

Extensive use of Magic Methods are used to implement the following operations [presume that $rc is an instance of RequestCleaner]:

Instance Methods

ERROR_MODE_MASK = 3.

RETURN_NULL = 1.

RETURN_FALSE = 2.

THROW_EXCEPTION = 3.

USE_HTMLENTITIES = 1.

USE_HTMLSPECIALCHARS = 2.

USE_NL2BR = 4.