Index

Validator

MMO\core\schemas · 1 symbol · generated 5 Oct 2026

class

Validator

Validator.php:52

Validates one value against one Schema (JSON Schema 2020-12 semantics), keyword by keyword. Iterating a Validator (it's an \IteratorAggregate) yields every validation failure as schemaPath => Validator pairs (the sub-validator whose value actually failed, at that keyword); an empty iteration means the value is valid -- this is what Schema::validate uses. Each JSON-Schema "instance type" (null/boolean/number/string/array object/instance) has its own subclass (NullValidator, NumberValidator, etc.) implementing just the keywords relevant to that type (KEYS) -- Schema::createValidator picks the right one for a value.

class MMO\core\schemas\Validator implements IteratorAggregate
Namespace
MMO\core\schemas
Implements
IteratorAggregate
$errors = []; $schema->validate($value, $errors); // true/false, $errors filled with ValidatorError on failureforeach ($schema->createValidator($value) as $schemaPath => $failingValidator) { echo $failingValidator->toError($schemaPath)->message; }

Index

ERROR_TEMPLATESHuman-readable message template per keyword, used by toError.
KEYSKeywords this validator type checks (see getIterator) -- each subclass adds its own type-specific keywords on top of these type-agnostic ones.
keyThis validator's key/index within its $parent (e.g.
parentThe validator for the enclosing value, or null at the root.
schema readonlyThe schema it's validated against.
value readonlyThe value being validated.
createInPlaceValidator($schema)A validator of this same value against another schema: an allOf/anyOf/oneOf branch, not, if/then/else, a dependent schema.
describeAssert($assert)What a failing keyword expected, as plain text: a list of types reads null|string.
getIterator()\IteratorAggregate::getIterator -- yields schemaPath => Validator for every keyword this value fails (the Validator being the (sub-)validator whose value actually failed that keyword, not necessa…
getPath($join)
isValidType($types)
Reorder($value) staticRecursively sort $value's keys (and, in turn, every nested array's keys), in place -- used before comparing two structures for equality regardless of key order (validate_enum/validate_const).
setParent($validator, $key)Attach this validator (for a nested value) under $validator, at $key (a property name or array index) -- used to build getPath.
toError($schemaPath)Build a human-readable error for a failing schema path (a key yielded by getIterator/a validate_* method), this validator being the one that failed.
validate_allOf()'allOf': the value must validate against every listed schema; each schema's own failures are all yielded (not just the first).
validate_anyOf()'anyOf': the value must validate against at least one listed schema; if none match, every schema's failures are yielded together.
validate_const()'const': same as a single-value validate_enum.
validate_enum()'enum': the value must strictly equal (order-independent for arrays/objects, and int/float-interchangeable for whole numbers) one of the declared constants.
validate_if()'if'/'then'/'else': validates against 'then' if the value matches 'if', otherwise against 'else' (each defaulting to TrueSchema, i.e.
validate_not()'not': the value must NOT validate against the given schema.
validate_oneOf()'oneOf': the value must validate against exactly one listed schema -- matching zero (all schemas' failures yielded) or more than one (a single "matched more than one" error) both fail.
__construct($schema, $value)

Constants2

ERROR_TEMPLATES

Human-readable message template per keyword, used by toError. {assert} is the keyword's own schema value, {key} this validator's $key, {value} the failing value -- but for dependentRequired, {assert} is the missing property and {key} the one requiring it.

const ERROR_TEMPLATES = […37 items]

KEYS

Keywords this validator type checks (see getIterator) -- each subclass adds its own type-specific keywords on top of these type-agnostic ones.

const KEYS = ['enum', 'const', 'allOf', 'anyOf', 'oneOf', 'not', 'if']

Properties4

key

This validator's key/index within its $parent (e.g. a property name or array index), or '' at the root.

string $key = ''
Type
string

parent

The validator for the enclosing value, or null at the root. setParent

?MMO\core\schemas\Validator $parent = null
Type
null | Validator

schema

readonly

The schema it's validated against.

readonly MMO\core\interfaces\iSchema $schema
Type
iSchema

value

readonly

The value being validated.

readonly mixed $value
Type
mixed

Methods16

createInPlaceValidator($schema)

Validator.php:197

A validator of this same value against another schema: an allOf/anyOf/oneOf branch, not, if/then/else, a dependent schema. It takes this one's place (same $parent, same $key): its errors are this value's -- detached, it reported a property's errors at the root, keyed ''.

protected function createInPlaceValidator(MMO\core\schemas\Schema|MMO\core\schemas\aBoolSchema $schema): MMO\core\schemas\Validator

describeAssert($assert)

Validator.php:174

What a failing keyword expected, as plain text: a list of types reads null|string. It used to go through \MMO\idump(), a debug dump -- array(2)0(4)null 1(6)string, and html markup in a web request.

protected function describeAssert(mixed $assert): string
$assertmixedthe keyword's value in the schema
returnsstring
$this->describeAssert(['null', 'string']); // 'null|string'$this->describeAssert(0); // '0'

getIterator()

Validator.php:224

\IteratorAggregate::getIterator -- yields schemaPath => Validator for every keyword this value fails (the Validator being the (sub-)validator whose value actually failed that keyword, not necessarily $this).

function getIterator(): GeneratorA `false` boolean schema always fails; a `true` one never does; otherwise, a type mismatch ([`isValidType`](https://mcp.mmoframework.fr/documentation/mmo.core/php/schemas/Validator.md#validator-isvalidtype)) short-circuits everything else, and each type-agnostic/type-specific keyword present in the schema ([`KEYS`](https://mcp.mmoframework.fr/documentation/mmo.core/php/schemas/Validator.md#validator-keys)) is checked via its own `validate_{keyword}()` method.
returnsGeneratorValidator>

getPath($join)

Validator.php:207
function getPath(bool $join = true): array|string
$join = trueboolif true (default), a single JSON-pointer-style path string; if false, the raw list of key segments.
returnsarray | stringthis validator's value's location within the overall validated document, root-to-here (via $parent/$key).

isValidType($types)

Validator.php:243
function isValidType(array $types): bool
$typesarraythe schema's declared 'type' list.
returnsboolwhether this validator's value type is among them. Overridden per-type; this base (untyped) implementation always accepts.

Reorder($value)

staticValidator.php:121

Recursively sort $value's keys (and, in turn, every nested array's keys), in place -- used before comparing two structures for equality regardless of key order (validate_enum/validate_const).

static function Reorder(array &$value): void
$valuearray
returnsvoid

setParent($validator, $key)

Validator.php:185

Attach this validator (for a nested value) under $validator, at $key (a property name or array index) -- used to build getPath.

function setParent(MMO\core\schemas\Validator $validator, string|int $key)
$validatorValidator
$keystring | int
returns

toError($schemaPath)

Validator.php:146

Build a human-readable error for a failing schema path (a key yielded by getIterator/a validate_* method), this validator being the one that failed. The message template is looked up by walking $schemaPath's segments from the end until one matches a key in ERROR_TEMPLATES (e.g. for 'properties/age/maximum', that's 'maximum' itself; for a bare keyword name it's immediate) -- except for 'dependentRequired/{property}/{missing}', which ends with two property names.

function toError(string $schemaPath): MMO\core\schemas\ValidatorError
$schemaPathstring
returnsValidatorError

validate_allOf()

Validator.php:276

'allOf': the value must validate against every listed schema; each schema's own failures are all yielded (not just the first).

protected function validate_allOf(): Generator
returnsGenerator

validate_anyOf()

Validator.php:287

'anyOf': the value must validate against at least one listed schema; if none match, every schema's failures are yielded together.

protected function validate_anyOf(): Generator
returnsGenerator

validate_enum()

Validator.php:248

'enum': the value must strictly equal (order-independent for arrays/objects, and int/float-interchangeable for whole numbers) one of the declared constants.

protected function validate_enum(): Generator
returnsGenerator

validate_if()

Validator.php:333

'if'/'then'/'else': validates against 'then' if the value matches 'if', otherwise against 'else' (each defaulting to TrueSchema, i.e. "always passes", when absent) -- 'if' itself never produces an error on its own.

protected function validate_if(): Generator
returnsGenerator

validate_not()

Validator.php:324

'not': the value must NOT validate against the given schema.

protected function validate_not(): Generator
returnsGenerator

validate_oneOf()

Validator.php:303

'oneOf': the value must validate against exactly one listed schema -- matching zero (all schemas' failures yielded) or more than one (a single "matched more than one" error) both fail.

protected function validate_oneOf(): Generator
returnsGenerator