Index

JsonDocument

MMO\core\documents · 1 symbol · generated 30 Sep 2026

class

JsonDocument

JsonDocument.php:16

A JSON Document. Unless isRaw, the rendered JSON wraps the body under a 'data' key alongside 'meta'/'links'/'logs' (jsonSerialize); when raw, only the bare body is rendered.

class MMO\core\documents\JsonDocument extends MMO\core\documents\Document
Namespace
MMO\core\documents
Extends
Document
$doc = new JsonDocument(['hello' => 'world']); echo $doc->render(); // {"meta":[],"links":[],"data":{"hello":"world"},"logs":[]} echo JsonDocument::Raw(['hello' => 'world'])->render(); // {"hello":"world"}

Methods2

renderValue($value, $opts)

JsonDocument.php:22
function renderValue(mixed $value, MMO\core\interfaces\iOptions|array $opts = []): string
$valuemixed
$opts = []iOptions | array
returnsstring$value JSON-encoded, or the encoding exception's own text if encoding fails.
Inherited members (50)
PropertiesDeclared byDescription
bodyDocument
importPathsDocument
linksDocument
logsDocument
metaDocumentFree-form metadata about this document (e.g.
optsDocument
readOnlyDocumentIf true, the document's body/links/meta can no longer be modified (setters throw eRuntime).
MethodsDeclared byDescription
addContent($data)DocumentRecursively merge $data into the current body (see merge).
addImportPath($path, $first)DocumentAdd one base directory to the import search paths.
addLink($link)DocumentAppend a link to this document.
addMeta($data)DocumentRecursively merge $data into $meta (existing keys are overwritten, not combined -- see merge's $combine argument).
addOptions($opts, $appendList)DocumentMerge $opts into the existing options (through merge), rather than replacing them wholesale like setOptions.
addVars($vars)DocumentMerge extra variables into the set made available to import()-ed files.
clearLogs()DocumentDiscard all recorded logs.
clearOptions()DocumentEmpty the options bag.
createStream()Document
findImportPath($filename)DocumentResolve a relative filename against getImportPaths (first match wins).
getBody()Document
getImportPaths()Document
getLinkByRel($rel)Document
getLinks()DocumentReturns an iterable of LinkInterface objects.
getLinksByRel($rel)DocumentReturns an iterable of LinkInterface objects that have a specific relationship.
getLogs()Document
getOption($key, $default)Document
getOptions()Document
getPrinter()Document
getVars()DocumentGet the variables available for import
hasLogs($flag)Document
import($_FILENAME, $_VARS, $_KEY)DocumentImport (require) a PHP/phtml file as a sub-template, capturing its output.
isImportValid($filename)Document
isRaw()Document
jsonSerialize()Document
logEvent($event)DocumentRecord a log/event on this document, e.g.
offsetExists($offset)DocumentArrayAccess: isset($document[$offset]) -- true for a body entry with a non-null value, or, when the body is a plain array, for any existing key (including one whose value is null).
offsetGet($offset)DocumentArrayAccess: $document[$offset] -- returns null for a missing entry, same as `$document[$offset] ??
offsetSet($offset, $value)DocumentArrayAccess: $document[$offset] = $value sets a body entry ($document[] = $value appends).
offsetUnset($offset)DocumentArrayAccess: unset($document[$offset]) removes a body entry.
Raw($body, $opts)DocumentBuild a document whose isRaw is true from the start (see setRaw for what "raw" means).
removeLink($link)DocumentRemove a link (by identity).
setBody($body)DocumentReplace the document's content, then dispatch DocumentInit.
setImportPaths($paths)DocumentReplace the base directories searched by findImportPath/import for a relative filename.
setLogs($logs)Document
setOption($key, $value)DocumentSet (or, with a null $value, remove) a single option.
setOptions($opts)DocumentReplace the whole options bag.
setPrinter($printer)Document
setRaw($raw)DocumentTells a document should be left as raw as possible.
setVars($vars)DocumentReplace the variables made available to import()-ed files (a 'document' => $this var is always added at construction, see __construct).
startCapture($key)DocumentStart output capture.
__construct($body, $opts)DocumentConstructor
__toString()Document