Coercer
MMO\core\schemas · 1 symbol · generated 30 Sep 2026
Coercer
Coercer.php:17Converter from one type to another.
- Namespace
MMO\core\schemas- Extends
- aCoercer
Index
| coerceArray($value, $options) | ||
| coerceBoolean($value, $options) | ||
| coerceDateTime($value, $options) | ||
| coerceDateTimeImmutable($value, $options) | Same as coerceDateTime, but returns a \DateTimeImmutable. | |
| coerceEntity($value, $options) | Coerce $value into an iEntity. | |
| coerceEnum($value, $options) | Coerce $value to match one of the schema's declared enum constants: each candidate constant's own PHP type is used to first try coercing $value to that same type, then compared strictly (===); if n… | |
| coerceInstance($value, $options) | Coerce $value into an instance of one of the declared candidate classes. | |
| coerceInteger($value, $options) | ||
| coerceNull($value, $options) | ||
| coerceNumber($value, $options) | ||
| coerceObject($value, $options) | ||
| coerceString($value, $options) | ||
| coerceTimestamp($value, $options) | ||
| __construct($config) |
Methods14
coerceArray($value, $options)
Coercer.php:77| $value | mixed | a JSON array string, or a plain (list) array. |
| $options | array | 'schema' (a Schema) coerces each item's value via Schema::coerceItem. |
| returns | ||
| throws | if $value isn't (or doesn't decode to) a list array. |
coerceBoolean($value, $options)
Coercer.php:145coerceDateTime($value, $options)
Coercer.php:355| $value | mixed | anything dateTime accepts (a string, timestamp, or DateTimeInterface). |
| $options | array | 'format': a DATE_FORMATS key, or a literal date() format string, to parse $value with. 'endOfDay': if true and the parsed time is exactly midnight (i.e. $value carried no time component), set it to 23:59:59 instead -- e.g. so a plain date used as a range's upper bound includes that whole day. |
| returns | DateTimeInterface | a mutable \DateTime. |
| throws | for a null value. |
coerceDateTimeImmutable($value, $options)
Coercer.php:363Same as coerceDateTime, but returns a \DateTimeImmutable.
| $value | mixed | |
| $options | array | |
| returns | DateTimeInterface |
coerceEntity($value, $options)
Coercer.php:281Coerce $value into an iEntity.
| $value | mixed | an array (with a 'uid' key, fetched by id via fetch and updated in place; or without one, used to build a new entity of whichever candidate class in $options['instanceOf'] best matches the array's keys against that class's required schema properties); an object already matching one of the candidate classes (returned as-is); or a string (an entity link/href, or a bare uid, resolved via fetch). |
| $options | array | 'instanceOf' (candidate entity classes), plus, for building a new non-embedded entity, 'repository'; for a new EmbeddedEntity, 'parent' and 'key'. |
| returns | ||
| throws | if $value can't be resolved to a valid entity. |
coerceEnum($value, $options)
Coercer.php:186Coerce $value to match one of the schema's declared enum constants: each candidate constant's own PHP type is used to first try coercing $value to that same type, then compared strictly (===); if no strict match is found but a string constant matches after normalization (normalize, e.g.
coerceInstance($value, $options)
Coercer.php:222Coerce $value into an instance of one of the declared candidate classes.
| $value | mixed | an object (returned as-is if it's already an instance of one of $options['instanceOf'], or if no 'instanceOf' is given at all -- any object is accepted); an array (built into a new instance of the first non-abstract, non-enum candidate class, via create -- Create); or a string/int (matched against an enum candidate's cases, via tryEnumFrom). |
| $options | array | 'instanceOf': candidate class/interface names, tried in order. A candidate that has its own registered coercer (aConverter::getClassFunction) is delegated to that instead of the generic logic above. |
| returns | ||
| throws | if $value matches none of the candidates. |
coerceInteger($value, $options)
Coercer.php:130coerceNull($value, $options)
Coercer.php:171coerceNumber($value, $options)
Coercer.php:118coerceObject($value, $options)
Coercer.php:50| $value | mixed | a JSON object string, or an associative array (or empty array). |
| $options | array | 'schema' (a Schema) coerces each property's value via Schema::coerceProperty. |
| returns | ||
| throws | if $value isn't (or doesn't decode to) an associative array/empty array. |
coerceString($value, $options)
Coercer.php:104coerceTimestamp($value, $options)
Coercer.php:375| $value | mixed | an int (used as-is), or anything coerceDateTime accepts. |
| $options | array | |
| returns | int | a Unix timestamp. |
__construct($config)
Coercer.php:19| $config | array |
Inherited members (63)
| Constants | Declared by | Description | |
|---|---|---|---|
ALERT | iLogLevel | Alert: Action must be taken immediately. | |
ALL | iLogLevel | Mask for all | |
ALL_PLUS | iLogLevel | debug everything | |
BACKTRACE | iLogLevel | ||
CRITICAL | iLogLevel | Critical: Critical conditions. | |
DEBUG | iLogLevel | Debug: Detailed debug information. | |
DEEP | iLogLevel | debug everything with arguments | |
EMERGENCY | iLogLevel | Emergency: System is unusable. | |
ERROR | iLogLevel | Error: Runtime errors that do not require immediate action but should typically be logged and monitored. | |
ERROR_PLUS | iLogLevel | Mask for all error | |
FATAL | iLogLevel | Mask for all fatal error | |
INFO | iLogLevel | Info: Interesting events. | |
INFO_PLUS | iLogLevel | Mask for all errors/warning/notices/info | |
MEMORY | iLogLevel | include backtrace object | |
NOTICE | iLogLevel | Notice: Normal but significant events. | |
NOTICE_PLUS | iLogLevel | Mask for all errors/warning/notices/info | |
TRACE | iLogLevel | include backtrace as origins | |
WARNING | iLogLevel | Warning: Exceptional occurrences that are not errors. | |
WARNING_PLUS | iLogLevel | Mask for all errors and warnings |
| Properties | Declared by | Description | |
|---|---|---|---|
functions | aConverter | ||
globalOptions | aConverter | ||
verbosity | aModule |
| Methods | Declared by | Description | |
|---|---|---|---|
addOptions($type, $options) | aConverter | Merge $options into $type's existing options (via merge), rather than replacing them wholesale like setOptions. | |
alert($message, $context) | aModule | Action must be taken immediately. | |
backtraces($message, $context) | aModule | Force-log a message at INFO level together with a full stack trace/memory snapshot (iLogLevel::BACKTRACE), bypassing the verbosity mask entirely (any non-zero verbosity is enough to trigger it). | |
call($type, $value, $options) | aConverter | Call the function associated to a type | |
clear() | aConverter | Remove every registered type/function. | |
Coerce($types, $value, $options) | aCoercer | ||
Configure($config) | aModule | Merge $config into this module's configuration in the shared Configuration. | |
critical($message, $context) | aModule | Critical conditions. No-op if CRITICAL is currently filtered out by the verbosity mask. | |
debug($message, $context) | aModule | Detailed debug information. | |
debugName() | aModule | Human-readable identifier used as the default {origin} in this instance's log messages. | |
DefaultConfig() | aModule | The config a module starts from before anything loaded via Configuration is merged in. | |
emergency($message, $context) | aModule | System is unusable. No-op if EMERGENCY is currently filtered out by the verbosity mask. | |
error($message, $context) | aModule | Runtime errors that do not require immediate action but should typically be logged and monitored. | |
getClassFunction($class) | aConverter | Find which registered type (a class or interface name) applies to $class: itself if directly registered, else the closest registered ancestor class or implemented interface. | |
getFunction($type) | aConverter | ||
getFunctions() | aConverter | ||
getOptions($type) | aConverter | ||
getType($value, $allowClass) | aConverter | Normalize $value's type into one of this converter's type names. | |
getVerbosity() | aModule | ||
hasType($type) | aConverter | ||
info($message, $context) | aModule | Interesting events. No-op if INFO is currently filtered out by the verbosity mask. | |
Instantiate($config) | aModule | (Re)create the shared instance immediately, configured with $config merged into the class's existing config. | |
IsShared() | aModule | ||
log($level, $message, $context) | aModule | Logs with an arbitrary level. | |
notice($message, $context) | aModule | Normal but significant events. | |
offsetExists($key) | aModule | \ArrayAccess::offsetExists -- tells whether $key is a declared property at all, regardless of whether it is currently readable/writable through array access. | |
offsetGet($key) | aModule | \ArrayAccess::offsetGet -- reads a property directly, unless it has a #[Serialize(serialize: 'methodName')] attribute, in which case that zero-argument method is called instead (e.g. | |
offsetSet($key, $value) | aModule | \ArrayAccess::offsetSet -- sets a property directly, unless it has a #[Serialize(unserialize: 'methodName')] attribute, in which case that method is called with $value instead (e.g. | |
offsetUnset($key) | aModule | \ArrayAccess::offsetUnset -- equivalent to $module[$key] = null. | |
serialize($path, $serializer) | aModule | \MMO\core\interfaces\iSerializable::serialize -- exports every property (via | |
setFunction($type, $fn, $options) | aConverter | Set a coercer | |
setFunctions($fns) | aConverter | Register many functions at once, e.g. | |
setOptions($type, $options) | aConverter | Replace $type's options wholesale. | |
setVerbosity($verb) | aModule | Set the current verbosity mask, replacing whatever it was before. | |
Shared() | aModule | Get the shared instance, creating (and configuring) it on first call. | |
testVerbosity($level) | aModule | Test whether a given level (or set of levels) is currently enabled by this instance's verbosity mask. | |
traitUnshare($serialize) | aModule | Remove the shared instance, so the next Shared() call creates a fresh one. | |
unserialize($data, $path, $instances) | aModule | \MMO\core\interfaces\iSerializable::unserialize -- merges $data onto DefaultConfig, runs it through the (possibly overridden) constructor, then applies each resulting value to its property (via | |
Unshare($serialize) | aModule | Like tSingleton::Unshare, but also disconnects this module's instance from every event it was listening to (via Event::DisconnectListeners) before dropping it. | |
warning($message, $context) | aModule | Exceptional occurrences that are not errors. | |
__invoke($value, $options, $types) | aCoercer | Try each of $types in turn (via aConverter::call), returning the result of the first one that doesn't throw an eInvalid. |