Document
MMO\core\documents · 1 symbol · generated 5 Oct 2026
Document
Document.php:31A renderable container for a controller/response's output data (its "body"), plus metadata: HTTP-style Links (LinkProviderInterface), request/response logs (Log), free-form meta.
- Namespace
MMO\core\documents- Implements
- ArrayAccess,
LinkProviderInterface, iRenderable, JsonSerializable - Uses traits
- tWithOptions
Index
| body | ||
| importPaths | ||
| links | ||
| logs | ||
| meta | Free-form metadata about this document (e.g. | |
| opts | ||
| readOnly | If true, the document's body/links/meta can no longer be modified (setters throw eRuntime). | |
| addContent($data) | Recursively merge $data into the current body (see merge). | |
| addImportPath($path, $first) | Add one base directory to the import search paths. | |
| addLink($link) | Append a link to this document. | |
| addMeta($data) | Recursively merge $data into $meta (existing keys are overwritten, not combined -- see merge's $combine argument). | |
| addOptions($opts, $appendList) | Merge $opts into the existing options (through merge), rather than replacing them wholesale like setOptions. | |
| addVars($vars) | Merge extra variables into the set made available to import()-ed files. | |
| clearLogs() | Discard all recorded logs. | |
| clearOptions() | Empty the options bag. | |
| createStream() | ||
| findImportPath($filename) | Resolve a relative filename against getImportPaths (first match wins). | |
| getBody() | ||
| getImportPaths() | ||
| getLinkByRel($rel) | ||
| getLinks() | Returns an iterable of LinkInterface objects. | |
| getLinksByRel($rel) | Returns an iterable of LinkInterface objects that have a specific relationship. | |
| getLogs() | ||
| getOption($key, $default) | ||
| getOptions() | ||
| getPrinter() | ||
| getVars() | Get the variables available for import | |
| hasLogs($flag) | ||
| import($_FILENAME, $_VARS, $_KEY) | Import (require) a PHP/phtml file as a sub-template, capturing its output. | |
| isImportValid($filename) | ||
| isRaw() | ||
| jsonSerialize() | ||
| logEvent($event) | Record a log/event on this document, e.g. | |
| offsetExists($offset) | ArrayAccess: 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) | ArrayAccess: $document[$offset] -- returns null for a missing entry, same as `$document[$offset] ?? | |
| offsetSet($offset, $value) | ArrayAccess: $document[$offset] = $value sets a body entry ($document[] = $value appends). | |
| offsetUnset($offset) | ArrayAccess: unset($document[$offset]) removes a body entry. | |
| Raw($body, $opts) static | Build a document whose isRaw is true from the start (see setRaw for what "raw" means). | |
| removeLink($link) | Remove a link (by identity). | |
| render($opts) | Export view to string | |
| renderValue($value, $opts) | Render an arbitrary value through this document's printer (getPrinter, or TextPrinter by default), merging $opts over the document's own options. | |
| setBody($body) | Replace the document's content, then dispatch DocumentInit. | |
| setImportPaths($paths) | Replace the base directories searched by findImportPath/import for a relative filename. | |
| setLogs($logs) | ||
| setOption($key, $value) | Set (or, with a null $value, remove) a single option. | |
| setOptions($opts) | Replace the whole options bag. | |
| setPrinter($printer) | ||
| setRaw($raw) | Tells a document should be left as raw as possible. | |
| setVars($vars) | Replace the variables made available to import()-ed files (a 'document' => $this var is always added at construction, see __construct). | |
| startCapture($key) | Start output capture. | |
| __construct($body, $opts) | Constructor | |
| __toString() |
Properties7
body
importPaths
- Type
- array
links
logs
meta
Free-form metadata about this document (e.g. generation time, pagination info) -- not part of the body.
- Type
- array
opts
- Type
- array
readOnly
If true, the document's body/links/meta can no longer be modified (setters throw eRuntime).
- Type
- bool
Methods45
addContent($data)
Document.php:148Recursively merge $data into the current body (see merge).
| $data | ArrayAccess | array | |
| returns | void |
addImportPath($path, $first)
Document.php:351Add one base directory to the import search paths.
addLink($link)
Document.php:261Append a link to this document.
| $link | LinkInterface | array | string | a LinkInterface, an href string, or an array of Link attributes (e.g. ['href' => '/next', 'rel' => 'next']) -- see Link::__construct. |
| returns | LinkInterface | $link itself (wrapped as a Link if it wasn't already one), for chaining. |
| throws | if the document is read-only. |
addMeta($data)
Document.php:153Recursively merge $data into $meta (existing keys are overwritten, not combined -- see merge's $combine argument).
addOptions($opts, $appendList)
tWithOptions.php:65Merge $opts into the existing options (through merge), rather than replacing them wholesale like setOptions.
| $opts | array | the options to merge in |
| $appendList = false | bool | if true, a list-valued option is appended to (rather than replaced by) the corresponding list in $opts -- see \MMO\core\arrays\merge for the exact semantics |
| returns | void |
addVars($vars)
Document.php:204Merge extra variables into the set made available to import()-ed files.
clearLogs()
Document.php:102Discard all recorded logs.
| returns | void |
clearOptions()
tWithOptions.php:39Empty the options bag.
| returns | void |
createStream()
Document.php:186findImportPath($filename)
Document.php:362Resolve a relative filename against getImportPaths (first match wins).
getBody()
Document.php:132getImportPaths()
Document.php:341| returns | array | the current import search paths, in search order. |
getLinkByRel($rel)
Document.php:307getLinks()
Document.php:284Returns an iterable of LinkInterface objects.
| returns | array |
getLinksByRel($rel)
Document.php:299Returns an iterable of LinkInterface objects that have a specific relationship.
getLogs()
Document.php:92getOption($key, $default)
tWithOptions.php:49getOptions()
tWithOptions.php:20| returns | array | every option currently set |
getPrinter()
Document.php:82| returns | null | callable | the printer used by renderValue, or null to fall back to TextPrinter. |
getVars()
Document.php:194Get the variables available for import
| returns | array |
hasLogs($flag)
Document.php:110import($_FILENAME, $_VARS, $_KEY)
Document.php:396Import (require) a PHP/phtml file as a sub-template, capturing its output.
| $_FILENAME | string | a PHP file, absolute or resolved via findImportPath. |
| $_VARS = [] | ArrayAccess | array | variables to make available to the file (take precedence over getVars). |
| $_KEY = null | string | false | null | where to add the captured output: null appends to the body, a string path adds it under that key (push), false doesn't add it to the body at all. |
| returns | OutputCapture | the (already-closed) capture -- OutputCapture::getText() for its content. |
isImportValid($filename)
Document.php:373| $filename | string | |
| returns | bool | whether $filename can currently be resolved by findImportPath. |
isRaw()
Document.php:222jsonSerialize()
Document.php:72| returns | array | the document's full structured content ('meta'/'links'/'data'/'logs'), for json_encode(). |
logEvent($event)
Document.php:124Record a log/event on this document, e.g. so it's included in the rendered output (a JSON document typically surfaces these under its 'logs' key -- see jsonSerialize).
| $event | object | typically a Log; if it's an iStoppableEvent, propagation is stopped so no other listener also handles it (this document is now the one "owning" it). |
| returns | bool | false (a no-op) if the document is read-only or isRaw. |
offsetExists($offset)
Document.php:242ArrayAccess: 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)
Document.php:247ArrayAccess: $document[$offset] -- returns null for a missing entry, same as $document[$offset] ?? null.
offsetSet($offset, $value)
Document.php:235ArrayAccess: $document[$offset] = $value sets a body entry ($document[] = $value appends). @throws eRuntime if read-only.
offsetUnset($offset)
Document.php:229ArrayAccess: unset($document[$offset]) removes a body entry. @throws eRuntime if read-only.
Raw($body, $opts)
staticDocument.php:65Build a document whose isRaw is true from the start (see setRaw for what "raw" means).
removeLink($link)
Document.php:319Remove a link (by identity).
| $link | LinkInterface | |
| returns | bool | false if $link isn't currently one of this document's links. |
render($opts)
Document.php:175Export view to string
renderValue($value, $opts)
Document.php:165Render an arbitrary value through this document's printer (getPrinter, or TextPrinter by default), merging $opts over the document's own options.
setBody($body)
Document.php:141Replace the document's content, then dispatch DocumentInit.
setImportPaths($paths)
Document.php:332Replace the base directories searched by findImportPath/import for a relative filename.
setLogs($logs)
Document.php:97setOption($key, $value)
tWithOptions.php:77Set (or, with a null $value, remove) a single option.
setOptions($opts)
tWithOptions.php:30Replace the whole options bag.
setPrinter($printer)
Document.php:87| $printer | null | callable | a callable(mixed $value, array $opts): string, or null to use TextPrinter. |
| returns | void |
setRaw($raw)
Document.php:217Tells a document should be left as raw as possible.
| $raw = true | bool | |
| returns |
setVars($vars)
Document.php:199Replace the variables made available to import()-ed files (a 'document' => $this var is always added at construction, see __construct).
startCapture($key)
Document.php:424Start output capture. Start output buffering (capture echo)
| $key = null | string | false | null | the content's key to add output to. if null, add to the content. if false, don't add it to the content (just return) |
| returns | OutputCapture |
__construct($body, $opts)
Document.php:53Constructor