# Trace

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

[API reference](/docs/api/index.md) › [Debug Core](/docs/extensions/debug-core/reference/index.md) › [Helper](/docs/extensions/debug-core/reference/helper/index.md) › Trace

| final class | `PHPForge\Debug\Helper\Trace` |
| --- | --- |
| Source | [`src/Helper/Trace.php`](https://github.com/php-forge/debug-core/blob/main/src/Helper/Trace.php#L20) |

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

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`create()`](#method-create) static | Creates a renderer emitting [`DEFAULT_TEMPLATE`](/docs/extensions/debug-core/reference/helper/trace/index.md#const-DEFAULT_TEMPLATE) links without path rewriting. | `Trace` |
| [`render()`](#method-render) | Renders one source frame, or an escaped dump when `file` or `line` is missing. | `Trace` |
| [`withPathMappings()`](#method-withPathMappings) | Returns a copy rewriting containerized or remote source paths to their local counterparts. | `Trace` |
| [`withTemplate()`](#method-withTemplate) | Returns a copy rendering every frame with the given template. | `Trace` |

## Constants

| Constant | Value | Description | Defined by |
| --- | --- | --- | --- |
| <span id="const-DEFAULT_TEMPLATE"></span>`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` |

## Method details

### create() <span id="method-create"></span>

```php
public static function create(): self
```

Creates a renderer emitting [`DEFAULT_TEMPLATE`](/docs/extensions/debug-core/reference/helper/trace/index.md#const-DEFAULT_TEMPLATE) links without path rewriting.

**Returns**

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

### render() <span id="method-render"></span>

```php
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()`](https://www.php.net/manual/en/function.call-user-func.php) may produce frames without those keys, see
[`https://www.php.net/manual/en/function.debug-backtrace.php#59713`](https://www.php.net/manual/en/function.debug-backtrace.php#59713).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$frame` | `array<string, mixed>` | Source frame; consumes `file`, `line`, and the optional `text` label. |

**Returns**

`string`: Rendered source line.

### withPathMappings() <span id="method-withPathMappings"></span>

```php
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**

| Parameter | Type | Description |
| --- | --- | --- |
| `$pathMappings` | `array<array-key, mixed>` | Remote source-path prefixes mapped to local prefixes. |

**Returns**

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

### withTemplate() <span id="method-withTemplate"></span>

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

Returns a copy rendering every frame with the given template.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$template` | [`Closure`](https://www.php.net/manual/en/class.closure.php)`(array<string, mixed>): mixed\|string\|false` | Placeholder 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.