tourze/backtrace-helper

Backtrace helper

0.0.7 2025-04-16 13:13 UTC

This package is auto-updated.

Last update: 2025-04-25 19:06:39 UTC


README

English | 中文

Latest Version Total Downloads

A PHP package for enhanced backtrace handling and exception printing with useful context information.

Features

  • Enhanced backtrace information with cleaner output
  • Intelligent filtering of irrelevant stack frames in production environments
  • Exception printer with rich context information
  • Support for context-aware exceptions
  • Clean class name formatting (especially for AOP proxies)
  • Easy integration with existing PHP applications

Installation

composer require tourze/backtrace-helper

Quick Start

<?php

use Tourze\BacktraceHelper\Backtrace;
use Tourze\BacktraceHelper\ExceptionPrinter;

// Get a formatted backtrace
$backtrace = Backtrace::create();
echo $backtrace->toString();

// Print an exception with enhanced information
try {
    // Some code that might throw an exception
    throw new \Exception("Something went wrong");
} catch (\Throwable $e) {
    echo ExceptionPrinter::exception($e);
}

// Create context-aware exceptions
class MyException extends \Exception implements \Tourze\BacktraceHelper\ContextAwareInterface 
{
    use \Tourze\BacktraceHelper\ContextAwareTrait;
}

throw new MyException("Error with context", 0, null, ["user_id" => 123]);

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

The MIT License (MIT). Please see License File for more information.