0

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.

Rocket04
  • 1,801
  • 5
  • 25
  • 47

2 Answers2

2

First you should add this code to Module.php of your module

    return array(
        //...
        'Zend\Loader\ClassMapAutoloader' => array(
                __DIR__ . '/autoload_classmap.php',
        ),
    );

and here content of autoload_classmap.php

<?php

return array(
    'FirePHP' => realpath(APPLICATION_PATH . '/vendor/FirePHP').'/FirePHP.php',
);

FirePHP.php(renamed from FirePHP.class.php) downloaded from official site.

then you can write below code in any place of your module and it will work

use Zend\Log\Writer\FirePhp;
use Zend\Log\Logger;

    $writer = new FirePhp();
    $logger = new Logger();
    $logger->addWriter($writer);
    $logger->info("hi");
BigBadAlien
  • 236
  • 3
  • 8
0

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.

timdev
  • 61,857
  • 6
  • 82
  • 92
  • OK, so I downloaded the FirePHP files and managed to get this working the "ghetto" way. Meaning, I did an include('FirePHP.class.php') in my bootstrap file and I can run things by creating a writer like so: $writer = new Zend\Log\Writer\FirePhp(new Zend\Log\Writer\FirePhp\FirePhpBridge(FirePHP::getInstance(true))); But I'm a bit lost on how I can actually get this working cleanly like the rest of my code which is namespaced and taking advantage of the Zend\Di module. I'm adding details in my post. – Rocket04 Dec 06 '12 at 14:07