\Fubber\UtilErrors

This class provides validation functionality on objects and arrays.

Example:

<?php $errors = new Errors($array); // $array is a set of key-value pairs. However, the argument is optional

$errors->password('pass'); // Requires that the 'pass' property is at minimum 8 characters long and contains one number and one character $errors->required('username'); // The 'username' property is required $errors->minLen('username', 3'); // The 'username' property must be at least 3 characters $errors->email('email'); // The 'email' property must be a proper e-mail address

if($errors->pass != $errors->passConfirm) $errors->addError('passConfirm', 'Passwords do not match');

var_dump($errors->isInvalid()); // Prints NULL or an array of errors, where the key is the property name ?>

Summary

Methods
Properties
Constants
__construct()
__get()
__isset()
hasError()
addError()
isInvalid()
password()
minLen()
maxLen()
required()
email()
oneOf()
No public properties found
No constants found
No protected methods found
$_errors
$_val
N/A
No private methods found
No private properties found
N/A

Properties

$_errors

$_errors : 

Type

$_val

$_val : 

Type

Methods

__construct()

__construct(array|object|null  $val = null) 

Parameters

array|object|null $val

Pre-initialize the values.

__get()

__get(  $fieldname) 

Parameters

$fieldname

__isset()

__isset(  $fieldname) 

Parameters

$fieldname

hasError()

hasError(string  $fieldname) : boolean

Parameters

string $fieldname

Returns

boolean

addError()

addError(string  $fieldname, string  $error) : $this

Add a custom validation error

Parameters

string $fieldname
string $error

Returns

$this

isInvalid()

isInvalid() : array|false

Check if there are any validation errors

Returns

array|false

password()

password(string  $fieldname) : $this

Password validator for field

Parameters

string $fieldname

Returns

$this

minLen()

minLen(string  $fieldname, integer  $minLen) : $this

Minimum length validator for field

Parameters

string $fieldname
integer $minLen

Returns

$this

maxLen()

maxLen(string  $fieldname, integer  $maxLen) : $this

Maximum length validator for field

Parameters

string $fieldname
integer $maxLen

Returns

$this

required()

required(string  $fieldname) : $this

Field must not be empty

Parameters

string $fieldname

Returns

$this

email()

email(string  $fieldname) : $this

Field must be a valid e-mail address

Parameters

string $fieldname

Returns

$this

oneOf()

oneOf(string  $fieldname, array  $values) : $this

Field must be one of the supplied values

Parameters

string $fieldname
array $values

Returns

$this