Index

aModule

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

class

aModule

aModule.php:41

Base class for a configurable singleton module.

abstract class MMO\core\classes\aModule implements MMO\core\interfaces\iModule, MMO\core\interfaces\iSerializable use MMO\core\classes\tLogEmitter, MMO\core\classes\tSingleton
Namespace
MMO\core\classes
Implements
iModule, iSerializable
Uses traits
tLogEmitter, tSingleton
> WARNING: A module cannot be created with `new Module()`. You MUST use `Module::Shared()` to get an instance. A Module can be accesses like an array. This allows configuration to be injected directly with the array's function `\MMO\corer\arrays\xxx()` For example, you can get the module's verbosity using `MyModule::Shared()['verbosity']` ### Configuration A module use `\MMO\core\objects\unserialize()` to be instantiated. It reads its configuration from the `MMO\core\Configuration` singleton. If you want certain properties to be set with a method instead of being directly set, use the attribute [`\MMO\core\attribute\Serialize`](../../docs/Serialization.md). #### Change the given configuration programmatically Module can manipulate the given configuration by implementing the protected constructor. It takes the configuration as a reference on an array : `protected function __construct(array &$config)` #### Initialize the module After the module has been unserialized, its `__wakeup()` method is called. Implement your initialization there.

Index

verbosity
alert($message, $context)Action must be taken immediately.
backtraces($message, $context)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).
Configure($config) staticMerge $config into this module's configuration in the shared Configuration.
critical($message, $context)Critical conditions. No-op if CRITICAL is currently filtered out by the verbosity mask.
debug($message, $context)Detailed debug information.
debugName()Human-readable identifier used as the default {origin} in this instance's log messages.
DefaultConfig() staticThe config a module starts from before anything loaded via Configuration is merged in.
emergency($message, $context)System is unusable. No-op if EMERGENCY is currently filtered out by the verbosity mask.
error($message, $context)Runtime errors that do not require immediate action but should typically be logged and monitored.
getVerbosity()
info($message, $context)Interesting events. No-op if INFO is currently filtered out by the verbosity mask.
Instantiate($config) static(Re)create the shared instance immediately, configured with $config merged into the class's existing config.
IsShared() static
log($level, $message, $context)Logs with an arbitrary level.
notice($message, $context)Normal but significant events.
offsetExists($key)\ArrayAccess::offsetExists -- tells whether $key is a declared property at all, regardless of whether it is currently readable/writable through array access.
offsetGet($key)\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)\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)\ArrayAccess::offsetUnset -- equivalent to $module[$key] = null.
serialize($path, $serializer)\MMO\core\interfaces\iSerializable::serialize -- exports every property (via
setVerbosity($verb)Set the current verbosity mask, replacing whatever it was before.
Shared() staticGet the shared instance, creating (and configuring) it on first call.
testVerbosity($level)Test whether a given level (or set of levels) is currently enabled by this instance's verbosity mask.
traitUnshare($serialize) staticRemove the shared instance, so the next Shared() call creates a fresh one.
unserialize($data, $path, $instances)\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) staticLike 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)Exceptional occurrences that are not errors.
__construct($config)protected constructor, so it is not possible to do new Module(...) called by the serialization process just before being injected with data.

Properties1

verbosity

#[MMO\core\attributes\Serialize(order: -1000)] protected int $verbosity = 31
Type
int

Methods28

alert($message, $context)

tLogEmitter.php:121

Action must be taken immediately.

function alert(Stringable|string $message, array $context = []): voidExample: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up.
$messageStringable | string
$context = []array
returnsvoid
$this->alert('payment gateway unreachable for 5 minutes.');

backtraces($message, $context)

tLogEmitter.php:234

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).

function backtraces(string $message = ' -- TRACES -- ', array $context = []): void
$message = ' -- TRACES -- 'string
$context = []array
returnsvoid
$this->backtraces('unexpected state reached in {method}.', ['method' => __METHOD__]);

Configure($config)

staticaModule.php:78

Merge $config into this module's configuration in the shared Configuration. If the module's shared instance already exists, each value is applied to it immediately (through the container's mutation-aware injection, which reaches into the live object's own ArrayAccess setter); otherwise it is simply stored and picked up whenever the instance is first built.

static function Configure(array $config): void
$configarray
returnsvoid
I18n::Shared(); // instance already built I18n::Configure(['lang' => 'fr']); // I18n::Shared()['lang'] is 'fr' immediately, no rebuild needed

critical($message, $context)

tLogEmitter.php:138

