VOOZH about

URL: https://deepwiki.com/hypervel/components/10.2-enhanced-vardumper

⇱ Enhanced VarDumper | hypervel/components | DeepWiki


Loading...
Last indexed: 7 March 2026 (96fbab)
Menu

Enhanced VarDumper

Purpose and Scope

The Enhanced VarDumper system extends Symfony's VarDumper component to provide automatic source file resolution, compiled view origin tracking, and editor link generation when debugging with dump() or dd(). This system intercepts variable dumps and augments them with contextual information about where the dump call originated, making debugging significantly more efficient.

For information about monitoring and observability in production, see Telescope Monitoring System.

Architecture Overview

The Enhanced VarDumper system consists of two dumper implementations that extend Symfony's base dumpers, a shared trait for source resolution logic, and automatic registration through the FoundationServiceProvider.


Sources: src/foundation/src/Providers/FoundationServiceProvider.php181-201 src/foundation/src/Console/CliDumper.php1-103 src/foundation/src/Http/HtmlDumper.php1-115 src/foundation/src/Concerns/ResolvesDumpSource.php1-191

Component Structure

ComponentLocationPurpose
CliDumpersrc/foundation/src/Console/CliDumper.phpCLI-formatted dumps with ANSI colors and hyperlinks
HtmlDumpersrc/foundation/src/Http/HtmlDumper.phpHTML-formatted dumps for web requests
ResolvesDumpSourcesrc/foundation/src/Concerns/ResolvesDumpSource.phpShared logic for backtrace analysis and source resolution
FoundationServiceProvider::registerDumper()src/foundation/src/Providers/FoundationServiceProvider.php181-201Automatic registration during framework bootstrap

Sources: src/foundation/src/Console/CliDumper.php src/foundation/src/Http/HtmlDumper.php src/foundation/src/Concerns/ResolvesDumpSource.php src/foundation/src/Providers/FoundationServiceProvider.php

Dumper Registration Flow

The system automatically selects and registers the appropriate dumper based on the execution context.


Sources: src/foundation/src/Providers/FoundationServiceProvider.php181-201

Source Resolution Mechanism

The ResolvesDumpSource trait implements sophisticated backtrace analysis to determine where dump() was called.

Backtrace Analysis

The system walks the debug backtrace to find the originating call site, with special handling for wrapper functions:


Sources: src/foundation/src/Concerns/ResolvesDumpSource.php56-113

Adjustable Traces

Certain files require special offset handling in the backtrace to correctly identify the actual call site:

File PatternOffsetReason
symfony/var-dumper/Resources/functions/dump.php+1Global dump() function wraps the actual dumper

Sources: src/foundation/src/Concerns/ResolvesDumpSource.php40-42

Compiled View File Handling

One of the most powerful features is the ability to trace dumps in compiled Blade views back to their original source files.

Detection and Resolution Process


Sources: src/foundation/src/Concerns/ResolvesDumpSource.php118-139

Compiled View Comment Format

Blade compiles views into PHP files that include a special comment marker:


The getOriginalFileForCompiledView() method extracts this path using the regex /\/\*\*PATH\s(.*)\sENDPATH/.

Sources: src/foundation/src/Concerns/ResolvesDumpSource.php130-139 tests/Foundation/fixtures/fake-compiled-view.php9

Editor Integration

The system generates clickable links that open files in your preferred editor at the specific line number.

Supported Editors

The $editorHrefs array defines URL schemes for popular editors:

EditorURL SchemeExample
atomatom://core/open/file?filename={file}&line={line}Atom editor
cursorcursor://file/{file}:{line}Cursor editor
phpstormphpstorm://open?file={file}&line={line}PhpStorm/IntelliJ
vscodevscode://file/{file}:{line}Visual Studio Code
vscode-insidersvscode-insiders://file/{file}:{line}VSCode Insiders
vscode-remotevscode://vscode-remote/{file}:{line}VSCode Remote
sublimesubl://open?url=file://{file}&line={line}Sublime Text
emacsemacs://open?url=file://{file}&line={line}Emacs
textmatetxmt://open?url=file://{file}&line={line}TextMate
novanova://core/open/file?filename={file}&line={line}Nova
macvimmvim://open/?url=file://{file}&line={line}MacVim
netbeansnetbeans://open/?f={file}:{line}NetBeans
xdebugxdebug://{file}@{line}Xdebug

