Class RequestFilter

Description

Extensible Request filtering

This class provides input filtering for request data provided through an UnifiedRequest object (what means you will have to name the arguments e.g. for XMLRPC requests first). It checks for the correct typing in cases where types are present (this is true for XMLRPC but not HTTP POST/GET) and provides you will correctly typed (php types) data.

It provides acccess to scalar types (string, boolean, integer, float) by default but is extensible through RequestFilterCustom objects.

Error handling can be done via two methods:

  • By default exceptions are thrown when an validation error occurs.
  • A UserErrorHandler may be provided to which all errors are passed. This means you will have to check for error yourself but are free in what you are doing with them (includes presenting more than one error at a time).

  • todo: Check what we can do with non-standard typed variables (like base64 in XMLRPC)

Located in /phpsatk-lib/global/org.eenterphace.sat.request.filter/request.filter.php (line 50)


	
			
Method Summary
RequestFilter __construct (UnifiedRequest $request)
void check (string $type, string $name)
mixed external (mixed $filter, string $name, [array $args = null], [mixed $value = null])
array getArray (string $name)
boolean getBoolean (string $name, [mixed $default = false])
float getFloat (string $name)
float getFloatNotNull (string $name)
int getInt (string $name)
int getIntNotNull (string $name)
string getString (string $name, [boolean $safe = true])
string getStringNotEmpty (string $name, [boolean $safe = true])
string getStringRegex (string $name, string $regex, [boolean $safe = true])
boolean isError ()
void setUserErrorHandler (UserErrorHandler $handler)
void userErrorHandler (string $message, string $field)
Methods
Constructor __construct (line 71)

Initialize a new Filter based on the given request data.

  • access: public
RequestFilter __construct (UnifiedRequest $request)
check (line 319)

Checks whether a given argument is avaialable in the given type.

Available types:

  • string
  • integer
  • float
  • boolean

  • access: public
void check (string $type, string $name)
  • string $type: Argument type
  • string $name: Argument name
external (line 397)

Validates a value using an external filter.

External filters are classes which implement RequestFilterCustom and implement one single method "filter" which performs specific tasks on the given argument and returns it on success or throws a RequestException.

Either a object of a class implementing RequestFilterCustom may be given as filter or some symbolic name - in this case a class providing "request.filter.$name" is searched and if present used as a filter.

  • access: public
mixed external (mixed $filter, string $name, [array $args = null], [mixed $value = null])
  • mixed $filter: Object of RequestFilterCustom or symbolic name
  • string $name: Argument name
  • array $args: Validator arguments
  • mixed $value: Special value to check (optional, use for chaining)
getArray (line 366)

Gets an array

Warning: array elements are not checked anyway.

  • access: public
array getArray (string $name)
  • string $name: Argument name
getBoolean (line 263)

Fetches a boolean value

Allows symbolic values ('true', 'yes' <-> 'false', 'no') additionally to 0/1.

  • access: public
boolean getBoolean (string $name, [mixed $default = false])
  • string $name: Argument name
getFloat (line 219)

Gets a floating point value

Returns zero if not present. Automatical conversion of decimal signs (',' to '.').

  • access: public
float getFloat (string $name)
  • string $name
getFloatNotNull (line 242)

Gets a float which mustn't be zero

float getFloatNotNull (string $name)
  • string $name: Argument name
getInt (line 178)

Gets a integer value

Will return zero if not set (can't check for this- at least using HTTP).

  • access: public
int getInt (string $name)
  • string $name: Variable name
getIntNotNull (line 199)

Gets a integer value which mustn't be zero

int getIntNotNull (string $name)
  • string $name: Argument name
getString (line 133)

Gets a string

If the safe parameter is set, all tags will automatically stripped off to provide safe content for output.

Returns an empty string if the argument is not given.

  • access: public
string getString (string $name, [boolean $safe = true])
  • string $name: Argument name
  • boolean $safe: Safe mode (strip tags)
getStringNotEmpty (line 159)

Gets a string which mustn't be empty

string getStringNotEmpty (string $name, [boolean $safe = true])
  • string $name: Variable name
  • boolean $safe: Safe mode (strip tags)
getStringRegex (line 295)

Fetches a string and valides by a regular expression (perl-style)

In safe mode tags are stripped off before applying the regex.

  • access: public
string getStringRegex (string $name, string $regex, [boolean $safe = true])
  • string $name: Argument name
  • string $regex: Regular expression to match
  • boolean $safe: Safe mode (strip tags)
isError (line 451)

Checks whether an error has occured.

Always returns false if there is no userErrorHandler.

  • access: public
boolean isError ()
setUserErrorHandler (line 87)

Sets a UserErrorHandler

If set no more exceptions will be thrown. You will have to decide for yourself, what you want to do with the errors given.

One example for a UserErrorHandler is the Output object. Request handlers 'should' present the errors stored there in some way, but you still need to react to the errors in you application.

  • access: public
void setUserErrorHandler (UserErrorHandler $handler)
userErrorHandler (line 437)

Invokes the userErrorHandler if present.

In case no userErrorHandler was set, throws a RequestException with the message passed. Otherwise the error will be added to the UserErrorHandler.

  • access: public
void userErrorHandler (string $message, string $field)
  • string $message: Error message
  • string $field: Field/Argument where the error occured

Documentation generated on Mon, 21 May 2007 10:35:15 +0200 by phpDocumentor 1.3.0RC5