Critical conditions. No-op if CRITICAL is currently filtered out by the verbosity mask.

function critical(Stringable|string $message, array $context = []): voidExample : Application component unavailable, unexpected exception.
$messageStringable | string
$context = []array
returnsvoid
$this->critical('unexpected {exception}.', ['exception' => $e]);

debug($message, $context)

tLogEmitter.php:219

Detailed debug information. No-op if DEBUG is currently filtered out by the verbosity mask.

function debug(Stringable|string $message, array $context = []): void
$messageStringable | string
$context = []array
returnsvoid
$this->debug('set stream [{stream}].', ['stream' => $stream]);

debugName()

tLogEmitter.php:30

Human-readable identifier used as the default {origin} in this instance's log messages.

function debugName(): stringOverride this in a class using the trait to show something more specific than the bare classname.
returnsstring

DefaultConfig()

staticaModule.php:52

The config a module starts from before anything loaded via Configuration is merged in.

static function DefaultConfig(): arrayOverride in a subclass to declare its own defaults (as done by [`I18n`](https://mcp.mmoframework.fr/documentation/mmo.core/php/I18n.md#i18n)).
returnsarray
MyModule::DefaultConfig(); // ['verbosity' => MMO_DEBUG_FLAGS]

emergency($message, $context)

tLogEmitter.php:103

System is unusable. No-op if EMERGENCY is currently filtered out by the verbosity mask.

function emergency(Stringable|string $message, array $context = []): void
$messageStringable | string
$context = []array
returnsvoid
$this->emergency('database connection lost.');

error($message, $context)

tLogEmitter.php:154

Runtime errors that do not require immediate action but should typically be logged and monitored.

function error(Stringable|string $message, array $context = []): voidNo-op if ERROR is currently filtered out by the verbosity mask.
$messageStringable | string
$context = []array
returnsvoid
$this->error('failed to write [{file}].', ['file' => $filename]);

getVerbosity()

tLogEmitter.php:38
function getVerbosity(): int
returnsintthe current verbosity, as a bitmask of iLogLevel::* constants
$this->getVerbosity() === (iLogLevel::ERROR_PLUS); // true if only errors/critical/alert/emergency are enabled

info($message, $context)

tLogEmitter.php:204

Interesting events. No-op if INFO is currently filtered out by the verbosity mask.

function info(Stringable|string $message, array $context = []): voidExample: User logs in, SQL logs.
$messageStringable | string
$context = []array
returnsvoid
$this->info('routing [{request}] ...', ['request' => $request]);

Instantiate($config)

statictSingleton.php:61

(Re)create the shared instance immediately, configured with $config merged into the class's existing config.

static function Instantiate(array $config = []): staticUnlike a plain [`Shared()`](https://mcp.mmoframework.fr/documentation/mmo.core/php/classes/aModule.md#amodule-shared) call (which lazily builds the instance from whatever config was already loaded), this lets you supply/override config right before the instance is built.
$config = []arrayconfig values merged in before the instance is constructed
returnsstaticthe newly (re)created shared instance
MyService::Instantiate(['greeting' => 'yo'])->greeting; // 'yo'

IsShared()

statictSingleton.php:49
static function IsShared(): bool
returnsbooltrue if the shared instance has already been created (a call to Shared() would not need to construct a new one)
MyService::IsShared(); // false until the first MyService::Shared() call

log($level, $message, $context)

tLogEmitter.php:81

Logs with an arbitrary level.

function log($level, Stringable|string $message, array $context = []): voidNOTE: $level is filtered against the current [`setVerbosity()`](https://mcp.mmoframework.fr/documentation/mmo.core/php/classes/aModule.md#amodule-setverbosity): if the level is masked out, nothing is logged/dispatched at all. Return type is `void` (not the dispatched Log) to satisfy \Psr\Log\LoggerInterface.
$level
$messageStringable | string
$context = []arrayignored if $message is a Log
returnsvoid
$this->log(self::ERROR, 'disk usage at {percent}%.', ['percent' => 92]); $this->log('error', $caughtException); //string levels are resolved through \MMO\core\debug\flags()

notice($message, $context)

tLogEmitter.php:187

Normal but significant events. No-op if NOTICE is currently filtered out by the verbosity mask.

function notice(Stringable|string $message, array $context = []): void
$messageStringable | string
$context = []array
returnsvoid
$this->notice('-- START -- ({mode}): {time}', ['mode' => MMO_MODE, 'time' => date('r')]);

offsetExists($key)

aModule.php:192

\ArrayAccess::offsetExists -- tells whether $key is a declared property at all, regardless of whether it is currently readable/writable through array access.

function offsetExists(mixed $key): bool
$keymixed
returnsbool
isset(I18n::Shared()['lang']); // true

offsetGet($key)

aModule.php:146

\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. Application's paths property is declared #[Serialize(serialize: 'getPaths', ...)], so $app['paths'] calls $app->getPaths()). A property declared #[Serialize(false)] (serialize explicitly disabled) reads as null through array access.

function offsetGet(mixed $key): mixed
$keymixed
returnsmixed
throwsif $key is not a declared property at all
I18n::Shared()['lang']; // reads the $lang property directly, e.g. 'en-EN'

offsetSet($key, $value)

aModule.php:170

\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. I18n's lang property is declared #[Serialize(null, 'setLanguage')], so $i18n['lang'] = 'fr' calls $i18n->setLanguage('fr')).

function offsetSet(mixed $key, mixed $value): void
$keymixed
$valuemixed
returnsvoid
throwsif $key is not a declared property at all
throwsif the property is #[Serialize(false)] (or its unserialize side is explicitly false): such a property cannot be set through array access at all
I18n::Shared()['lang'] = 'fr'; // routes through setLanguage('fr')

offsetUnset($key)

aModule.php:134

\ArrayAccess::offsetUnset -- equivalent to $module[$key] = null.

function offsetUnset(mixed $key): void
$keymixed
returnsvoid
unset($module['someProperty']);

serialize($path, $serializer)

aModule.php:101

\MMO\core\interfaces\iSerializable::serialize -- exports every property (via

function serialize(string $path, callable $serializer): array
See
serializeProperties, which honors each property's #[Serialize] attribute), then drops any value that still equals its DefaultConfig default, so only the meaningful overrides are kept.
$pathstring
$serializercallable
returnsarray

setVerbosity($verb)

tLogEmitter.php:64

Set the current verbosity mask, replacing whatever it was before.

function setVerbosity(string|int|null $verb = null): void
$verb = nullstring | int | nulla bitmask of iLogLevel::* constants, or a level name/expression resolved through \MMO\core\debug\flags() (e.g. 'error+' for iLogLevel::ERROR_PLUS)
returnsvoid
$this->setVerbosity(iLogLevel::WARNING_PLUS); // only log warnings and above $this->setVerbosity('all'); // log everything

Shared()

statictSingleton.php:22

Get the shared instance, creating (and configuring) it on first call.

static function Shared(): static
returnsstatic
MyService::Shared()->greeting; // 'hello'

testVerbosity($level)

tLogEmitter.php:50

Test whether a given level (or set of levels) is currently enabled by this instance's verbosity mask.

function testVerbosity(string|int $level): int
$levelstring | inta iLogLevel::* constant/bitmask, or a level name resolved through \MMO\core\debug\flags()
returnsintthe bits of $level that are currently enabled (0 if none of them are)
$this->testVerbosity(self::DEBUG); // non-zero if debug-level logging is currently enabled $this->testVerbosity('error'); // same, using the string form

traitUnshare($serialize)

statictSingleton.php:35

Remove the shared instance, so the next Shared() call creates a fresh one.

static function traitUnshare(bool $serialize = true): bool
See
serialize) and kept as the class's config, so the next instance created picks up where this one left off; if false, the instance is simply discarded and the next one starts from the class's original config
$serialize = trueboolif true (the default) and an instance currently exists, it is serialized first (via
returnsbooltrue if an instance actually existed and was removed
MyService::Unshare(); // true if MyService::Shared() had already been called; the next call rebuilds it

unserialize($data, $path, $instances)

aModule.php:122

\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

function unserialize( array $data, string $path, Psr\Container\ContainerInterface|array &$instances ): void
See
unserializeProperties, again honoring #[Serialize]). This is how a module is actually built: Container::getInstance ultimately calls this, never new.
$dataarray
$pathstring
$instancesContainerInterface | array
returnsvoid

warning($message, $context)

tLogEmitter.php:172

Exceptional occurrences that are not errors. No-op if WARNING is currently filtered out by the verbosity mask.

function warning(Stringable|string $message, array $context = []): voidExample: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong.
$messageStringable | string
$context = []array
returnsvoid
$this->warning('{count} logs were dropped.', ['count' => 3]);

__construct($config)

aModule.php:89

protected constructor, so it is not possible to do new Module(...) called by the serialization process just before being injected with data.

protected function __construct(array &$config)Override in a subclass to alter $config before it is applied (e.g. resolve derived values).
$configarray
Inherited members (19)
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