Documentation

ValidationUtility

Validation utility.

Table of Contents

ensureBoolean()  : mixed
Ensure that the type of the given object is `boolean`.
ensureInteger()  : mixed
Ensure that the type of the given object is `integer`.
ensureNotNegative()  : mixed
Ensure that the given object is not less than 0.
ensureNotNull()  : mixed
Ensure that the given object is not `null`.
ensureNullOrArrayOfString()  : mixed
Ensure that the given object is null or an array of string.
ensureNullOrArrayOfType()  : mixed
Ensure that the given object is null or an array whose elements are of the specified type.
ensureNullOrString()  : mixed
Ensure that the given object is `null` or a `string` instance.
ensureNullOrStringOrInteger()  : mixed
Ensure that the given object is `null`, a `string` instance, or an `integer` instance.
ensureNullOrType()  : mixed
Ensure that the given object is `null` or an instance of the specified type.
ensureString()  : mixed
Ensure that the type of the given object is `string`.
ensureStringOrInteger()  : mixed
Ensure that the type of the given object is either `string` or `integer`.

Methods

ensureBoolean()

Ensure that the type of the given object is `boolean`.

public static ensureBoolean(string $name, mixed $value) : mixed
Parameters
$name : string

Name of a parameter.

$value : mixed

Value of a parameter.

Tags
throws
InvalidArgumentException

The type of $value is not boolean.

Return values
mixed —

ensureInteger()

Ensure that the type of the given object is `integer`.

public static ensureInteger(string $name, mixed $value) : mixed
Parameters
$name : string

Name of a parameter.

$value : mixed

Value of a parameter.

Tags
throws
InvalidArgumentException

The type of $value is not integer.

Return values
mixed —

ensureNotNegative()

Ensure that the given object is not less than 0.

public static ensureNotNegative(string $name, int $value) : mixed
Parameters
$name : string

Name of a parameter.

$value : int

Value of a parameter.

Tags
throws
InvalidArgumentException

$value is less than 0.

Return values
mixed —

ensureNotNull()

Ensure that the given object is not `null`.

public static ensureNotNull(string $name, mixed $value) : mixed
Parameters
$name : string

Name of a parameter.

$value : mixed

Value of a parameter.

Tags
throws
InvalidArgumentException

$value is null.

Return values
mixed —

ensureNullOrArrayOfString()

Ensure that the given object is null or an array of string.

public static ensureNullOrArrayOfString(string $name[, array<string|int, mixed> &$array = null ]) : mixed
Parameters
$name : string

Name of a parameter.

$array : array<string|int, mixed> = null

Value of a parameter.

Tags
throws
InvalidArgumentException

$array is neither null nor a reference of an array. Or the array has one or more non string elements.

Return values
mixed —

ensureNullOrArrayOfType()

Ensure that the given object is null or an array whose elements are of the specified type.

public static ensureNullOrArrayOfType(string $name[, array<string|int, mixed> &$array = null ], string $type) : mixed
Parameters
$name : string

Name of a parameter.

$array : array<string|int, mixed> = null

Value of a parameter.

$type : string

The expected type of the elements in the given array.

Tags
throws
InvalidArgumentException

$array is neither null nor a reference of an array. Or the array has one or more elements whose type is not the specified type.

Return values
mixed —

ensureNullOrString()

Ensure that the given object is `null` or a `string` instance.

public static ensureNullOrString(string $name, int $value) : mixed
Parameters
$name : string

Name of a parameter.

$value : int

Value of a parameter.

Tags
throws
InvalidArgumentException

$value is neither null nor a string instance.

Return values
mixed —

ensureNullOrStringOrInteger()

Ensure that the given object is `null`, a `string` instance, or an `integer` instance.

public static ensureNullOrStringOrInteger(string $name, int $value) : mixed
Parameters
$name : string

Name of a parameter.

$value : int

Value of a parameter.

Tags
throws
InvalidArgumentException

$value is not null, a string instance or an integer instance.

Return values
mixed —

ensureNullOrType()

Ensure that the given object is `null` or an instance of the specified type.

public static ensureNullOrType(string $name, int $value, string $type) : mixed
Parameters
$name : string

Name of a parameter.

$value : int

Value of a parameter.

$type : string

The expected type of the value.

Tags
throws
InvalidArgumentException

$value is neither null nor an instance of the specified type.

since
1.2
Return values
mixed —

ensureString()

Ensure that the type of the given object is `string`.

public static ensureString(string $name, mixed $value) : mixed
Parameters
$name : string

Name of a parameter.

$value : mixed

Value of a parameter.

Tags
throws
InvalidArgumentException

The type of $value is not string.

since
1.3
Return values
mixed —

ensureStringOrInteger()

Ensure that the type of the given object is either `string` or `integer`.

public static ensureStringOrInteger(string $name, int $value) : mixed
Parameters
$name : string

Name of a parameter.

$value : int

Value of a parameter.

Tags
throws
InvalidArgumentException

The type of $value is neither string nor integer.

Return values
mixed —

Search results