Debug in Zend Framework using FirePHP

Zend Framework and FrePHP

There is one rule — not to show the customer the debug information for this purpose usually there are two configurations, but if the customer is very curious, or You, for aesthetic reasons, want to hide kilobytes debug information? These good intentions will help us FirePHP.


For those who do not know — FirePHP is a plug-in extension FireBug for Mozilla Firefox


For this purpose we need Your Zend Framewrok'native project to change a little bootsrap.php and add a couple of files in the library. Start with simple — change bootstrap:
// this piece of code is inserted after loading the config file
{
// variable from config, which is responsible for the output of debug information
if ($config->application->debug) {
/* Turn on all errors and STRICT notices */
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);

require_once 'Core/Debug.php'; // connect the class Core_Debug - what's he doing read more
Core_Debug::setEnabled(true);
Core_Debug::getGenerateTime('Begin');
} else {
/* Turn off all errors */
error_reporting(0);
ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
}
}


// this inclusion after the initialization of the DB adapter
{
// something it intim
$dbAdapter = Zend_Db::factory($config->database);

// the plug-in Profiler
if ($config->application->debug) {
require_once 'Core/Db/Profiler.php'; // connected Core_Db_Profiler is not quite a standard Profiler to the database
$profiler = new Core_Db_Profiler('Profiler');
$profiler->setEnabled(true);

$dbAdapter->setProfiler($profiler);
}
}


Now, on to the delicious...

the

DB_Profiler


Core_Db_Profiler (although all the rules he should be called Core_Db_Profiler_Firebug) this is the class for debugging work with the database application (see Zend DB Profiler), it inherited from Zend_Db_Profiler_Firebugcontains only one change — added backtrace, because it is very helpful to know where was made a request to the database.
It looks like the following (clickable):
DB_Profiler

the

Debug


Class Core_Debug inherited from Zend_Debug and expands its functionality to work with FirePHP, added debug function that dumps information about a variable (-tion) in the console of Fire Bug and give an example PHP code:

$a = $b = $c = array(123, 456, 789);
Core_Debug::debug($a); // print a single variable
Core_Debug::debug($a, $b, $c); // print some variables

You can see the result in the console:
Debug

The last line of backtrace is displayed — so there was no problem finding the line where You call debug. But there is this way of debugging one problem — if too much data, the browser just the most intriguing moment, trying to execute JavaScript.

There is another useful feature in the class Core_Debug — it is called getGenerateTime — that's what we called right after connection Core_Debug — the main task of this function is to write the timestamps on the code, i.e. method to call the first time — the time of the call is preserved, the second callee — save (print) the difference between the previous and the first challenge. As an example, my code is the three calls:
// right after connection Core_Debug
require_once 'Core/Debug.php';
Core_Debug::setEnabled(true);
Core_Debug::getGenerateTime('Begin');
/* ... */
// Index Action in Index Controller
Core_Debug::getGenerateTime('IndexAction');
/* ... */
// before dispatch
Core_Debug::getGenerateTime('Before Dispatch');
Zend_Controller_Front::getInstance()->dispatch();


The result will again be the FireBug console:

Timer

Where:
the
    the
  • Time (sec) — the time from the previous "notch"
  • the
  • Total (sec) — the time from the first "notch"
  • the
  • Memory (Kb) — number of memory eating from the previous "notch"
  • the
  • Total (Kb) — number of memory eating all the time


These classes You can download at the following link: FirePHP Debug (2.5 Kb)

Related links:
the

PS Thanks Baziakfor the idea.

Link to article in my blog: the Debug in Zend Framework using FirePHP
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

Briefly on how to make your Qt geoservice plugin

Database replication PostgreSQL-based SymmetricDS

Yandex.Widget + adjustIFrameHeight + MooTools