Sources: src/foundation/src/Concerns/ResolvesDumpSource.php16-33

Editor Configuration

Editor links are configured via the app.editor configuration key. Multiple formats are supported:

Simple String Configuration


Array Configuration with Custom Base Path

For Docker or remote environments where the file path on the host differs from the container:


Array Configuration with Custom Href

For editors not in the predefined list or custom URL schemes:


Sources: src/foundation/src/Concerns/ResolvesDumpSource.php146-171 tests/Foundation/Http/HtmlDumperTest.php215-288

CliDumper Implementation

The CLI dumper outputs dumps with source information appended as a gray comment.

Output Format


Sources: src/foundation/src/Console/CliDumper.php56-76

Source Content Generation

The getDumpSourceContent() method formats the source information with ANSI color codes and optional hyperlinks:


When a file is a compiled view, the line number is omitted since it cannot be accurately mapped back to the original view.

Sources: src/foundation/src/Console/CliDumper.php81-97

Registration


Creates a VarCloner with UNSET_CLOSURE_FILE_INFO casters to hide internal closure details, then sets the global VarDumper handler to use the CliDumper instance.

Sources: src/foundation/src/Console/CliDumper.php46-53

HtmlDumper Implementation

The HTML dumper injects source information as styled HTML spans within the dump output.

Injection Strategy

The dumper searches for specific separators in the dump HTML to determine where to inject source information:


Sources: src/foundation/src/Http/HtmlDumper.php65-94

Source Content HTML

The getDumpSourceContent() method generates a gray-colored span with an optional hyperlink:


Sources: src/foundation/src/Http/HtmlDumper.php99-114

Separator Constants

ConstantValuePurpose
EXPANDED_SEPARATOR'class=sf-dump-expanded>'Injection point for expanded dumps (arrays, objects)
NON_EXPANDED_SEPARATOR"\n</pre><script>"Injection point for non-expanded dumps (scalars)

Sources: src/foundation/src/Http/HtmlDumper.php23-30

Custom Dump Source Resolvers

The system allows complete customization of source resolution logic.

Setting a Custom Resolver


Sources: src/foundation/src/Concerns/ResolvesDumpSource.php178-181

Disabling Source Resolution

To completely disable source information in dumps:


This sets the internal resolver to false, causing resolveDumpSource() to always return null.

Sources: src/foundation/src/Concerns/ResolvesDumpSource.php186-189

Caster Configuration

The dumpers are configured with default casters to prevent dumping internal framework objects:


These casters use StubCaster::cutInternals to hide internal properties that would create noisy, unhelpful dumps.

Sources: src/foundation/src/Providers/FoundationServiceProvider.php183-186

Recursive Dump Protection

Both dumpers implement a $dumping flag to prevent infinite recursion:


This prevents issues when the dumper needs to call dump() internally while generating source content.

Sources: src/foundation/src/Console/CliDumper.php60-64 src/foundation/src/Http/HtmlDumper.php67-71

Environment Variable Control

The VAR_DUMPER_FORMAT environment variable overrides automatic dumper selection:

ValueBehavior
htmlForce HtmlDumper
cliForce CliDumper
serverUse Symfony's server dumper (no source resolution)
tcp://host:portUse Symfony's TCP dumper (no source resolution)
(not set)Auto-detect based on php_sapi_name()

Sources: src/foundation/src/Providers/FoundationServiceProvider.php192-200

Testing Support

The dumpers include comprehensive test coverage demonstrating all features:

Test Scenarios

TestPurpose
Primitive typesVerify correct output for strings, integers, floats, booleans, null
Arrays and objectsVerify expanded format with source injection
Compiled view detectionTest isCompiledViewFile() logic
Original view extractionTest PATH comment parsing
Editor href generationTest all configuration formats
Unresolvable sourcesTest graceful fallback when source cannot be determined
Custom resolversTest resolveDumpSourceUsing() API

Sources: tests/Foundation/Console/CliDumperTest.php tests/Foundation/Http/HtmlDumperTest.php