Validator
MMO\core\schemas · 1 symbol · generated 5 Oct 2026
Validator
Validator.php:52Validates 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.
- Namespace
MMO\core\schemas- Implements
- IteratorAggregate
Index
| ERROR_TEMPLATES | Human-readable message template per keyword, used by toError. | |
| KEYS | Keywords this validator type checks (see getIterator) -- each subclass adds its own type-specific keywords on top of these type-agnostic ones. | |
| key | This validator's key/index within its $parent (e.g. | |
| parent | The validator for the enclosing value, or null at the root. | |
| schema readonly | The schema it's validated against. | |
| value readonly | The 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) static | 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). | |
| 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.
KEYS
Keywords this validator type checks (see getIterator) -- each subclass adds its own type-specific keywords on top of these type-agnostic ones.
Properties4
key
This validator's key/index within its $parent (e.g. a property name or array index), or '' at the root.
- Type
- string
parent
The validator for the enclosing value, or null at the root. setParent
schema
readonlyThe schema it's validated against.
- Type
- iSchema
value
readonlyThe value being validated.
- Type
- mixed
Methods16
createInPlaceValidator($schema)
Validator.php:197A 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 ''.
| $schema | Schema | aBoolSchema | |
| returns | Validator |
describeAssert($assert)
Validator.php:174What 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.
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).
| returns | Generator | Validator> |
getPath($join)
Validator.php:207isValidType($types)
Validator.php:243Reorder($value)
staticValidator.php:121Recursively 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)
Validator.php:185Attach this validator (for a nested value) under $validator, at $key (a property name or array index) -- used to build getPath.
toError($schemaPath)
Validator.php:146Build 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.
| $schemaPath | string | |
| returns | ValidatorError |
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).
| returns | Generator |
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.
| returns | Generator |
validate_const()
Validator.php:262'const': same as a single-value validate_enum.
| returns | Generator |
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.
| returns | Generator |
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.
| returns | Generator |
validate_not()
Validator.php:324'not': the value must NOT validate against the given schema.
| returns | Generator |
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.
| returns | Generator |