Skip to content
PHP Ecosystem
Explore

Trace

API reference › Debug Core › Helper › Trace

final classPHPForge\Debug\Helper\Trace
Sourcesrc/Helper/Trace.php

Renders captured argument-free source frames as configurable, escaped source links.

MethodDescriptionDefined by
create() staticCreates a renderer emitting DEFAULT_TEMPLATE links without path rewriting.Trace
render()Renders one source frame, or an escaped dump when file or line is missing.Trace
withPathMappings()Returns a copy rewriting containerized or remote source paths to their local counterparts.Trace
withTemplate()Returns a copy rendering every frame with the given template.Trace
ConstantValueDescriptionDefined by
DEFAULT_TEMPLATE'<a href="ide://open?url=file://{file}&amp;line={line}">{text}</a>'Default template: an ide:// deep link IDE extensions resolve into “open file at line”.Trace
public static function create(): self

Creates a renderer emitting DEFAULT_TEMPLATE links without path rewriting.

Returns

self: Renderer using the default template and no path mappings.

public function render(array<string, mixed> $frame): string

Renders one source frame, or an escaped dump when file or line is missing.

Internal PHP functions such as call_user_func() may produce frames without those keys, see https://www.php.net/manual/en/function.debug-backtrace.php#59713.

Parameters

ParameterTypeDescription
$framearray<string, mixed>Source frame; consumes file, line, and the optional text label.

Returns

string: Rendered source line.

public function withPathMappings(array<array-key, mixed> $pathMappings): self

Returns a copy rewriting containerized or remote source paths to their local counterparts.

Entries whose value does not coerce to a string are dropped; both sides are normalized to forward slashes and a single trailing slash, and only the first matching prefix is applied.

Parameters

ParameterTypeDescription
$pathMappingsarray<array-key, mixed>Remote source-path prefixes mapped to local prefixes.

Returns

self: New instance rewriting frame paths through the normalized mappings.

public function withTemplate(Closure(array<string, mixed>): mixed|string|false $template): self

Returns a copy rendering every frame with the given template.

Parameters

ParameterTypeDescription
$templateClosure(array<string, mixed>): mixed|string|falsePlaceholder template resolving {file}, {line}, and {text} against the escaped frame values, false to emit escaped plain text without a link, or a closure receiving the frame with the normalized file, line, and text keys; a string returned by the closure resolves the same placeholders, any other result renders as an escaped dump.

Returns

self: New instance rendering every frame with the given template.