gajus/bugger

Bugger 是一个用于调试 PHP 代码的函数集合。

安装: 30

依赖: 0

建议者: 0

安全性: 0

星星: 77

关注者: 7

分支: 7

开放问题: 10

语言:CSS

0.2.1 2014-04-25 11:30 UTC

This package is not auto-updated.

Last update: 2024-09-14 14:45:13 UTC


README

Build Status Coverage Status Latest Stable Version License

Bugger 是一个用于调试 PHP 代码的函数集合。使用它来

  • 输出变量的信息
  • 在循环中设置断点

Bugger 设计用于在没有远程调试器的情况下使用。它允许在调试回溯(trace 方法)中一起输出变量的信息,它允许在脚本执行期间收集多个变量的信息,并在脚本执行结束时输出它们(stack 方法),以及捕获迭代(tick 方法)。

API

Bugger API 通过三个函数暴露给全局命名空间

Trace

/**
 * Terminates the script, discards the output buffer, dumps information about the expression including backtrace up to the `trace` call.
 * 
 * @param mixed $expression The variable you want to dump.
 * @return null
 */
trace ( mixed $expression );

Trace 用于输出表达式信息,包括回溯信息。Trace 将尝试丢弃现有的输出缓冲区。如果输出缓冲区无法丢弃,因为它已经被发送到浏览器,那么 Bugger 将尝试使用客户端脚本清除先前的输出。

Trace output

Stack

/**
 * Stacks information about the expression and dumps the stack at the end of the script execution.
 *
 * @param mixed $expression The variable you want to dump.
 * @return null
 */
stack ( mixed $expression );

Stack 与 trace 相同,但调用 stack 不会在调用时终止脚本。如果在脚本执行期间至少调用一次 stack,则脚本执行结束时将丢弃输出缓冲区,并用收集到的 stack 输出替换,例如:

echo 'foo';
stack('a');
echo 'bar';
stack('b');
echo 'baz';
stack('c');
echo 'qux';

在上面的示例中,'foo'、'bar'、'baz' 和 'qux' 将被丢弃。

Stack output

Tick

/**
 * Tracks the number of times tick function itself has been called and returns true
 * when the desired number within the namespace is reached.
 *
 * @param int $true_after Number of the itteration after which response is true.
 * @param string $namespace Itteration namespace.
 * @return boolean
 */
tick ( int $true_after [, string $namespace = 'default' ] )

tick 用于捕获在循环或递归调用中的脚本执行。tick 在执行了预定义的次数或更多次后返回 true,例如:

while (true) {
    if (tick(10)) {
        // Tick will return true after 10 itterations.
        break;
    }
}

tick(4, 'test'); // false
tick(4, 'test'); // false
tick(4, 'test'); // false
tick(4, 'test'); // true
tick(4, 'test'); // true
tick(4, 'test'); // true

tick 可以与 stacktrace 一起使用来捕获特定迭代或多个迭代的状态。

Tick output

安装

推荐使用 Composer 使用 Bugger。

{
    "require": {
       "gajus/bugger": "0.2.*"
    }
}

如果您想在服务器上使用 Bugger,则使用 auto_prepend_file 设置加载 ./src/autoload.php

路线图

  • 支持 CLI。