Schema
MMO\core\schemas · 1 symbol · generated 30 Sep 2026
Schema
Schema.php:100Implementation of JSON Schema
- Namespace
MMO\core\schemas- Extends
- Container
- Implements
- iMutationObserver, iSchema
Index
| SCHEMAS_PROPERTY | ||
| SCHEMA_PROPERTY | ||
| anchors | ||
| addRequired($key) | Add $key to the 'required' list (a no-op if it's already there). | |
| coerce($value, $opts) | Coerce $value to match this schema's declared type(s), trying each in turn (Coercer::Coerce) -- 'enum'/'const' take priority (coerced to match one of the allowed values), 'instanceOf' adds the… | |
| coerceItem($key, $value, $opts) | ||
| coerceProperty($key, $value, $opts) | ||
| createValidator($value) | Build the right Validator subclass for $value, based on this schema's declared 'type' (or, if none, $value's own PHP type -- see typeOf). | |
| Defs($classes) static | Create a list of definition schema from a list of classes. | |
| Fetch($url) static | Same as Container::Fetch, ensuring the built-in global types (InitGlobalTypes) are registered first. | |
| From($schema, $parent) static | Build a schema from a flexible, convenient input. | |
| FromClass($class, $parent) static | ||
| FromEnum($class, $parent) static | Create a schema from an enum | |
| get($id, $default) | Same as Container::get, also checking the root schema's $anchor-registered sub-schemas (setContent) first. | |
| getAnchor() | ||
| getDefault() | Get schema default value. | |
| getDescription() | ||
| getIcon() | ||
| getInstanceTypes($recursive) | Collect every class/interface name this schema (and, per $recursive, its sub-schemas) could produce via 'instanceOf' -- used e.g. | |
| getItemSchema($index) | ||
| getLabel($content) | ||
| getLabelProperties() | ||
| getName() | ||
| getOrder() | ||
| getPHPClass() | ||
| getPropertySchema($key) | ||
| getSchema($path, $_cyclic) | Get the schema at the given path | |
| getSchemaFor($instancePath) | Get the schema for an object path (using 'properties' or 'items' sub schemas) | |
| getTitle($content) | Same as getLabel, for the 'title' keyword (falling back to getLabel if there's no 'title'). | |
| getTitleProperties() | ||
| getUniquePropertyGroups() | ||
| getVisibleProperties() | Get all the readable properties | |
| GlobalTypes() static | ||
| has($id) | NOTE: this used to check $this->anchors -- but anchors are only ever registered on the ROOT schema's | |
| hasDefault() | Tells if schema has a default value | |
| hasNoIndex() | ||
| InitGlobalTypes() static | Register the bare {"type": "..."} schema for each of TYPES globally, once. | |
| isDateTime() | Test if schema represents a datetime | |
| isInstanceOf($class, $direct) | Test if schema is an instance of a class | |
| isList() | ||
| isNullable() | NOTE: this used to omit the ??[] fallback that every other 'type'-array check in this class uses (e.g. | |
| isObject() | ||
| isPropertyNullable($key) | ||
| isString() | ||
| mutate($type, $path, $value, $oldValue) | ||
| printItem($value, $options) | Render one value for a {placeholder} in getLabel/getTitle's templates: an iEntity's title, a backed enum's value, a date as 'd/m/Y', or its plain string cast otherwise. | |
| RegisterGlobalType($id, $schema) static | Register a custom named schema globally, reachable afterward via its TypeId (e.g. | |
| resolve($url, $_cyclic) | Resolve a JSON Schema $ref (or any URI) to the schema it points to. | |
| resolveInstanceOf($allowEnum) | Get the schema associated to the first instanceOf | |
| setContent($content) | Load raw schema data: sets $id/registers an $anchor/$dynamicAnchor on the root, converts a $dynamicRef to a plain $ref (dynamic refs aren't otherwise supported), triggers mutate for … | |
| setId($id) | ||
| setType($type) | Set the type | |
| sort($array, $byKeys) | Order the keys of an array using the properties order | |
| toRegex($withDelimiter) | Build a regular expression matching (roughly) the same values this schema would accept -- useful e.g. | |
| TypeId($class) static | ||
| validate($value, $errors) | Validate a value through this schema | |
| walkSchemaFor($instancePath) | Walk through all the schema in a path, resolving the instanceOf on the way. |
Constants2
SCHEMAS_PROPERTY
SCHEMA_PROPERTY
Properties1
anchors
- Type
- array
Methods54
addRequired($key)
Schema.php:690Add $key to the 'required' list (a no-op if it's already there).
coerce($value, $opts)
Schema.php:872Coerce $value to match this schema's declared type(s), trying each in turn (Coercer::Coerce) -- 'enum'/'const' take priority (coerced to match one of the allowed values), 'instanceOf' adds the 'instance' type, and an untyped-but-structured schema ('properties' implies 'object', 'items'/'prefixItems' implies 'array') is coerced accordingly; a schema with no type information at all is left untouched.
coerceItem($key, $value, $opts)
Schema.php:919coerceProperty($key, $value, $opts)
Schema.php:909| $key | string | |
| $value | mixed | |
| $opts = [] | array | |
| returns | mixed | $value coerced per property $key's own schema (getPropertySchema), or returned unchanged if $key has none. |
createValidator($value)
Schema.php:929Build the right Validator subclass for $value, based on this schema's declared 'type' (or, if none, $value's own PHP type -- see typeOf).
Defs($classes)
staticSchema.php:122Create a list of definition schema from a list of classes.
Fetch($url)
staticSchema.php:272Same as Container::Fetch, ensuring the built-in global types (InitGlobalTypes) are registered first.
From($schema, $parent)
staticSchema.php:163Build a schema from a flexible, convenient input.
| $schema | iSchema | array | string | bool | an existing iSchema (returned as-is); a bool (TrueSchema/FalseSchema); a type name string (shorthand for ['type' => $schema]); or a raw schema array (a lone $ref key resolves against $parent immediately instead of building a new schema). |
| $parent = null | null | self | |
| returns | iSchema |
FromClass($class, $parent)
staticSchema.php:201FromEnum($class, $parent)
staticSchema.php:185Create a schema from an enum
get($id, $default)
Schema.php:280Same as Container::get, also checking the root schema's $anchor-registered sub-schemas (setContent) first.
getAnchor()
Schema.php:519getDefault()
Schema.php:579Get schema default value.
| returns | mixed |
getDescription()
Schema.php:559| returns | string | the 'description' keyword, or ''. |
getIcon()
Schema.php:569getInstanceTypes($recursive)
Schema.php:774Collect every class/interface name this schema (and, per $recursive, its sub-schemas) could produce via 'instanceOf' -- used e.g. by Defs to discover which classes' own schemas need registering.
getItemSchema($index)
Schema.php:723getLabel($content)
Schema.php:533| $content = null | ArrayAccess | array | null | if given and the schema has a 'label' template, render it against this data (renderTemplate, using printItem for each placeholder). |
| returns | string | the rendered label, or the raw 'label' template/'' if $content isn't given. |
getLabelProperties()
Schema.php:541| returns | array | property names referenced by the 'label' template's {placeholder}s. |
getName()
Schema.php:524getOrder()
Schema.php:564getPHPClass()
Schema.php:611getPropertySchema($key)
Schema.php:712getSchema($path, $_cyclic)
Schema.php:290Get the schema at the given path
getSchemaFor($instancePath)
Schema.php:352Get the schema for an object path (using 'properties' or 'items' sub schemas)
| $instancePath | array | string | |
| returns | null | iSchema | null if not known: a path through a property typed with an interface (walkSchemaFor) |
getTitle($content)
Schema.php:546Same as getLabel, for the 'title' keyword (falling back to getLabel if there's no 'title').
| $content = null | ArrayAccess | array | null | |
| returns | string |
getTitleProperties()
Schema.php:554| returns | array | property names referenced by the 'title' template's {placeholder}s. |
getUniquePropertyGroups()
Schema.php:685| returns | array | the 'uniquePropertyGroups' keyword (this framework's own extension: groups of properties whose combined values must be unique). |
getVisibleProperties()
Schema.php:699Get all the readable properties
| returns | array |
GlobalTypes()
staticSchema.php:262| returns | array | every globally-registered schema (the built-in types plus any RegisterGlobalType/FromClass/FromEnum ones), keyed by its bare id (without the schema: prefix). |
has($id)
Schema.php:364NOTE: this used to check $this->anchors -- but anchors are only ever registered on the ROOT schema's
- See
$anchors(setContent), same asget()correctly checks via$this->getRoot()->anchors. So has() only ever worked when called directly on the root; called on any nested sub-schema, it always missed an anchor that get() itself could find on that very same schema. Fixed to match get()'s own logic.
| $id | ||
| returns | bool |
hasDefault()
Schema.php:600Tells if schema has a default value
| returns | bool |
hasNoIndex()
Schema.php:633| returns | bool | the 'noindex' keyword (marks this schema/property as excluded from search indexing). |
InitGlobalTypes()
staticSchema.php:253Register the bare {"type": "..."} schema for each of TYPES globally, once. Called automatically wherever a global schema might be looked up (GlobalTypes/Fetch).
| returns | void |
isDateTime()
Schema.php:659Test if schema represents a datetime
| returns | bool |
isInstanceOf($class, $direct)
Schema.php:643Test if schema is an instance of a class
isList()
Schema.php:618| returns | bool | whether this schema describes a list (an explicit 'items' keyword, or 'array' in its 'type'). |
isNullable()
Schema.php:671NOTE: this used to omit the ??[] fallback that every other 'type'-array check in this class uses (e.g.
- See
isList/isObject/isString), so a schema with no 'type' keyword at all (a completely valid, common case -- e.g. a bare{"enum": [...]}) crashed with a TypeError instead of correctly answering "not nullable". Fixed to match the established pattern.
| returns | bool | whether this schema's 'type' includes 'null'. |
isObject()
Schema.php:623| returns | bool | whether this schema describes a map (an explicit 'properties' keyword, or 'object' in its 'type'). |
isPropertyNullable($key)
Schema.php:679| $key | string | |
| returns | bool | whether property $key's own schema is nullable (isNullable). |
isString()
Schema.php:628| returns | bool | whether this schema's 'type' includes 'string'. |
mutate($type, $path, $value, $oldValue)
Schema.php:440- See
iMutationObserverhook, invoked whenever a schema property is set/changed (including once for every top-level keyword right aftersetContentloads new content). Keeps this schema's internal invariants: schema-shaped properties (SCHEMA_PROPERTY/SCHEMAS_PROPERTY) are normalized into real Schema/,TrueSchema/FalseSchemainstances (viaFrom) as soon as they're set; 'type' is re-normalized (setType); a scalar 'instanceOf' is wrapped into a single-element array; and, on deletion, a removed sub-schema's anchor (if any) is unregistered from the root.
printItem($value, $options)
Schema.php:511Render one value for a {placeholder} in getLabel/getTitle's templates: an iEntity's title, a backed enum's value, a date as 'd/m/Y', or its plain string cast otherwise.
RegisterGlobalType($id, $schema)
staticSchema.php:247Register a custom named schema globally, reachable afterward via its TypeId (e.g. by $ref).
resolve($url, $_cyclic)
Schema.php:479Resolve a JSON Schema $ref (or any URI) to the schema it points to.
| $url | string | a bare fragment ('#', '#/path', '#anchorName'), a bare (possibly relative) URL, or a URL with a fragment -- resolved against this schema's root's own $id when relative. |
| $_cyclic = 10 | int | internal recursion guard. |
| returns | iSchema | |
| throws | if references form a cycle too deep to resolve ($_cyclic). | |
| throws | if $url points at something that isn't a valid schema. |
resolveInstanceOf($allowEnum)
Schema.php:315Get the schema associated to the first instanceOf
setContent($content)
Schema.php:379Load raw schema data: sets $id/registers an $anchor/$dynamicAnchor on the root, converts a $dynamicRef to a plain $ref (dynamic refs aren't otherwise supported), triggers mutate for every top-level keyword (so schema-shaped properties -- SCHEMA_PROPERTY/SCHEMAS_PROPERTY -- are converted into actual Schema/TrueSchema/FalseSchema instances), then, if a root-level $ref is present, resolves and merges it in (a $ref alongside other keywords -- unlike From's lone-$ref shortcut -- augments this schema rather than replacing it).
setId($id)
Schema.php:416setType($type)
Schema.php:751Set the type
sort($array, $byKeys)
Schema.php:733Order the keys of an array using the properties order
toRegex($withDelimiter)
Schema.php:816Build a regular expression matching (roughly) the same values this schema would accept -- useful e.g. for a route parameter pattern.
TypeId($class)
staticSchema.php:111validate($value, $errors)
Schema.php:955Validate a value through this schema
| $value | mixed | |
| $errors = null | null | array | if passed, this reference will hold all the errors encountered, keyed by the failing value's key: each has its keywordLocation (the schema's path where the validator failed) and its message; its JSON form (jsonSerialize) adds instanceLocation and names the message error |
| returns | bool | true if valid. if false $errors will contain the errors. |
walkSchemaFor($instancePath)
Schema.php:330Walk through all the schema in a path, resolving the instanceOf on the way.
| $instancePath | array | string | the path to walk to |
| returns | Generator | string $key => ?iSchema, null from the first key whose schema is not known |
| throws |
Inherited members (30)
| Constants | Declared by | Description | |
|---|---|---|---|
MAX_REFERENCE_DEPTH | Container |
| Methods | Declared by | Description | |
|---|---|---|---|
clear() | Container | Empty the underlying content, keeping the object itself. | |
count() | Container | \Countable::count | |
delete($id) | Container | Remove the value at $id and return it. | |
Exists($url) | Container | ||
getContent() | Container | ||
getId() | Container | ||
getIterator() | Container | \IteratorAggregate::getIterator | |
getParent() | Container | ||
getRoot() | Container | ||
inject($id, $config, $recursive) | Container | Merge $config into the content at $id (each of $config's own keys is injected at $id/$key). | |
isEmpty() | Container | ||
jsonSerialize($options) | Container | ||
keys() | Container | ||
load($configs) | Container | Merge one or more configs into this container's content (via inject). | |
loadArray($data) | Container | Load every entry of a plain array into the content, through offsetSet (so any offsetSet() override defined by the class using this trait, e.g. | |
offsetExists($key) | Container | \ArrayAccess::offsetExists | |
offsetGet($key) | Container | \ArrayAccess::offsetGet | |
offsetSet($key, $value) | Container | \ArrayAccess::offsetSet -- a null $key appends ($bag[] = $value), like a plain PHP array. | |
offsetUnset($key) | Container | \ArrayAccess::offsetUnset -- on a list (sequential integer keys, as produced by $bag[] = ...), the element is spliced out (closing the gap and reindexing), matching \unset() semantics on a plain … | |
push($id, $value, $create) | Container | Push a value in content | |
set($id, $value, $create) | Container | Set a value at $id, creating intermediate structure as needed. | |
toArray() | Container | Convert the content to a plain array, recursively converting any nested iArray value (e.g. | |
UnFetch($url) | Container | Forget the container registered under $url (it can be Fetch-ed again afterward, rebuilding it). | |
UnFetchAll() | Container | Forget every registered container. | |
__construct($content, $id, $parent) | Container | Create container |