2017 © Pedro Peláez
 

library nicetrace

Library to make human-friendly PHP backtrace arrays.

image

donquixote/nicetrace

Library to make human-friendly PHP backtrace arrays.

  • Sunday, March 6, 2016
  • by donquixote
  • Repository
  • 1 Watchers
  • 0 Stars
  • 24 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 4 % Grown

The README.md

nicetrace

PHP library to generate a human-friendly backtrace array., (*1)

Inspired from ddebug_backtrace() in the Devel module for Drupal., (*2)

The structure of the nicetrace can be seen in nicetrace.php, (*3)

Development status

This library is quite fresh, and I am still ironing out API details, that is, names of interfaces, method signatures, etc.
You are welcome to participate., (*4)

Features

The main design goal is a backtrace array structure that looks nice in recursive array display tools, such as Krumo, or possibly Ladybug., (*5)

  • Indices of trace items enhanced with function / method names.
  • Indices for arguments enhanced with parameter names (based on reflection).
  • Indices of trace items reversed, so that the index reflects the depth in the call tree.
  • Arguments inlined, so the array becomes flatter. E.g.
    $backtrace[5]['args'][0] = .. becomes
    $nicetrace[' 8: foo()']['args[0]: $x'] = ...
  • Filename and line number from trace item one level deeper, instead of the "called from".
  • File paths shortened, if known base paths are specified.
  • File basename and line number combined into one array key. E.g.
    $backtrace[5]['file'] = '/../src/MyNamespace/MyFile.php'; $backtrace[5]['line'] = 97; becomes
    $nicetrace[' 8: foo()']['MyClass.php: 97'] = 'src/MyNamespace/MyClass.php';

Basic usage

use Donquixote\Nicetrace\Util\NicetraceUtil;

$backtrace = debug_backtrace();
$nicetrace = NicetraceUtil::backtraceGetNicetrace($backtrace);

// Choose your favourite recursive function/method for recursive printing.
print_r($nicetrace);

Advanced usage

The library allows to create and compose custom BacktraceToNicetrace handlers., (*6)

It is recommended to use the fluent interface provided by the Builder class., (*7)

use Donquixote\Nicetrace\BacktraceToNicetrace\BacktraceToNicetraceBuilder;

$backtrace = debug_backtrace();
$backtraceToNicetrace = BacktraceToNicetraceBuilder::start()
  ->withClasslessKey()
  ->create();
$nicetrace = NicetraceUtil::backtraceGetNicetrace($backtrace);

// Choose your favourite recursive function/method for recursive printing.
print_r($nicetrace);

The test case gives some examples., (*8)

The Versions

06/03 2016

dev-master

9999999-dev http://github.com/donquixote/nicetrace

Library to make human-friendly PHP backtrace arrays.

  Sources   Download

MIT

by Andreas Hennings

06/03 2016

0.0.4

0.0.4.0 http://github.com/donquixote/nicetrace

Library to make human-friendly PHP backtrace arrays.

  Sources   Download

MIT

by Andreas Hennings

06/03 2016

0.0.3

0.0.3.0 http://github.com/donquixote/nicetrace

Library to make human-friendly PHP backtrace arrays.

  Sources   Download

MIT

by Andreas Hennings

06/03 2016

0.0.2

0.0.2.0 http://github.com/donquixote/nicetrace

Library to make human-friendly PHP backtrace arrays.

  Sources   Download

MIT

by Andreas Hennings

06/03 2016

0.0.1

0.0.1.0 http://github.com/donquixote/nicetrace

Library to make human-friendly PHP backtrace arrays.

  Sources   Download

MIT

by Andreas Hennings

06/03 2016

0.0.0

0.0.0.0 http://github.com/donquixote/nicetrace

Library to make human-friendly PHP backtrace arrays.

  Sources   Download

MIT

by Andreas Hennings