An expandable PHP debugger panel.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Fire
Test
demo
.gitignore
LICENSE
README.md
RELEASE.md
composer.json
functions.php

README.md

FireBug

An expandable PHP debugger panel.

The true power of FireBug is that it can easily be added to any project and expanded upon! You can even create your own panels to track whatever data you care about while your going through debugging. FireBug comes featured with a Debuggers panel. Which allows you to call debugger() anywhere inside of your application. All debuggers will display the entire debug_trace along with var_dump within the "Debuggers" section of the FireBug Panel.

FireBug API Documentation

FireBug API Documentation

Installation

  1. Add ua1-labs\firebug:dev-master to your require-dev configuration in your composer.json file.

     "require": {
         "ua1-labs/firebug": "dev-master"
     }
    
  2. Run composer install

Enable FireBug

For performance reasons, firebug is initially disabled and needs enabled in order to use it. Here's how:

$fireBug = Fire\Bug::get();
$fireBug->enable();

FireBug Timer

Once FireBug is enabled, it will start a timer that will report how much time it takes to load your page and return your request. Keep in mind, that times are determined by when you enable FireBug.

Render FireBug

Once you've installed FireBug, it's time to output it somewhere in your HTML.

$fireBug = Fire\Bug::get();
echo $fireBug->render();

When rendering out FireBug, it is suggested that you place it the footer of your application.

Debugger Panel

As mentioned before, FireBug comes bundled with a "Debuggers" panel. This panel allows you to replace your use of var_dump and debug_trace. When FireBug is installed in your application, all you have to do is call the debugger(mixed $value); function and let FireBug do the work. This function can take any value and will simply var_dump and debug_trace it within the "Debuggers" panel of FireBug.

Example:

debugger('debug value...');

Debuggers also take a second parameter called exit. If you decide you need to exit the execution of any process and render the debug panel at that point in execution, you may do so by passing in true as a second parameter.

Example:

debugger('debug value...', true);

Debugger Panel and X-Debug Overlay

In this project, it was decided to disable x-debug overlay for var_dumps. This makes it easier to read the entire output of debuggers without having to scroll to much left and right. So, if you would like to enable it, here is the code you will want to run when you initize your application.

$fireBug = Fire\Bug::get();
$debuggerPanel = $fireBug->getPanel(Fire\Bug\Panel\Debugger::ID);
$fireBug->enableXDebugOverlay();

Creating And Registering Your Own Panel

We've given you everything you need to easily create your own panel.

  1. Create your own Panel Class:

     namespace Fire\Bug\Panel;
    
     use Fire\Bug\Panel;
    
     class MyOwnPanel extends Panel
     {
         const ID = 'myOwnPanel';
         const NAME = 'My Own Panel';
         const TEMPLATE = '/pathto/my-own-panel.phtml';
    
         public $myName;
    
         public function __construct()
         {
             parent::__construct(self::ID, self::NAME, __DIR__ . self::TEMPLATE);
             $this->myName = 'Testy Testerson';
         }
    
         public function myInfo()
         {
             return '1 Awesome Dude, Orlando, FL, 32708';
         }
     }
    
  2. Create a panel template file:

     <div class="my-own-panel">
         <?php echo $this->myName; ?>
         <?php echo $this->myInfo(); ?>
     </div>
    
  3. Register Your Panel

     $fireBug = Fire\Bug::get();
     $fireBug->addPanel(new Fire\Bug\Panel\MyOwnPanel());
    

Three easy steps and you just added your own panel to FireBug! Now with that being said, here is some info about how it works behind the scenes. Panels act as ViewModels. In the way that any data or methods you add to the panel object itself will also be available to the template object. In the example panel above you can see that the panel was created with a public property called myName and a method myInfo. In the template, you can see we are echoing out these values.

Timer

FireBug also comes bundled with a timer you may use to detect how much time a process takes. Here's how to use the timer:

$fireBug = Fire\Bug::get();
//get a start time
$startTime = $fireBug->timer();
//get time length in milliseconds
$timeLength = $fireBug->timer($startTime);

FireBug API

/**
 * Gets the instance of Fire\Bug.
 * @return Fire\Bug
 */
static function get()

/**
 * Destroys the current instance of FireBug.
 * @return void
 */
static function destroy()

/**
 * Enables FireBug
 * @return void
 */
public function enable()

/**
 * Determines if firebug is enabled.
 * @return boolean
 */
public function isEnabled()

/**
 * Adds a Fire\Bug\Panel object to the the array of panels.
 * @param Fire\Bug\Panel $panel The panel you are adding to FireBug
 */
public function addPanel(Panel $panel)

/**
 * Gets a stored panel object by its ID.
 * @param [type] $id The id of defined on the Fire\Bug\Panel instance object.
 * @return [type] Fire\Bug\Panel
 */
public function getPanel($id)

/**
 * Gets all stored panels.
 * @return array<Fire\Bug\Panel>
 */
public function getPanels()

/**
 * Method used to measure the amount of time that passed in milliseconds.
 * If you pass in a $start time, then you will be returned time length from
 * the start time. If you don't pass anything in, a start time will be returned.
 * @param  float|null $start The start time.
 * @return float
 */
public function timer($start = null)

/**
 * If the timer was started, the load time will be returned
 * @return float
 */
public function getLoadTime()

/**
 * Method used to render FireBug.
 * @return void
 */
public function render()