Index

TextPrinter

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

class

TextPrinter

TextPrinter.php:26

Converter to string for any value's type, driven by a per-type/per-log-level $templates table (each a strtr()-style string with {placeholder} tokens -- see renderTemplate/setTemplate). Subclasses (XmlPrinter, HtmlPrinter) override $templates with format-appropriate markup instead of plain text, reusing this class's export logic (type dispatch, dump mode, cyclic-reference tracking) as-is.

class MMO\core\printers\TextPrinter extends MMO\core\classes\aExporter
Namespace
MMO\core\printers
Extends
aExporter
An entity is printed as its toArray(), and dumped without the value of a hidden property: [`exportEntity`](https://mcp.mmoframework.fr/documentation/mmo.core/php/printers/TextPrinter.md#textprinter-exportentity). Known options : - max-depth: {int} the maximum depth to go when describing an array - indent: {int|string} if the resulted text need to be indented
TextPrinter::Print(['a' => 1, 'b' => 2]);TextPrinter::Shared()->idump($someObject); // a fuller, recursive "var_dump"-style rendering

Index

globalOptions
templates
clear()Reset both the exporter state (aExporter::clear) and $templates.
dump($values)Echo one or more values in dump mode (see idump), with a header naming the calling file/line and a footer.
exportBoolean($value, $options)Typecast to a boolean and return template 'true' or 'false'
exportClosure($value, $options)Closure
exportDateTime($value, $options)Render a DatimeInterface
exportDump($value, $options)The 'dump' type exporter -- same as idump but registered for explicit dispatch via __invoke($v, [], 'dump').
exportEntity($value, $options)An entity (any iArrayProperties) is printed as its toArray() -- what an API returns of it -- the same as
exportEnum($value, $options)
exportFilename($value, $options)Render a relative filename
exportInstance($value, $options)object options: - {int} scope: binary combinaison of the class constants PROPERTY_*.
exportLog($value, $options)MMO\core\events\Log
exportNull($value, $options)Return template 'null'
exportNumber($value, $options)Format number
exportObject($value, $options)array options: {HashList} hashes: the hash list {int|false} max-level: the max level to go to.
exportRenderable($value, $options)
exportResource($value, $options)Resource
exportSplObjectStorage($value, $options)
exportsProperty($prop, $value)Same as aExporter::exportsProperty, and a property marked #[NoDump] (a back-reference, such as a collection's repository) is not printed either: an object is printed without what its dump leav…
exportString($value, $options)Typecast to a string
exportThrowable($value, $options)
exportTraces($value, $options)MMO\core\messages\Log::traces
exportValidatorError($value, $options)
getIndent($options)
getTemplate($name)
getTemplates()
hash($value, $options)
hasTemplate($name)
hiddenProperties($value)The properties of $value whose value a dump does not show (exportInstance): for an iArrayProperties (an entity), those behind a hidden ArrayProperty (ArrayProper…
idump($value, $options)
isDumpForwarder($name) staticWhether the backtrace frame named $name only forwards to dump -- the caller a dump's header names is above it.
Print($value, $options, $type) static
renderMaxLevel($value, $options)
renderPrintError($e)What a value whose exporter threw is printed as (__invoke): the exception's class and message, as text (renderText) -- never its stack trace.
renderTemplate($name, $data)Render a template
renderText($text)The text a template holds that comes from the value printed: the keys and property names of a dump (a decoded request body's...), a resource's uri, a validation error's message, a log's message and…
setTemplate($name, $tpl)Set template
setTemplates($tpls)
__construct($config)
__invoke($value, $options, $type)Render $value. Never throws: a failing exporter's exception is caught and printed inline instead (its class and message: renderPrintError), and a type with no registered exporter falls back to…

Properties2

globalOptions

array $globalOptions = ['indent' => ' ']
Type
array

templates

#[MMO\core\attributes\Serialize(serialize: false, unserialize: 'setTemplates')] protected array $templates = […36 items]
Type
array

Methods39

dump($values)

TextPrinter.php:289

Echo one or more values in dump mode (see idump), with a header naming the calling file/line and a footer. @param mixed ...$values

function dump(mixed ...$values): void
...$valuesmixed
returnsvoid

exportBoolean($value, $options)

TextPrinter.php:361

Typecast to a boolean and return template 'true' or 'false'

function exportBoolean(mixed $value, array $options = []): string
$valuemixed
$options = []array
returnsstring

exportClosure($value, $options)

TextPrinter.php:419

Closure

function exportClosure(mixed $value, array $options = []): string
$valuemixed
$options = []array- basepath: {string} the basepath for the filenames
returnsstring

exportDateTime($value, $options)

TextPrinter.php:400

Render a DatimeInterface

function exportDateTime(mixed $value, array $options = []): string
$valuemixed
$options = []array- format: {string} the format to use to format the date (see) - lang: {string} the language to use (en_EN | en_US | fr_FR | ... )
returnsstring

exportDump($value, $options)

TextPrinter.php:313

The 'dump' type exporter -- same as idump but registered for explicit dispatch via __invoke($v, [], 'dump').

function exportDump(mixed $value, array $options = []): string
$valuemixed
$options = []array
returnsstring

exportEntity($value, $options)

TextPrinter.php:522

An entity (any iArrayProperties) is printed as its toArray() -- what an API returns of it -- the same as

function exportEntity(MMO\core\interfaces\iArrayProperties $value, array $options = []): string
See
JsonPrinter::exportEntity: a hidden property (ArrayProperty::isHidden), such as a password's hash, is left out, even named in fields, and so is its collection. Dumped, it shows its properties, protected ones included, but a hidden one's value is not: hiddenProperties. NOTE: it used to be exported like any object, property by property (exportInstance): an HTML or XML page printing a user printed its password's hash, then the class-level caches, its collection and its repository -- 50 to 100 KB for one entity, the application's output stream read along the way, and a print error with its stack trace where a property could not be read.
$valueiArrayProperties
$options = []arrayfields restricts the fields printed (not those of the entities it holds)
returnsstring
HtmlPrinter::Print($user); // same as HtmlPrinter::Print($user->toArray()): no passhashHtmlPrinter::Print($user, new PrintOptions(fields: ['username', 'passhash'])); // its username only

exportEnum($value, $options)

TextPrinter.php:748
function exportEnum(mixed $value, array $options = []): string
$valuemixeda \UnitEnum/\BackedEnum case.
$options = []array
returnsstringvia the 'enum' template ({class}::{name}({value}), value empty for a pure \UnitEnum).

exportFilename($value, $options)

TextPrinter.php:329

Render a relative filename

function exportFilename(mixed $value, array $options = []): string
$valuemixed
$options = []array- basepath: {string} the basepath to remove rom filename
returnsstring

exportInstance($value, $options)

TextPrinter.php:620
object options: - {int} scope: binary combinaison of the class constants PROPERTY_*. by default print all properties - {int} max-level: the max level to go to.function exportInstance(mixed $value, array $options = []): string- indent (int|string): the value to add at the begining of each item - separator (PHP_EOL): the delimiter to cut the text Dumped, a hidden property's value is printed as the 'hidden' template: [`hiddenProperties`](https://mcp.mmoframework.fr/documentation/mmo.core/php/printers/TextPrinter.md#textprinter-hiddenproperties)
$valuemixed
$options = []array
returnsstring

exportLog($value, $options)

TextPrinter.php:536

MMO\core\events\Log

function exportLog(MMO\core\events\Log $value, array $options = []): string
$valueLog
$options = []array{string} basepath: the base folder for relative filenames
returnsstring

exportNumber($value, $options)

TextPrinter.php:374

Format number

function exportNumber(mixed $value, array $options = []): string
$valuemixed
$options = []array- precision: number of decimals - separator-decimal: decimal separator - separator-thousand: thousand separator
returnsstring

exportObject($value, $options)

TextPrinter.php:714

array options: {HashList} hashes: the hash list {int|false} max-level: the max level to go to. default : false {string} format-item

function exportObject(mixed $value, array $options = []): string{callable} layout: the layout to use to render the property's values - indent (int|string): the value to add at the begining of each item - separator (PHP_EOL): the delimiter to cut the text
$valuemixed
$options = []array
returnsstring

exportRenderable($value, $options)

TextPrinter.php:502
function exportRenderable(MMO\core\interfaces\iRenderable $value, array $options = []): string
$valueiRenderable
$options = []array
returnsstringin dump mode, its properties (via exportInstance) rather than its own render() output -- so dumping an object shows its actual state, not (possibly misleading) rendered markup.

exportSplObjectStorage($value, $options)

TextPrinter.php:469
function exportSplObjectStorage(mixed $value, array $options = []): string
$valuemixed
$options = []array
returnsstringeach stored object rendered alongside its attached data ('#' => $object, '$' => $data), wrapped like a normal object dump.

exportsProperty($prop, $value)

TextPrinter.php:696

Same as aExporter::exportsProperty, and a property marked #[NoDump] (a back-reference, such as a collection's repository) is not printed either: an object is printed without what its dump leaves out (exportInstance).

protected function exportsProperty(ReflectionProperty $prop, object $value): boolNOTE: printed (not dumped), an object went through its #[NoDump] properties: a Query or a Collection through its repository, to a PDORepository's handler and the database's password -- which only an exception cut short, as long as the collection's uninitialized schema threw.
$this->exportsProperty(new \ReflectionProperty(Collection::class, 'repository'), $collection); // false

exportString($value, $options)

TextPrinter.php:342

Typecast to a string

function exportString(mixed $value, array $options = []): string
$valuemixed
$options = []array- dump: {bool} if true, use template dump-string (holders: {size}, {value})
returnsstring

exportTraces($value, $options)

TextPrinter.php:557

MMO\core\messages\Log::traces

function exportTraces(mixed $value, array $options = []): string
$valuemixed
$options = []array{array} traces-filter: filterTraces {string|int} indent: either a number of space or a string to indent text
returnsstring

exportValidatorError($value, $options)

TextPrinter.php:490
function exportValidatorError(mixed $value, array $options = []): string
$valuemixed
$options = []array
returnsstringjust its message (no template/wrapping), as text: renderText

getIndent($options)

TextPrinter.php:116
function getIndent(array $options): string
$optionsarray'indent': an int (that many spaces) or a literal string.
returnsstringthe indent string to use, or '' if unset.

hash($value, $options)

TextPrinter.php:131
function hash(object $value, array $options = []): string
$valueobject
$options = []array
returnsstringrendered via the 'cyclic-ref' template, for an object already seen higher up the same dump (avoiding infinite recursion).

hiddenProperties($value)

TextPrinter.php:597

The properties of $value whose value a dump does not show (exportInstance): for an iArrayProperties (an entity), those behind a hidden ArrayProperty (ArrayProperty::isHidden) -- the property named like it, and the one its getter, setter or store reads or writes directly ('$passhash'). A dump is a debug page, but a page nonetheless (\MMO\dump() prints into the response, a development database holds real users): it shows that a secret is there, never what it holds. Code that needs the value dumps it: \MMO\dump($user['passhash']).

protected function hiddenProperties(object $value): array
$valueobject
returnsarraytrue> property name => true
$this->hiddenProperties($user); // ['password' => true, 'passhash' => true]: mmo.oauth's User

idump($value, $options)

TextPrinter.php:282
function idump(mixed $value, array $options = []): string
$valuemixed
$options = []array
returnsstring$value rendered in dump mode ("var_dump"-style, capped to MMO_DUMP_LEVEL deep), as a string instead of being echoed (see dump).

isDumpForwarder($name)

staticTextPrinter.php:307

Whether the backtrace frame named $name only forwards to dump -- the caller a dump's header names is above it.

private static function isDumpForwarder(string $name): bool
$namestring
returnsbool

Print($value, $options, $type)

staticTextPrinter.php:206
static function Print( mixed $value, MMO\core\interfaces\iOptions|array $options = [], ?string $type = null ): string
$valuemixed
$options = []iOptions | array
$type = nullnull | string
returnsstringshorthand for static::Shared()->__invoke(...).
TextPrinter::Print($value);HtmlPrinter::Print($comment, new PrintOptions(escape: true));

renderMaxLevel($value, $options)

TextPrinter.php:144
function renderMaxLevel(mixed $value, array $options): string
$valuemixed
$optionsarray
returnsstringrendered via the 'max-level' template, once $options['max-level'] is reached.

renderPrintError($e)

TextPrinter.php:170

What a value whose exporter threw is printed as (__invoke): the exception's class and message, as text (renderText) -- never its stack trace.

protected function renderPrintError(Throwable $e): stringNOTE: it used to print the exception whole (`"!! print error: {$e} !!"`): its message as markup, then its stack trace -- the server's absolute paths, the arguments of every call -- in the HTML or XML page printing the value.
$this->renderPrintError(new \Error('<b>')); // '!! print error: Error: <b> !!' (HtmlPrinter: &lt;b&gt;)

renderTemplate($name, $data)

TextPrinter.php:271

Render a template

function renderTemplate(string $name, array $data): string
$namestring
$dataarrayWARNING: the key MUST be enclosed in curly bracket ({xxx})
returnsstring

renderText($text)

TextPrinter.php:157

The text a template holds that comes from the value printed: the keys and property names of a dump (a decoded request body's...), a resource's uri, a validation error's message, a log's message and the name and arguments of each call of its backtrace. It is text, never markup -- printed as is here, HTML-escaped by HtmlPrinter, whose templates are markup.

protected function renderText(string $text): string
$textstring
returnsstring
$this->renderText('<img src=x>'); // as is; HtmlPrinter: '&lt;img src=x&gt;'

setTemplate($name, $tpl)

TextPrinter.php:254

Set template

function setTemplate(string $name, ?string $tpl): bool
$namestring
$tplnull | stringa template with moustache holders: {xxx:type}. if null remove template
returnsboolif template has changed

__invoke($value, $options, $type)

TextPrinter.php:182

Render $value. Never throws: a failing exporter's exception is caught and printed inline instead (its class and message: renderPrintError), and a type with no registered exporter falls back to describe.

function __invoke(mixed $value, array $options = [], ?string $type = null): mixed
$valuemixed
$options = []array
$type = nullnull | stringoverride the auto-detected type.
returnsmixedusually a string.
Inherited members (63)
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
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
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.
Export($value, $options, $type)aExporterExport any value, dispatching to the right converter based on its type (or the explicit $type).
exportArray($value, $options)aExporterBuilt-in 'array' converter (a list): recursively exports every value, in place.
ExportProperties($value, $options)aExporterExport an object exportInstance method
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.
resetHash($value, $options)aExporterForget that $value was already seen, within the given $options['hashes'] tracking map: the next time $value is encountered in this same export, it is exported in full again instead of collapsing to…
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.