Class Validator

Description

Interface to all framework's validators

The Validator class contains static methods to test a value or a list of values against a validator, based just on the validator class path, the validator arguments and the value(s) to be validated.

Examples:

  1.  /* simple value */
  2.  $value 'foo@bar.com';
  3.  if (Validator::validate('php2go.validation.EmailValidator'$value)) {
  4.    print 'valid e-mail!';
  5.  else {
  6.    print 'bad e-mail syntax!';
  7.  }
  8.  
  9.  /* multiple values */
  10.  $values array(1.242.01);
  11.  $wrongValues array();
  12.      'php2go.validation.MaxValidation'$values,
  13.      array('max'=>2)$wrongValues)
  14.  {
  15.    print 'values ok';
  16.  else {
  17.       print 'max exceeded! => wrong values: ' var_dump($wrongValues);
  18.  }

Located in /core/validation/Validator.class.php (line 67)

PHP2Go
   |
   --Validator
Variable Summary
array $errorStack
Method Summary
static void addError (string $msg)
static void clearErrors ()
static array getErrors ()
static bool validate (string $path, mixed &$value, [array $params = NULL], [string $userMessage = NULL])
static bool validateField (FormField &$Field, string $path, [array $params = NULL], [string $userMessage = NULL])
static bool validateMultiple (string $path, array $value, [array $params = NULL],  &$wrongValues, array $wrongValues)
Variables
array $errorStack = array() (line 74)

Error stack

Methods
static method addError (line 227)

Registers a validator error

static void addError (string $msg)
  • string $msg: Error message
static method clearErrors (line 248)

Clears all validation errors

static void clearErrors ()
static method getErrors (line 238)

Gets the collected error messages

static array getErrors ()
static method getInstance (line 82)

Get the singleton of the Validator class

static Validator &getInstance ()
static method validate (line 102)

Validates a value against a given validator

The $path argument must contain the path to the validator class, using "dot path" notation.

static bool validate (string $path, mixed &$value, [array $params = NULL], [string $userMessage = NULL])
  • string $path: Validator class path
  • mixed &$value: Value to be validated
  • array $params: Validator arguments
  • string $userMessage: User defined error message
static method validateField (line 148)

Used by the forms API to perform validations on form fields

The FormField instance is passed by reference, along with the validator path and arguments. Some validators might change the value of the field.

static bool validateField (FormField &$Field, string $path, [array $params = NULL], [string $userMessage = NULL])
  • FormField &$Field: Form field
  • string $path: Validator path
  • array $params: Validator arguments
  • string $userMessage: Customized error message
static method validateMultiple (line 187)

Runs a validation on multiple values

The failed values are collected and returned through the 4th parameter, $wrongValues, that sould be passed by reference.

Returns TRUE only when the validation returned TRUE for all values.

static bool validateMultiple (string $path, array $value, [array $params = NULL],  &$wrongValues, array $wrongValues)
  • string $path: Validator path
  • array $value: Values to be validated
  • array $params: Validator arguments
  • array $wrongValues: Used to return the wrong values
  • &$wrongValues

Inherited Methods

Inherited From PHP2Go

PHP2Go::PHP2Go()
PHP2Go::equals()
PHP2Go::generateUniqueId()
PHP2Go::getClassName()
PHP2Go::getConfigVal()
PHP2Go::getLangVal()
PHP2Go::getObjectName()
PHP2Go::getParentName()
PHP2Go::hasDestructor()
PHP2Go::hashCode()
PHP2Go::isA()
PHP2Go::isSubclassOf()
PHP2Go::logError()
PHP2Go::raiseError()
PHP2Go::registerDestructor()
PHP2Go::registerShutdownFunc()
PHP2Go::retrieve()
PHP2Go::store()
PHP2Go::__toString()

Documentation generated on Sun, 07 Oct 2007 19:31:05 -0300 by phpDocumentor 1.3.2