JsonParser
MMO\core · 1 symbol · generated 30 Sep 2026
JsonParser
JsonParser.php:14A hand-written, tolerant JSON parser (Decode/DecodeFile): accepts standard JSON, plus a few lenient extensions with a warning logged (not thrown) -- single-quoted strings, and unquoted barewords as string values. Malformed input (that isn't one of those tolerated leniencies) throws eJson.
- Namespace
MMO\core- Extends
- aParser
Index
| WHITE_SPACES | ||
| filter | ||
| addError($token, $message, $context) | ||
| addWarning($token, $message, $context) | A non-fatal parse issue (aParser::addError -- just logs/accumulates, doesn't throw), for tolerated leniencies (decodeText/decodeValue). | |
| createTokenizer() | ||
| Decode($text, $callback) static | Parse json | |
| decodeAny() | Decode one JSON value of any type, dispatching on the current token: {//quote start a nested object/array/string, anything else is a bare value ([decodeValue). | |
| decodeArray() | Decode a [...] array (the tokenizer's current position is just past the opening [). | |
| DecodeFile($filename, $callback) static | ||
| decodeObject() | Decode a {...} object (the tokenizer's current position is just past the opening {). | |
| decodeText() | Decode a quoted string token (starting at the tokenizer's current position, a ' or " token) into its real string value, resuming the tokenizer past its closing quote. | |
| decodeValue($token) | Decode a bare (unquoted) value token: a number, true/false/null (case-insensitively), or -- tolerated with a warning, not valid JSON -- an unquoted bareword, returned as a plain string. | |
| process($opts) |
Constants1
WHITE_SPACES
Properties1
filter
Methods11
addError($token, $message, $context)
JsonParser.php:54- See
aParser::addError-- overridden to be fatal: unlike the base parser (which just logs and accumulates errors, tolerating malformed input), any real syntax error immediately aborts parsing.
addWarning($token, $message, $context)
JsonParser.php:61A non-fatal parse issue (aParser::addError -- just logs/accumulates, doesn't throw), for tolerated leniencies (decodeText/decodeValue).
createTokenizer()
JsonParser.php:66- See
aParser::createTokenizer-- recognizes '/"-quoted strings, [...]/{...} groups (each nestable inside the other), and a ':' token inside objects.
| returns | Tokenizer |
Decode($text, $callback)
staticJsonParser.php:29Parse json
| $text | the text or resource to read from | |
| $callback = null | null | callable | function(array $data, Tokenizer $tokenizer): mixed -- called once per array/object found (innermost first), with $data being that structure's already-decoded content; its return value replaces that structure in the final result (e.g. to turn a decoded object into a real class instance). |
| returns | mixed | |
| throws | if $text isn't valid (tolerantly-extended) JSON. |
decodeAny()
JsonParser.php:220Decode one JSON value of any type, dispatching on the current token: {//quote start a nested object/array/string, anything else is a bare value ([decodeValue).
| returns | ||
| throws | if there's nothing left to decode (aParser::addError's EOF handling). |
decodeArray()
JsonParser.php:193Decode a [...] array (the tokenizer's current position is just past the opening [).
| returns | the decoded list, passed through $filter if set. | |
| throws | on any syntax error (missing ,, or unterminated array). |
DecodeFile($filename, $callback)
staticJsonParser.php:39decodeObject()
JsonParser.php:160Decode a {...} object (the tokenizer's current position is just past the opening {).
| returns | the decoded array (string keys => decoded values), passed through $filter if set. | |
| throws | on any syntax error (missing :/,, or unterminated object). |
decodeText()
JsonParser.php:118Decode a quoted string token (starting at the tokenizer's current position, a ' or " token) into its real string value, resuming the tokenizer past its closing quote. Single-quoted strings are tolerated (with a warning -- the class docblock) and converted to an equivalent double-quoted form.
| returns | string |
decodeValue($token)
JsonParser.php:98Decode a bare (unquoted) value token: a number, true/false/null (case-insensitively), or -- tolerated with a warning, not valid JSON -- an unquoted bareword, returned as a plain string.
process($opts)
JsonParser.php:83- See
aParser::process-- entry point: stores $opts['filter'] (Decode) and decodes from the start of the token stream.
Inherited members (56)
| 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 |
| Methods | Declared by | Description | |
|---|---|---|---|
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). | |
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. | |
getErrors() | aParser | ||
getTokenizer() | aParser | ||
getVerbosity() | aModule | ||
hasErrors() | aParser | ||
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. | |
isLocked() | aParser | ||
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. | |
parse($text, $opts) | aParser | Parse $text: resets getErrors, (re)builds/reuses the tokenizer, runs process, then always clears the tokenizer's tokens from memory (even if process() throws). | |
serialize($path, $serializer) | aModule | \MMO\core\interfaces\iSerializable::serialize -- exports every property (via | |
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. | |
__construct($config) | aModule | protected constructor, so it is not possible to do new Module(...) called by the serialization process just before being injected with data. |