除了 Kudehinbu 的工作和我自己的工作,即重构https://github.com/frankforte/quantumphp提供的 QuantumPHP 类,为开发人员提供从 FirePHP 更无缝的方法和迁移过程,我还可以补充一点,与 FirePHP 不同,当对象是info()、warn()或error()方法的参数的一部分时,客户端渲染不会越过简洁的 [object Object] 。
要详尽地开发一个对象,就像 FirePHP 所做的那样,您可能希望在调用 QuantumPHP 类的输出方法之前使用print_r()或var_export()转换$args,或者更好的是,作为私有/受保护的转换器。类本身。
protected function resolveObjectArgs(array &$args)
{
array_walk($args, function(&$value, $key) {
if (is_array($value)) {
$value = print_r($value, true);
}
else if(is_object($value)) {
$value = var_export($value, true);
}
else return;
});
}
因此在输出方法中调用这个转换器:
public function info()
{
$args = func_get_args();
$this->resolveObjectArgs($args); // <== this is the line to add to the existing code
return $this->_log(self::INFO, $args);
}
请注意,在我的重构之后,info()现在是public并且不再是public static,因为我决定使用对象上下文。
最后,利用公共上下文,您可能需要添加一个析构函数:
public function __destruct()
{
$this->send();
}
从而避免在 PHP 脚本最后一次调用 QuantumPHP 方法后系统地显式调用 send 方法。
客户端使用示例:
$QPHP = QuantumPHP::getInstance();
$Obj = new MyOwnObject();
$QPHP->info($Obj); // will eventually output a detailed structure of your object
// send() gets called magically at the end of the page!