mortenscheel / tracer
A PHP library for advanced stack trace handling and debugging.
0.2.0
2025-03-15 17:33 UTC
Requires
- php: ^8.2.0
- illuminate/collections: ^11|^12
- mortenscheel/editor-links: ^0.2.0
Requires (Dev)
- laravel/pint: ^1.18.3
- nunomaduro/collision: ^8.5
- pestphp/pest: ^3.7.1
- pestphp/pest-plugin-type-coverage: ^3.2.3
- phpro/grumphp-shim: ^2.10
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- rector/rector: ^2.0.4
- symfony/var-dumper: ^7.2.0
This package is auto-updated.
Last update: 2025-03-15 19:25:48 UTC
README
# TracerA PHP library for advanced stack trace handling and debugging.
Installation
composer require mortenscheel/tracer
Features
- Get detailed stack traces with clean filtering options
- Easily ignore vendor frames, specific classes, methods, files, or lines
- StackTrace is a Laravel Collection
- Format stack frames for debugging and display
- Generate editor links (see mortenscheel/editor-links)
- Serializable frames for logging or error reporting
Usage
Basic Usage
use Scheel\Tracer\StackTrace; // Get a full stack trace $trace = StackTrace::getTrace(); // Access the first frame $firstFrame = $trace->first(); // Convert to array for inspection $frames = $trace->toArray();
Filtering Frames
use Scheel\Tracer\StackTrace; use Scheel\Tracer\Frame; // Ignore vendor frames $trace = StackTrace::getTrace()->ignoreVendor(); // Ignore specific classes $trace = StackTrace::getTrace()->ignoreClass(SomeClass::class); // Ignore specific class methods $trace = StackTrace::getTrace()->ignoreClass(SomeClass::class, 'methodName'); // Ignore specific files $trace = StackTrace::getTrace()->ignoreFile('/path/to/file.php'); // Ignore specific lines in files $trace = StackTrace::getTrace()->ignoreFile('/path/to/file.php', 123); // Custom filtering using the filter method $trace = StackTrace::getTrace()->filter(function (Frame $frame): bool { return $frame->class !== 'ClassToIgnore'; });
Working with Frames
use Scheel\Tracer\StackTrace; $frame = StackTrace::getTrace()->first(); // Get frame location as string echo $frame->location(); // "/path/to/file.php:123" // Convert frame to array $frameData = $frame->toArray(); /* [ 'file' => '/path/to/file.php', 'line' => 123, 'function' => 'methodName', 'class' => 'ClassName', 'type' => '::', ] */ // Generate editor links echo $frame->editorLink(); // "phpstorm://open?file=/path/to/file.php&line=123"
Running Tests
composer test
License
MIT
Author
Morten Scheel