phpzend-framework2firephp

Using FirePHP with Zend Framework 2


I'm trying to use FirePHP with Zend Framework 2, but there seems to be something missing. Here's the basic code I'm trying to run:

$writer = new Zend\Log\Writer\FirePhp();
$logger = new Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info('FirePHP logging enabled');

The error I get is "FirePHP Class not found". I was initially puzzled because I do have a FirePhp class in my Zend/Log/Writer folder. But then I saw that the class constructor requires a FirePhp\FirePhpInterface object. So I checked the Zend/Log/Writer/FirePhp folder and there's a FirePhpBridge class in there that implements FirePhpInterface, but it also requires a FirePHP instance in the constructor. I don't have any FirePHP.php file in my Zend/Log/Writer/FirePhp folder. Am I supposed to get this from somewhere else?

Update

I now have managed to get FirePHP working, but I'm trying to figure out how to do it in a clean way so this works. The only way I've gotten it to work is putting it in the root directory of my project and doing the following:

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');

I assume that normally I should be able to create a writer like so:

$writer = new Zend\Log\Writer\FirePhp();

However, where this goes wrong I believe is in the getFirePhp() function of the Zend\Log\Writer\FirePhp class. The class does this:

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()));
}

This is where I get lost as to how I'm supposed to set things up so that this class_exists('FirePHP') call finds the right class and new FirePHPService() also works properly.


Solution

  • Am I supposed to get this from somewhere else?

    Yes, you need to get FirePHP into your project and autoloading.

    If you're using composer (and I recommend that you do), just add:

    "firephp/firephp-core" : "dev-master"
    

    (or similar) in your composer.json and update. If you're not using composer, you should grab the firephp libs, and let your autoloader know about them.