我试图在Zend Framework 2中使用FirePHP,但似乎有些东西缺失。这里是我试图运行的基本代码:在Zend Framework 2中使用FirePHP
$writer = new Zend\Log\Writer\FirePhp();
$logger = new Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info('FirePHP logging enabled');
我得到的错误是“FirePHP Class not found”。我最初感到困惑,因为我的Zend/Log/Writer文件夹中有一个FirePhp类。但后来我看到类构造函数需要一个FirePhp \ FirePhpInterface对象。所以我检查了Zend/Log/Writer/FirePhp文件夹,并且在那里有一个实现FirePhpInterface的FirePhpBridge类,但是它在构造函数中也需要一个FirePHP实例。我的Zend/Log/Writer/FirePhp文件夹中没有任何FirePHP.php文件。我应该从别的地方得到这个吗?
更新
我现在设法得到FirePHP的工作,但我试图找出如何做到这一点在这样一个干净的方式工作的。我已经得到了它工作的唯一方法就是把它在我的项目的根目录下,并执行以下操作:
include_once('FirePHP.php');
$writer = new Zend\Log\Writer\FirePhp(new Zend\Log\Writer\FirePhp\FirePhpBridge(FirePHP::getInstance(true)));
$logger = new Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info('FirePHP logging enabled');
我认为平时我应该能够创造像这样一个作家:
$writer = new Zend\Log\Writer\FirePhp();
但是,如果出现错误,我相信是在Zend \ Log \ Writer \ FirePhp类的getFirePhp()函数中。该类做到这一点:
if (!$this->firephp instanceof FirePhp\FirePhpInterface
&& !class_exists('FirePHP')
) {
// No FirePHP instance, and no way to create one
throw new Exception\RuntimeException('FirePHP Class not found');
}
// Remember: class names in strings are absolute; thus the class_exists
// here references the canonical name for the FirePHP class
if (!$this->firephp instanceof FirePhp\FirePhpInterface
&& class_exists('FirePHP')
) {
// FirePHPService is an alias for FirePHP; otherwise the class
// names would clash in this file on this line.
$this->setFirePhp(new FirePhp\FirePhpBridge(new FirePHPService()));
}
这是我迷路,以我应该如何设置的东西,所以这class_exists(“FirePHP”)调用找到正确的类和新FirePHPService()也适用正常。
OK,所以我下载了FirePHP文件,并设法得到这个工作的“贫民窟”的方式。意思是,我做了一个include('FirePHP.class。PHP的')在我的引导文件,我可以通过创建一个这样的作家运行的东西︰$ writer = new Zend \ Log \ Writer \ FirePhp(新的Zend \ Log \ Writer \ FirePhp \ FirePhpBridge(FirePHP :: getInstance(true)) );但我有点失落,我实际上可以像我的代码的名字空间和利用Zend \ Di模块一样干净地工作。我在我的文章中添加了详细信息。 – Rocket04