mortenscheel/tracer 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mortenscheel/tracer

最新稳定版本:0.2.0

Composer 安装命令:

composer require mortenscheel/tracer

包简介

A PHP library for advanced stack trace handling and debugging.

README 文档

README

GitHub Workflow Status (master) Total Downloads Latest Version License

# Tracer

A 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

统计信息

  • 总下载量: 5.84k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-15