Index

aCoercer

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

class

aCoercer

aCoercer.php:23

An aConverter specialized for coercion: given an ordered list of acceptable $types, try to convert $value into the first one that accepts it (rather than aConverter's single-type aConverter::call, which requires the caller to already know the right type). Used by the schema system to coerce a raw input value against a type list like ['integer', 'string'].

abstract class MMO\core\classes\aCoercer extends MMO\core\classes\aConverter implements MMO\core\interfaces\iCoercer
Namespace
MMO\core\classes
Extends
aConverter
Implements
iCoercer
class MyCoercer extends aCoercer {} $c = MyCoercer::Shared(); $c->setFunction('integer', function ($v, $opts) { if (!is_numeric($v)) {throw new eInvalid('coerce', 'not numeric');} return (int)$v; }); $c->setFunction('string', fn($v, $opts) => (string)$v); MyCoercer::Coerce(['integer', 'string'], '42'); // (int) 42 -- 'integer' accepts it MyCoercer::Coerce(['integer', 'string'], 'hello'); // (string) 'hello' -- falls through to 'string'

Index

Coerce($types, $value, $options) static
__invoke($value, $options, $types)Try each of $types in turn (via aConverter::call), returning the result of the first one that doesn't throw an eInvalid.

Methods2

Coerce($types, $value, $options)

staticaCoercer.php:32
static function Coerce(array $types, mixed $value, array $options = []): mixed
$typesarraythe acceptable types, in preference order (see __invoke for the one exception: 'string' is always tried last)
$valuemixed
$options = []array
returnsmixedthe value coerced to the first $types entry that accepts it
throwsif none of $types can coerce $value
MyCoercer::Coerce(['integer', 'string'], '42'); // (int) 42

__invoke($value, $options, $types)

aCoercer.php:47

Try each of $types in turn (via aConverter::call), returning the result of the first one that doesn't throw an eInvalid. 'string' is always tried last regardless of its position in $types, since almost any value can be coerced to a string -- letting it win by being listed first would defeat every other type.

function __invoke(mixed $value, array $options = [], array $types = []): mixed
$valuemixed
$options = []array
$types = []arraycandidate types, in preference order
returnsmixedthe converted value
throwsif every type in $types rejects $value (in MODE_DEV, the message includes each type's specific rejection reason; elsewhere it is a bare, non-leaking message)
Inherited members (62)
ConstantsDeclared byDescription
ALERTiLogLevelAlert: Action must be taken immediately.
ALLiLogLevelMask for all
ALL_PLUSiLogLeveldebug everything
BACKTRACEiLogLevel
CRITICALiLogLevelCritical: Critical conditions.
DEBUGiLogLevelDebug: Detailed debug information.
DEEPiLogLeveldebug everything with arguments
EMERGENCYiLogLevelEmergency: System is unusable.
ERRORiLogLevelError: Runtime errors that do not require immediate action but should typically be logged and monitored.
ERROR_PLUSiLogLevelMask for all error
FATALiLogLevelMask for all fatal error
INFOiLogLevelInfo: Interesting events.
INFO_PLUSiLogLevelMask for all errors/warning/notices/info
MEMORYiLogLevelinclude backtrace object
NOTICEiLogLevelNotice: Normal but significant events.
NOTICE_PLUSiLogLevelMask for all errors/warning/notices/info
TRACEiLogLevelinclude backtrace as origins
WARNINGiLogLevelWarning: Exceptional occurrences that are not errors.
WARNING_PLUSiLogLevelMask for all errors and warnings
PropertiesDeclared byDescription
functionsaConverter
globalOptionsaConverter
verbosityaModule
MethodsDeclared byDescription
addOptions($type, $options)aConverterMerge $options into $type's existing options (via merge), rather than replacing them wholesale like setOptions.
alert($message, $context)aModuleAction must be taken immediately.
backtraces($message, $context)aModuleForce-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)aConverterCall the function associated to a type
clear()aConverterRemove every registered type/function.
Configure($config)aModuleMerge $config into this module's configuration in the shared Configuration.
critical($message, $context)aModuleCritical conditions. No-op if CRITICAL is currently filtered out by the verbosity mask.
debug($message, $context)aModuleDetailed debug information.
debugName()aModuleHuman-readable identifier used as the default {origin} in this instance's log messages.
DefaultConfig()aModuleThe config a module starts from before anything loaded via Configuration is merged in.
emergency($message, $context)aModuleSystem is unusable. No-op if EMERGENCY is currently filtered out by the verbosity mask.
error($message, $context)aModuleRuntime errors that do not require immediate action but should typically be logged and monitored.
getClassFunction($class)aConverterFind 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)aConverterNormalize $value's type into one of this converter's type names.
getVerbosity()aModule
hasType($type)aConverter
info($message, $context)aModuleInteresting 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)aModuleLogs with an arbitrary level.
notice($message, $context)aModuleNormal 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)aConverterSet a coercer
setFunctions($fns)aConverterRegister many functions at once, e.g.
setOptions($type, $options)aConverterReplace $type's options wholesale.
setVerbosity($verb)aModuleSet the current verbosity mask, replacing whatever it was before.
Shared()aModuleGet the shared instance, creating (and configuring) it on first call.
testVerbosity($level)aModuleTest whether a given level (or set of levels) is currently enabled by this instance's verbosity mask.
traitUnshare($serialize)aModuleRemove 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)aModuleLike 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)aModuleExceptional occurrences that are not errors.
__construct($config)aModuleprotected constructor, so it is not possible to do new Module(...) called by the serialization process just before being injected with data.