TypeConstraint
extends Constraint
in package
The TypeConstraint Constraints, validates an element against a given type
Tags
Table of Contents
Constants
- CHECK_MODE_APPLY_DEFAULTS = 0x8
- CHECK_MODE_COERCE_TYPES = 0x4
- CHECK_MODE_DISABLE_FORMAT = 0x20
- CHECK_MODE_EXCEPTIONS = 0x10
- CHECK_MODE_NONE = 0x0
- CHECK_MODE_NORMAL = 0x1
- CHECK_MODE_ONLY_REQUIRED_DEFAULTS = 0x80
- CHECK_MODE_TYPE_CAST = 0x2
- CHECK_MODE_VALIDATE_SCHEMA = 0x100
Properties
- $wording : array<string|int, mixed>|array<string|int, string>
- $errorMask : int
- $errors : array<string|int, mixed>
- $factory : Factory
- $inlineSchemaProperty : mixed
Methods
- __construct() : mixed
- addError() : mixed
- addErrors() : mixed
- arrayToObjectRecursive() : object
- Recursively cast an associative array to an object
- check() : mixed
- invokes the validation of an element
- getErrorMask() : int
- Get the error mask
- getErrors() : mixed
- isValid() : mixed
- numErrors() : mixed
- reset() : mixed
- Clears any reported errors. Should be used between multiple validation checks.
- checkArray() : mixed
- Validates an array
- checkEnum() : mixed
- Checks a enum element
- checkFormat() : mixed
- Checks format of an element
- checkNumber() : mixed
- Checks a number element
- checkObject() : mixed
- Validates an object
- checkString() : mixed
- Checks a string element
- checkType() : mixed
- Validates the type of a property
- checkUndefined() : mixed
- Checks a undefined element
- convertJsonPointerIntoPropertyPath() : string
- getTypeCheck() : TypeCheckInterface
- Get the type check based on the set check mode.
- implodeWith() : string
- Implodes the given array like implode() with turned around parameters and with the difference, that, if $listEnd isn't false, the last element delimiter is $listEnd instead of $delimiter.
- incrementPath() : mixed
- Bubble down the path
- toBoolean() : bool|mixed
- Converts a value to boolean. For example, "true" becomes true.
- toInteger() : mixed
- toNumber() : int|float|mixed
- Converts a numeric string to a number. For example, "4" becomes 4.
- validateType() : bool
- Verifies that a given value is of a certain type
- validateTypeNameWording() : mixed
- Validates the given $type, if there's an associated self::$wording. If not, throws an exception.
- validateTypesArray() : mixed
- Validates the given $value against the array of types in $type. Sets the value of $isValid to true, if at least one $type mateches the type of $value or the value passed as $isValid is already true.
Constants
CHECK_MODE_APPLY_DEFAULTS
public
mixed
CHECK_MODE_APPLY_DEFAULTS
= 0x8
CHECK_MODE_COERCE_TYPES
public
mixed
CHECK_MODE_COERCE_TYPES
= 0x4
CHECK_MODE_DISABLE_FORMAT
public
mixed
CHECK_MODE_DISABLE_FORMAT
= 0x20
CHECK_MODE_EXCEPTIONS
public
mixed
CHECK_MODE_EXCEPTIONS
= 0x10
CHECK_MODE_NONE
public
mixed
CHECK_MODE_NONE
= 0x0
CHECK_MODE_NORMAL
public
mixed
CHECK_MODE_NORMAL
= 0x1
CHECK_MODE_ONLY_REQUIRED_DEFAULTS
public
mixed
CHECK_MODE_ONLY_REQUIRED_DEFAULTS
= 0x80
CHECK_MODE_TYPE_CAST
public
mixed
CHECK_MODE_TYPE_CAST
= 0x2
CHECK_MODE_VALIDATE_SCHEMA
public
mixed
CHECK_MODE_VALIDATE_SCHEMA
= 0x100
Properties
$wording
public
static array<string|int, mixed>|array<string|int, string>
$wording
= array(
'integer' => 'an integer',
'number' => 'a number',
'boolean' => 'a boolean',
'object' => 'an object',
'array' => 'an array',
'string' => 'a string',
'null' => 'a null',
'any' => null,
// validation of 'any' is always true so is not needed in message wording
0 => null,
)
type wordings for validation error messages
$errorMask
protected
int
$errorMask
= \JsonSchema\Validator::ERROR_NONE
All error types which have occurred
$errors
protected
array<string|int, mixed>
$errors
= array()
Errors
$factory
protected
Factory
$factory
$inlineSchemaProperty
protected
mixed
$inlineSchemaProperty
= '$schema'
Methods
__construct()
public
__construct([Factory $factory = null ]) : mixed
Parameters
- $factory : Factory = null
addError()
public
addError([JsonPointer $path = null ], mixed $message[, mixed $constraint = '' ][, array<string|int, mixed> $more = null ]) : mixed
Parameters
- $path : JsonPointer = null
- $message : mixed
- $constraint : mixed = ''
- $more : array<string|int, mixed> = null
addErrors()
public
addErrors(array<string|int, mixed> $errors) : mixed
Parameters
- $errors : array<string|int, mixed>
arrayToObjectRecursive()
Recursively cast an associative array to an object
public
static arrayToObjectRecursive(array<string|int, mixed> $array) : object
Parameters
- $array : array<string|int, mixed>
Return values
objectcheck()
invokes the validation of an element
public
check([mixed &$value = null ][, mixed $schema = null ][, JsonPointer $path = null ][, mixed $i = null ]) : mixed
Parameters
- $value : mixed = null
- $schema : mixed = null
- $path : JsonPointer = null
- $i : mixed = null
getErrorMask()
Get the error mask
public
getErrorMask() : int
Return values
intgetErrors()
public
getErrors([mixed $errorContext = Validator::ERROR_ALL ]) : mixed
Parameters
- $errorContext : mixed = Validator::ERROR_ALL
isValid()
public
isValid() : mixed
numErrors()
public
numErrors([mixed $errorContext = Validator::ERROR_ALL ]) : mixed
Parameters
- $errorContext : mixed = Validator::ERROR_ALL
reset()
Clears any reported errors. Should be used between multiple validation checks.
public
reset() : mixed
checkArray()
Validates an array
protected
checkArray(mixed &$value[, mixed $schema = null ][, JsonPointer|null $path = null ][, mixed $i = null ]) : mixed
Parameters
- $value : mixed
- $schema : mixed = null
- $path : JsonPointer|null = null
- $i : mixed = null
checkEnum()
Checks a enum element
protected
checkEnum(mixed $value[, mixed $schema = null ][, JsonPointer|null $path = null ][, mixed $i = null ]) : mixed
Parameters
- $value : mixed
- $schema : mixed = null
- $path : JsonPointer|null = null
- $i : mixed = null
checkFormat()
Checks format of an element
protected
checkFormat(mixed $value[, mixed $schema = null ][, JsonPointer|null $path = null ][, mixed $i = null ]) : mixed
Parameters
- $value : mixed
- $schema : mixed = null
- $path : JsonPointer|null = null
- $i : mixed = null
checkNumber()
Checks a number element
protected
checkNumber(mixed $value[, mixed $schema = null ][, JsonPointer $path = null ][, mixed $i = null ]) : mixed
Parameters
- $value : mixed
- $schema : mixed = null
- $path : JsonPointer = null
- $i : mixed = null
checkObject()
Validates an object
protected
checkObject(mixed &$value[, mixed $schema = null ][, JsonPointer|null $path = null ][, mixed $properties = null ][, mixed $additionalProperties = null ][, mixed $patternProperties = null ][, mixed $appliedDefaults = array() ]) : mixed
Parameters
- $value : mixed
- $schema : mixed = null
- $path : JsonPointer|null = null
- $properties : mixed = null
- $additionalProperties : mixed = null
- $patternProperties : mixed = null
- $appliedDefaults : mixed = array()
checkString()
Checks a string element
protected
checkString(mixed $value[, mixed $schema = null ][, JsonPointer|null $path = null ][, mixed $i = null ]) : mixed
Parameters
- $value : mixed
- $schema : mixed = null
- $path : JsonPointer|null = null
- $i : mixed = null
checkType()
Validates the type of a property
protected
checkType(mixed &$value[, mixed $schema = null ][, JsonPointer|null $path = null ][, mixed $i = null ]) : mixed
Parameters
- $value : mixed
- $schema : mixed = null
- $path : JsonPointer|null = null
- $i : mixed = null
checkUndefined()
Checks a undefined element
protected
checkUndefined(mixed &$value[, mixed $schema = null ][, JsonPointer|null $path = null ][, mixed $i = null ][, mixed $fromDefault = false ]) : mixed
Parameters
- $value : mixed
- $schema : mixed = null
- $path : JsonPointer|null = null
- $i : mixed = null
- $fromDefault : mixed = false
convertJsonPointerIntoPropertyPath()
protected
convertJsonPointerIntoPropertyPath(JsonPointer $pointer) : string
Parameters
- $pointer : JsonPointer
Return values
string —property path
getTypeCheck()
Get the type check based on the set check mode.
protected
getTypeCheck() : TypeCheckInterface
Return values
TypeCheckInterfaceimplodeWith()
Implodes the given array like implode() with turned around parameters and with the difference, that, if $listEnd isn't false, the last element delimiter is $listEnd instead of $delimiter.
protected
implodeWith(array<string|int, mixed> $elements[, string $delimiter = ', ' ][, bool $listEnd = false ]) : string
Parameters
- $elements : array<string|int, mixed>
-
The elements to implode
- $delimiter : string = ', '
-
The delimiter to use
- $listEnd : bool = false
-
The last delimiter to use (defaults to $delimiter)
Return values
stringincrementPath()
Bubble down the path
protected
incrementPath([JsonPointer|null $path = null ], mixed $i) : mixed
Parameters
- $path : JsonPointer|null = null
-
Current path
- $i : mixed
-
What to append to the path
Tags
toBoolean()
Converts a value to boolean. For example, "true" becomes true.
protected
toBoolean(mixed $value) : bool|mixed
Parameters
- $value : mixed
-
The value to convert to boolean
Return values
bool|mixedtoInteger()
protected
toInteger(mixed $value) : mixed
Parameters
- $value : mixed
toNumber()
Converts a numeric string to a number. For example, "4" becomes 4.
protected
toNumber(mixed $value) : int|float|mixed
Parameters
- $value : mixed
-
the value to convert to a number
Return values
int|float|mixedvalidateType()
Verifies that a given value is of a certain type
protected
validateType(mixed &$value, string $type) : bool
Parameters
- $value : mixed
-
Value to validate
- $type : string
-
TypeConstraint to check against
Tags
Return values
boolvalidateTypeNameWording()
Validates the given $type, if there's an associated self::$wording. If not, throws an exception.
protected
validateTypeNameWording(string $type) : mixed
Parameters
- $type : string
-
The type to validate
Tags
validateTypesArray()
Validates the given $value against the array of types in $type. Sets the value of $isValid to true, if at least one $type mateches the type of $value or the value passed as $isValid is already true.
protected
validateTypesArray(mixed &$value, array<string|int, mixed> $type, array<string|int, mixed> &$validTypesWording, bool &$isValid, mixed $path) : mixed
Parameters
- $value : mixed
-
Value to validate
- $type : array<string|int, mixed>
-
TypeConstraints to check agains
- $validTypesWording : array<string|int, mixed>
-
An array of wordings of the valid types of the array $type
- $isValid : bool
-
The current validation value
- $path : mixed