ObjectConstraint
extends Constraint
in package
The ObjectConstraint Constraints, validates an object against a given schema
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
- $appliedDefaults : array<string|int, mixed>
- $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.
- validateElement() : mixed
- Validates the element properties
- validatePatternProperties() : mixed
- validateProperties() : mixed
- Validates the definition properties
- 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
- getProperty() : mixed
- retrieves a property from an object or array
- getTypeCheck() : TypeCheckInterface
- Get the type check based on the set check mode.
- incrementPath() : mixed
- Bubble down the path
- validateMinMaxConstraint() : mixed
- validating minimum and maximum property constraints (if present) against an element
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
$appliedDefaults
protected
array<string|int, mixed>
$appliedDefaults
= array()
List of properties to which a default value has been applied
$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 &$element[, mixed $schema = null ][, JsonPointer $path = null ][, mixed $properties = null ][, mixed $additionalProp = null ][, mixed $patternProperties = null ][, mixed $appliedDefaults = array() ]) : mixed
Parameters
- $element : mixed
- $schema : mixed = null
- $path : JsonPointer = null
- $properties : mixed = null
- $additionalProp : mixed = null
- $patternProperties : mixed = null
- $appliedDefaults : mixed = array()
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
validateElement()
Validates the element properties
public
validateElement(StdClass $element, array<string|int, mixed> $matches[, StdClass $schema = null ][, JsonPointer|null $path = null ][, StdClass $properties = null ][, mixed $additionalProp = null ]) : mixed
Parameters
- $element : StdClass
-
Element to validate
- $matches : array<string|int, mixed>
-
Matches from patternProperties (if any)
- $schema : StdClass = null
-
ObjectConstraint definition
- $path : JsonPointer|null = null
-
Current test path
- $properties : StdClass = null
-
Properties
- $additionalProp : mixed = null
-
Additional properties
validatePatternProperties()
public
validatePatternProperties(mixed $element[, JsonPointer $path = null ], mixed $patternProperties) : mixed
Parameters
- $element : mixed
- $path : JsonPointer = null
- $patternProperties : mixed
validateProperties()
Validates the definition properties
public
validateProperties(stdClass &$element[, stdClass $properties = null ][, JsonPointer|null $path = null ]) : mixed
Parameters
- $element : stdClass
-
Element to validate
- $properties : stdClass = null
-
Property definitions
- $path : JsonPointer|null = null
-
Path?
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
getProperty()
retrieves a property from an object or array
protected
& getProperty(mixed &$element, string $property[, mixed $fallback = null ]) : mixed
Parameters
- $element : mixed
-
Element to validate
- $property : string
-
Property to retrieve
- $fallback : mixed = null
-
Default value if property is not found
getTypeCheck()
Get the type check based on the set check mode.
protected
getTypeCheck() : TypeCheckInterface
Return values
TypeCheckInterfaceincrementPath()
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
validateMinMaxConstraint()
validating minimum and maximum property constraints (if present) against an element
protected
validateMinMaxConstraint(stdClass $element, stdClass $objectDefinition[, JsonPointer|null $path = null ]) : mixed
Parameters
- $element : stdClass
-
Element to validate
- $objectDefinition : stdClass
-
ObjectConstraint definition
- $path : JsonPointer|null = null
-
Path to test?