此包已被废弃,不再维护。未建议替代包。

一个简单的 PHP 调试模块

dev-master 2016-09-24 09:21 UTC

This package is not auto-updated.

Last update: 2022-04-06 07:11:52 UTC


README

此包提供了一种简单的方式,在外部工具(如xDebug)不可用的情况下,从应用程序内部生成调试输出。

包含

  • 启用/禁用标志
  • 条件输出限制(通过传递闭包/可调用对象)
  • 可选的样式化/格式化
  • 内存中的日志记录,用于延迟渲染
  • 在单例/静态上下文中调用

此包是 ControlAltKaboom/BoomStick 框架的一部分

安装

切换调试模式

Debug::instance()->setDebugMode(TRUE); // Enables debug-mode
Debug::instance()->setDebugMode(FALSE); // Disables debug-mode

设置条件输出函数

// Using a function as a callback
function UserIsEnabled() {
  // your code
  return TRUE;
}
Debug::instance()->setCondition("UserIsEnabled"); // Evaluates the condition a run-time and outputs based on its return-value

// Using a class/method as a callback
Debug::instance()->setCondition(["\\YourNameSpace\\\YourClass", "methodName"]);

// Using an anonymous function (with optional variable assignment)
Debug::instance()->setCondition( 
  function() use($yourvar) { return TRUE; }
);

输出调试数据

$testVar = [
  "test" => "something",
  "foo"  -> "bar"
  "walrus" => [
    "status" => "awesome",
    "plural" => "walri",
    "asPets" => AskProfessionals->areGoodPets("walrus")
    ]
  ];

Debug::instance()->debug($testVar); // Directly outputs the debug-vars

$debugData = Debug::instance()->debug($testVar, TRUE); // Returns the output as a string

延迟输出

$testVar = ["foo" => "bar"];
Debug::instance()->log("testvar", $testVar);

$testVar2 = ["walrus" => "are awesome!"];
Debug::instance()->log("another reference", $testVar2);

// .. later on ..
Debug::instance()->showLog();