Index

MMO\core\schemas

MMO\core\schemas · 7 symbols · generated 5 Oct 2026

function

arrayKeysType

schemas.php:201

The JSON-Schema type of a phpstan array (array<K, V>) according to the type of its keys: integers make a list (array), strings a map (object), anything else (array-key, int|string, mixed) either.

function arrayKeysType(string $keys): array
Namespace
MMO\core\schemas
$keysstringthe keys' type, e.g. int, string, non-empty-string, 'a'|'b'
returnsarray['array'], ['object'] or ['array', 'object']
arrayKeysType('int'); // ['array'] arrayKeysType('class-string'); // ['object'] arrayKeysType('int|string'); // ['array', 'object']
Call graph

Used by (1)

function

commentInformation

schemas.php:627

Extract schema keywords/metadata from a PHP doc comment (as returned by \ReflectionProperty::getDocComment() and similar), so a class's own docblocks can double as its JSON-Schema definition (Schema::FromClass).

function commentInformation(string|false $doc, string $namespace = ''): array
Namespace
MMO\core\schemas
Recognized tags: `@type`/`@var` (a [`parseType()`](https://mcp.mmoframework.fr/documentation/mmo.core/php/schemas.md#parsetype) type, `@var` also captures a trailing description -- its type is read the way phpstan writes it, [`typeLength()`](https://mcp.mmoframework.fr/documentation/mmo.core/php/schemas.md#typelength): `@var list<string> the genres`, and what the framework cannot check there is left unchecked, [`parseType()`](https://mcp.mmoframework.fr/documentation/mmo.core/php/schemas.md#parsetype)'s $lenient), a bare description line, `@label`, `@title`, `@description`, `@order`, `@icon`, `@view`, `@store`, `@hidden`, `@noindex`, `@required` (bare/true/false, or a comma-separated list of required property names), `@unique` (repeatable, each a comma-separated list of properties that must be unique together), and every keyword in PRIMITIVE_CONSTRAINTS (e.g. `@minimum`, `@pattern`, `@format`).
$docstring | falsea raw doc comment string (or false, e.g. when a property has none)
$namespace = ''stringpassed to parseType() to resolve class names in @type/@var
returnsarraya JSON-Schema-shaped array of whatever keywords were found
commentInformation("*\n * @var int the user's age\n * @required\n * @minimum 0\n *\/"); // ['type' => ['integer'], 'description' => "the user's age", 'required' => true, 'minimum' => '0']
Call graph
function

parseType

schemas.php:259

Parse this framework's compact type-description mini-language (used in doc comments, commentInformation(), and anywhere a schema is written by hand as a short string) into a JSON-Schema-shaped array.

function parseType( string $type, ?string $namespace = '', bool $inObject = false, bool $lenient = false ): array
Namespace
MMO\core\schemas
- simple types: `integer|number|string|boolean|null` (also accepts PHP's own `int`/`float`/`bool`) - string constant: `"xxx"` or `'xxx'` (a single quoted value becomes a `const`; several `|`-joined become an `enum`) - number constant: `12` or `12.5` - constant: `null` | `true` | `false` - array: `[types]` (items share one schema; you cannot declare per-index item types) - object: `{key: types, ..., ...: types}` (`...` -- or a bare type with no key at all -- describes additionalProperties) NOTE: a type containing `:` needs an explicit property name or `...` before it -- `{"a:b"}` is invalid, `{...: "a:b"}` is not. - class/enum instance: `\Fully\Qualified\Name` or, when $namespace is given, a name resolved against it - `*` alone (also `mixed`): matches anything (an empty/unconstrained schema); inside an object, `*` alone as a value (not a key) marks `additionalProperties` as allowed with no further constraint - phpstan's arrays, the way they are written in doc comments: `list<T>`, `array<T>`, `iterable<T>`, `T[]`, `(A|B)[]` and `array<int, T>` are the list `[T]`; `array<string, T>` is the map `{T}`; `array<K, T>` with any other key (`array-key`, `int|string`) is either. `non-empty-list<T>`/`non-empty-array<...>` read as the same (their `non-empty` is not checked); `mixed` items (`array<mixed>`) are not checked either, as a bare `array`'s. Other generic arguments are ignored: `\Traversable<int>` is a `\Traversable`, `int<0, 10>` an integer. Shortcut: a leading `?` on a type is equivalent to also unioning it with `|null` (`?list<T>` is `list<T>|null`). NOT implemented (reserved/rejected syntax): `enum(...)`, `not(...)`/`any(...)`/`all(...)`/`one(...)`, `self`/`this`, `void`.
$typestringthe type description to parse
$namespace = ''null | stringthe namespace to resolve an unqualified class name against. null disallows classes entirely.
$inObject = falseboolinternal: true while recursing into an object's {...} body
$lenient = falsebooltrue to read a doc comment's type, written for phpstan rather than for this framework: a name without a leading \ that is neither a type nor a class of $namespace (a class imported with use, non-empty-string, a template's T...) matches anything instead of being an error, and an array shape (array{id: int}) is any array. A \Qualified\Name that does not exist is still an error.
returnsarraya JSON-Schema-shaped array (Schema)
throwson malformed input (unterminated quote/array/object, unknown type, misplaced separator, ...)
parseType('?integer'); // ['type' => ['null', 'integer']] parseType('"a"|"b"|"c"'); // ['enum' => ['a', 'b', 'c']] parseType('[boolean|null]'); // ['type' => ['array'], 'items' => ['type' => ['boolean', 'null']]] parseType('list<string>'); // ['type' => ['array'], 'items' => ['type' => ['string']]] -- as '[string]' parseType('array<string, int>'); // ['type' => ['object'], 'additionalProperties' => ['type' => ['integer']]] parseType('{prop1: boolean, prop2: string, ...: *}'); // ['type' => ['object'], 'properties' => ['prop1' => [...], 'prop2' => [...]], 'additionalProperties' => true] parseType('DateTime|DateTimeImmutable'); // ['type' => ['instance'], 'instanceOf' => ['DateTime', 'DateTimeImmutable']]
Call graph
function

typeLength

schemas.php:164

The length of the type a text starts with, read the way phpstan reads a doc tag: in list<string> the genres, the type is list<string>. Brackets (<>, [], {}, ()) and quoted texts are skipped whole; outside them, the type ends at a space -- unless the space is next to a | (string | null) -- or at a character no type has (,, :, $...).

function typeLength(string $text, int $offset = 0): int
Namespace
MMO\core\schemas
$textstring
$offset = 0intwhere the type starts
returnsintthe type's length: 0 when the text does not start with one, or when a bracket is never closed
typeLength('list<string> the genres'); // 12 typeLength('string | null the name'); // 13 typeLength('array<string, int>, ...'); // 18 typeLength('the genres'); // 3 -- a word: whether it is a type is up to the caller
Call graph
function

typeOf

schemas.php:59

Get the JSON-Schema primitive type name of a PHP value (as used in a schema's type array).

function typeOf( mixed $value, bool $allowEmptyArray = true, bool $allowInteger = true, bool $numberAsBool = false ): string
Namespace
MMO\core\schemas
$valuemixed
$allowEmptyArray = trueboolif $value is an empty array, array is returned if this is true; else object (there is no way to tell an empty JSON list from an empty JSON object in PHP)
$allowInteger = trueboolif false, an int/float value is always number, never integer
$numberAsBool = falseboolif true, an int/float value that is exactly 0 or 1 is reported as boolean
returnsstringone of the TYPES constant's values ('instance' for any PHP object)
throwsfor a value type JSON-Schema has no equivalent for (e.g. a resource)
typeOf(5); // 'integer' typeOf(5.5); // 'number' typeOf(5.0, allowInteger: false); // 'number' -- forced, even though 5.0 has no fractional part typeOf([]); // 'array' (allowEmptyArray defaults true) typeOf([], false); // 'object' typeOf(['a' => 1]); // 'object' -- has a non-numeric key typeOf(new DateTime()); // 'instance'
Call graph
function

typeOfText

schemas.php:91

Guess the JSON-Schema type of a raw text value (e.g. a query-string/CLI argument, always a string at that point), the way a JSON parser would interpret it if it could: [...]/{...}-looking text is array/object, 'null'/'true'/'false' (any case) are their own types, a numeric string is integer or number, otherwise string.

function typeOfText(string $value, ?array $allowedTypes = null): ?string
Namespace
MMO\core\schemas
$valuestring
$allowedTypes = nullnull | arrayif given, constrains/steers the guess to these types (TYPES) -- e.g. a numeric string is reported as 'string' instead of 'integer' if 'integer' isn't in $allowedTypes but 'string' is; an empty string is 'null' if 'string' isn't allowed but 'null' is.
returnsnull | stringone of TYPES's values, or null if nothing in $allowedTypes could plausibly match
typeOfText('[1,2]'); // 'array' typeOfText('null'); // 'null' typeOfText('true'); // 'boolean' typeOfText('1.5'); // 'number' typeOfText('1', ['integer', 'string']); // 'integer' typeOfText('', ['null']); // 'null' -- empty string coerced since 'string' isn't allowed
function

validateFormat

schemas.php:536

Validate a string against a JSON-Schema format keyword value.

function validateFormat(string $value, string $format): bool
Namespace
MMO\core\schemas
An unrecognized $format always validates successfully (per spec: an implementation that doesn't understand a format attribute must not fail validation because of it -- `the` comment above the `default` case).
$valuestring
$formatstringone of: date, time, datetime, date-utc, datetime-u, color, style, phone, uri, uriref/uri-reference, email, ip-address/ipv4, ipv6, host-name/hostname
returnsbool
validateFormat('2024-01-01', 'date'); // true validateFormat('not-a-date', 'date'); // false validateFormat('#ff0000', 'color'); // true validateFormat('red', 'color'); // true -- named CSS color, @see COLORS validateFormat('a@b.com', 'email'); // true validateFormat('anything', 'some-unknown-format'); // true -- unknown formats are not enforced
Call graph