\rex_validator

Validator class.

Summary

Methods
Properties
Constants
setFactoryClass()
getFactoryClass()
hasFactoryClass()
factory()
add()
addRule()
getRules()
isValid()
getMessage()
notEmpty()
type()
minLength()
maxLength()
min()
max()
url()
email()
match()
notMatch()
values()
custom()
No public properties found
No constants found
callFactoryClass()
__construct()
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

setFactoryClass()

setFactoryClass(string  $subclass) : mixed

Sets the class for the factory.

Parameters

string $subclass

Classname

Throws

\InvalidArgumentException

Returns

mixed —

getFactoryClass()

getFactoryClass() : string

Returns the class for the factory.

Returns

string —

hasFactoryClass()

hasFactoryClass() : bool

Returns if the class has a custom factory class.

Returns

bool —

factory()

factory() : static

Factory method.

Returns

static —

add()

add(string  $type, null|string  $message = null, mixed  $option = null) : $this

Adds a validation rule.

Parameters

string $type

Validator type (any static method name of this class)

null|string $message

Message which is used if this validator type does not match

mixed $option

Type specific option

Throws

\InvalidArgumentException

Returns

$this —

addRule()

addRule(\rex_validation_rule  $rule) : $this

Adds a validation rule.

Parameters

\rex_validation_rule $rule

Throws

\InvalidArgumentException

Returns

$this —

getRules()

getRules() : \rex_validation_rule[]

Returns

\rex_validation_rule[] —

isValid()

isValid(string  $value) : bool

Checks whether the given value matches all added validators.

Parameters

string $value

Returns

bool —

getMessage()

getMessage() : string|null

Returns the message.

Returns

string|null —

notEmpty()

notEmpty(string  $value) : bool

Checks whether the value is not empty.

Parameters

string $value

Returns

bool —

type()

type(string  $value, string  $type) : bool

Checks whether the value is from the given type.

Parameters

string $value
string $type

Throws

\InvalidArgumentException

Returns

bool —

minLength()

minLength(string  $value, int  $minLength) : bool

Checks whether the value has the given min length.

Parameters

string $value
int $minLength

Returns

bool —

maxLength()

maxLength(string  $value, int  $maxLength) : bool

Checks whether the value has the given max value.

Parameters

string $value
int $maxLength

Returns

bool —

min()

min(string  $value, int  $min) : bool

Checks whether the value is equal or greater than the given min value.

Parameters

string $value
int $min

Returns

bool —

max()

max(string  $value, int  $max) : bool

Checks whether the value is equal or lower than the given max value.

Parameters

string $value
int $max

Returns

bool —

url()

url(string  $value) : bool

Checks whether the value is an URL.

Parameters

string $value

Returns

bool —

email()

email(string  $value) : bool

Checks whether the value is an email address.

Parameters

string $value

Returns

bool —

match()

match(string  $value, string  $regex) : bool

Checks whether the value matches the given regex.

Parameters

string $value
string $regex

Returns

bool —

notMatch()

notMatch(string  $value, string  $regex) : bool

Checks whether the value does not match the given regex.

Parameters

string $value
string $regex

Returns

bool —

values()

values(string  $value, array  $validValues) : bool

Checks whether the value is one of the given valid values.

Parameters

string $value
array $validValues

Returns

bool —

custom()

custom(string  $value, callable  $callback) : bool

Checks the value by using the given callable.

Parameters

string $value
callable $callback

Returns

bool —

callFactoryClass()

callFactoryClass(string  $method, array  $arguments) : mixed

Calls the factory class with the given method and arguments.

Parameters

string $method

Method name

array $arguments

Array of arguments

Returns

mixed —

Result of the callback

__construct()

__construct() : mixed

Returns

mixed —