PHP_Debug, package sources
Sourceforge release : V2.1.4
Pear release : V1.0.2
PHP/Debug.php
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* PHP_Debug : A simple and fast way to debug your PHP code
*
* The basic purpose of PHP_Debug is to provide assistance in debugging PHP
* code, by 'debug' i don't mean 'step by step debug' but program trace,
* variables display, process time, included files, queries executed, watch
* variables... These informations are gathered through the script execution and
* therefore are displayed at the end of the script (in a nice floating div or a
* html table) so that it can be read and used at any moment. (especially
* usefull during the development phase of a project or in production with a
* secure key/ip)
*
* PHP version 5 only
*
* Copyright (c) 2007 - Vernet Loïc
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @category PHP
* @package PHP_Debug
* @author Vernet Loïc <qrf_coil[at]yahoo.fr>
* @copyright 1997-2007 The PHP Group
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://pear.php.net/package/PHP_Debug
* @link http://phpdebug.sourceforge.net
* @link http://www.php-debug.com
* @see Text_Highlighter
* @see Var_Dump, SQL_Parser
* @since 1.0.0RC1
* @version CVS: $Id: Debug.php,v 1.3 2008/08/31 19:32:50 c0il Exp $
*/
/**
* Factory class for renderer of Debug class
*
* @see Debug/Renderer/*.php
*/
require_once 'PHP/DebugLine.php';
require_once 'PHP/Debug/Renderer.php';
/**
* External constants
*
* @filesource
* @package PHP_Debug
*/
if (!defined('CR')) {
define('CR', "\n");
}
class PHP_Debug
{
/**
* Possible version of class Debug
*/
const VERSION_STANDALONE = 0;
const VERSION_PEAR = 1;
const VERSION_DEFAULT = self::VERSION_STANDALONE;
const VERSION = self::VERSION_STANDALONE;
const RELEASE = 'V2.1.4';
const PEAR_RELEASE = 'V1.0.2';
/**
* These are constant for dump() and DumpObj() functions.
*
* - DUMP_DISP : Tell the function to display the debug info.
* - DUMP_STR : Tell the fonction to return the debug info as a string
* - DUMP_VARNAME : Default name of Array - DBG_ARR_OBJNAME : Default name
* of Object
*/
const DUMP_DISP = 1;
const DUMP_STR = 2;
const DUMP_VARNAME = 'Variable';
/**
* These are constant for addDebug functions, they set the behaviour where
* the function should add the debug information in first or in last
* position
*/
const POSITIONLAST = 0;
const POSITIONFIRST = 1;
/**
* These are constants to define Super array environment variables
*/
const GLOBAL_GET = 0;
const GLOBAL_POST = 1;
const GLOBAL_FILES = 2;
const GLOBAL_COOKIE = 3;
const GLOBAL_REQUEST = 4;
const GLOBAL_SESSION = 5;
const GLOBAL_GLOBALS = 6;
/**
* Default configuration options
*
* @since V2.0.0 - 16 apr 2006
* @see setOptions()
* @var array
*/
protected $defaultOptions = array(
'render_mode' => 'Div', // Renderer mode
'render_type' => 'HTML', // Renderer type
'restrict_access' => false, // Restrict or not the access
'allowed_ip' => array('127.0.0.1'), // Authorized IP to view the debug when restrict_access is true
'allow_url_access' => false, // Allow to access the debug with a special parameter in the url
'url_key' => 'debug', // Key for url instant access
'url_pass' => 'true', // Password for url instant access
'enable_watch' => false, // Enable the watch function
'replace_errorhandler' => true, // Replace or no the PHP errorhandler
'lang' => 'EN', // Language
);
/**
* Default static options for static functions
*
* @since V2.0.0 - 16 apr 2006
* @see dump()
* @var array
*/
protected static $staticOptions = array(
'dump_method' => 'print_r', // print_r or var_dump
'pear_var_dump_method' => 'Var_Dump::display' // Var_Dump display funtion (not used for now)
);
/**
* Functions from this class that must be excluded in order to have the
* correct backtrace information
*
* @see PHP_DebugLine::setTraceback()
* @since V2.0.0 - 13 apr 2006
* @var array
*/
public static $excludedBackTraceFunctions = array(
'add',
'dump',
'error',
'query',
'addDebug',
'setAction',
'addDebugFirst',
'watchesCallback',
'errorHandlerCallback'
);
/**
* Correspondance between super array constant and variable name
* Used by renderers
*
* @since V2.0.0 - 18 apr 2006
* @var array
*/
public static $globalEnvConstantsCorresp = array(
self::GLOBAL_GET => '_GET',
self::GLOBAL_POST => '_POST',
self::GLOBAL_FILES => '_FILES',
self::GLOBAL_COOKIE => '_COOKIE',
self::GLOBAL_REQUEST=> '_REQUEST',
self::GLOBAL_SESSION=> '_SESSION',
self::GLOBAL_GLOBALS=> 'GLOBALS'
);
/**
* Default configuration options
*
* @since V2.0.0 - 13 apr 2006
* @see setOptions()
* @var array
*/
protected $options = array();
/**
* This is the array where the debug lines are collected.
*
* @since V2.0.0 - 11 apr 2006
* @see DebugLine
* @var array
*/
protected $debugLineBuffer = array();
/**
* This is the array containing all the required/included files of the
* script
*
* @since V2.0.0 - 17 apr 2006
* @see render(), PHP_DebugLine::TYPE_TEMPLATES
* @var array
*/
protected $requiredFiles = array();
/**
* This is the array containing all the watched variables
*
* @since V2.0.0 - 16 apr 2006
* @see watch()
* @var array
*/
protected $watches = array();
/**
* Execution start time
*
* @since V2.0.0 - 11 apr 2006
* @see __construct()
* @var float
*/
protected $startTime;
/**
* Exection end time
*
* @since V2.0.0 - 11 apr 2006
* @see render()
* @var float
*/
protected $endTime;
/**
* Number of queries executed during script
*
* @since V2.0.0 - 19 apr 2006
* @var integer
*/
protected $queryCount = 0;
/**
* PHP_Debug class constructor
*
* Here we set :
* - the execution start time
* - the options
* - the error and watch call back functions
*
* @param array $options Array containing options to affect to Debug
* object and his childs
*
* @since V2.0.0 - 11 apr 2006
*/
function __construct($options = array())
{
$this->startTime = PHP_Debug::getMicroTimeNow();
$this->options = array_merge($this->defaultOptions, $options);
$this->setWatchCallback();
$this->setErrorHandler();
}
/**
* Add a debug information
*
* @param string $info The main debug information
* (may be empty for some debug line types)
* @param integer $type Type of the DebugLine
*
* @see Debug constants
* @since V1.0.0 - 07 Apr 2006
*/
public function addDebug($info, $type = PHP_DebugLine::TYPE_STD,
$position = self::POSITIONLAST)
{
// Add info
$debugLine = new PHP_DebugLine($info, $type);
if ($position == self::POSITIONLAST) {
$this->debugLineBuffer[] = $debugLine;
} else {
array_unshift($this->debugLineBuffer, $debugLine);
}
// Additional process for some types
switch ($type) {
case PHP_DebugLine::TYPE_QUERY:
$this->queryCount++;
break;
default:
break;
}
// Return debugline
return $debugLine;
}
/**
* Add a debug info before all the existing other debug lines
* It is an alias for addDebug($info, self::POSITIONLAST)
*
* @see addDebug
* @since V1.0.0 - 13 Apr 2006
*/
public function addDebugFirst($info, $type = PHP_DebugLine::TYPE_STD)
{
return $this->addDebug($info, $type, self::POSITIONFIRST);
}
/**
* This is an alias for the addDebug function
*
* @see addDebug()
* @since V2.0.0 - 20 apr 2006
*/
public function add($info, $type = PHP_DebugLine::TYPE_STD)
{
return $this->addDebug($info, $type);
}
/**
* This is an alias for the addDebug function when wanting to add a query
* debug information
*
* @see addDebug(), PHP_DebugLine::TYPE_QUERY
* @since V2.0.0 - 21 Apr 2006
*/
public function query($qry)
{
return $this->addDebug($qry, PHP_DebugLine::TYPE_QUERY);
}
/**
* This is an alias for the addDebug function when wanting to add a
* database related debug info
*
* @see addDebug(), PHP_DebugLine::TYPE_QUERYREL
* @since V2.1.0 - 3 apr 2007
*/
public function queryRel($info)
{
return $this->addDebug($info, PHP_DebugLine::TYPE_QUERYREL);
}
/**
* This is an alias for the addDebug function when wanting to add an
* application error
*
* @see addDebug(), PHP_DebugLine::TYPE_APPERROR
* @since V2.0.0 - 21 Apr 2006
*/
public function error($info)
{
return $this->addDebug($info, PHP_DebugLine::TYPE_APPERROR);
}
/**
* This is an alias for adding the monitoring of processtime
*
* @see addDebug(), PHP_DebugLine::TYPE_PROCESSPERF
* @since V2.1.0 - 21 Apr 2006
*/
public function addProcessPerf()
{
return $this->addDebug('', PHP_DebugLine::TYPE_PROCESSPERF);
}
/**
* This a method to dump the content of any variable and add the result in
* the debug information
*
* @param mixed $var Variable to dump
* @param string $varname Name of the variable
*
* @since V2.0.0 - 25 Apr 2006
*/
public function dump($obj, $varName = '')
{
$info[] = $varName;
$info[] = $obj;
return $this->addDebug($info, PHP_DebugLine::TYPE_DUMP);
}
/**
* Set the main action of PHP script
*
* @param string $action Name of the main action of the file
*
* @since V2.0.0 - 25 Apr 2006
* @see PHP_DebugLine::TYPE_CURRENTFILE
*/
public function setAction($action)
{
$this->add($action, PHP_DebugLine::TYPE_PAGEACTION);
}
/**
* Add an application setting
*
* @param string $action Name of the main action of the file
*
* @since V2.1.0 - 02 Apr 2007
* @see PHP_DebugLine::TYPE_ENV
*/
public function addSetting($value, $name)
{
$this->add($name. ': '. $value, PHP_DebugLine::TYPE_ENV);
}
/**
* Add a group of settings
*
* @param string $action Name of the main action of the file
*
* @since V2.1.0 - 2 Apr 2007
* @see PHP_DebugLine::TYPE_ENV
*/
public function addSettings($values, $name)
{
$this->add($name. ': '.
PHP_Debug::dumpVar(
$values,
$name,
false,
PHP_Debug::DUMP_STR
),
PHP_DebugLine::TYPE_ENV
);
}
/**
* Set the callback fucntion to process the watches, enabled depending of
* the options flag 'enable_watch'
*
* @since V2.0.0 - 16 apr 2006
* @see options, watches, watchesCallback()
*/
protected function setWatchCallback()
{
if ($this->options['enable_watch'] == true) {
if (count($this->watches) === 0) {
$watchMethod = array($this, 'watchesCallback');
register_tick_function($watchMethod);
}
}
}
/**
* Set the callback function to process replace the php error handler,
* enabled depending of the options flag 'replace_errorhandler'
*
* @since V2.0.0 - 16 apr 2006
* @see options, errorHandlerCallback()
*/
protected function setErrorHandler()
{
if ($this->options['replace_errorhandler'] == true) {
$errorhandler = array(
$this,
'errorHandlerCallback'
);
set_error_handler($errorhandler);
}
}
/**
* Callback function for php error handling
*
* Warning : the only PHP error codes that are processed by this user
* handler are : E_WARNING, E_NOTICE, E_USER_ERROR
* For the other error codes the standart php handler will be used
*
* @since V2.0.0 - 17 apr 2006
* @see options, setErrorHandler()
*/
public function errorHandlerCallback()
{
$details = func_get_args();
$popNumber = 3;
// We already have line & file with setBackTrace function
for ($index = 0; $index < $popNumber; $index++) {
array_pop($details);
}
if ($details[0] != E_STRICT)
$this->addDebug($details, PHP_DebugLine::TYPE_PHPERROR);
}
/**
* Add a variable to the watchlist. Watched variables must be in a declare
* (ticks=n) block so that every n ticks the watched variables are checked
* for changes. If any changes were made, the new value of the variable is
* recorded
*
* @param string $variableName Variable to watch
* @since V2.0.0 - 17 apr 2006
* @see watchesCallback()
*/
public function watch($variableName)
{
if ($this->options['enable_watch'] == true) {
if (isset($GLOBALS[$variableName])) {
$this->watches[$variableName] = $GLOBALS[$variableName];
} else {
$this->watches[$variableName] = null;
}
} else {
throw new Exception('The Watch function is disabled please set the option \'enable_watch\' to \'true\' to be able to use this feature, it\'s stable with a Unix server');
}
}
/**
* Watch callback function, process watches and add changes to the debug
* information
*
* @since V2.0.0 - 17 apr 2006
* @see watch()
*/
public function watchesCallback()
{
// Check if there are variables to watch
if (count($this->watches)) {
foreach ($this->watches as $variableName => $variableValue) {
if ($GLOBALS[$variableName] !== $this->watches[$variableName]) {
$info = array(
$variableName,
$this->watches[$variableName],
$GLOBALS[$variableName]
);
$this->watches[$variableName] = $GLOBALS[$variableName];
$this->addDebug($info, PHP_DebugLine::TYPE_WATCH);
}
}
}
}
/**
* Get global process time
*
* @return float Execution process time of the script
*
* @see getElapsedTime()
* @since V2.0.0 - 21 Apr 2006
*/
public function getProcessTime()
{
return $this->getElapsedTime($this->startTime, $this->endTime);
}
/**
* Get database related process time
*
* @return float Execection process time of the script for all
* database specific tasks
*
* @see PHP_DebugLine::TYPE_QUERY, PHP_DebugLine::TYPE_QUERYREL
* @since V2.0.0 - 21 Apr 2006
*/
public function getQueryTime()
{
$queryTime = 0;
foreach($this->debugLineBuffer as $lkey => $lvalue) {
$properties = $lvalue->getProperties();
if ($properties['type'] == PHP_DebugLine::TYPE_QUERY
|| $properties['type'] == PHP_DebugLine::TYPE_QUERYREL) {
if (!empty($properties['endTime'])) {
$queryTime = $queryTime +
$this->getElapsedTime(
$properties['startTime'],
$properties['endTime']);
}
}
}
return $queryTime;
}
/**
* PHP_Debug default output function, first we finish the processes and
* then a render object is created and its render method is invoked
*
* The renderer used is set with the options, all the possible renderer
* are in the directory Debug/Renderer/*.php
* (not the files ending by '_Config.php')
*
* @since V2.0.0 - 13 apr 2006
* @see Debug_Renderer
*/
public function render()
{
// Finish process
$this->endTime = PHP_Debug::getMicroTimeNow();
// Render output if we are allowed to
if ($this->isAllowed()) {
// Create render object and invoke its render function
$renderer = PHP_Debug_Renderer::factory($this, $this->options);
// Get required files here to have event all Debug classes
$this->requiredFiles = get_required_files();
// Call rendering
return$renderer->render();
}
}
/**
* Alias for the render function
*
* @since V2.0.0 - 17 apr 2006
* @see render()
*/
public function display()
{
echo $this->render();
}
/**
* Return the output without displaying it
*
* @since V2.0.1 - 17 apr 2006
* @see render()
*/
public function getOutput()
{
return $this->render();
}
/**
* Restrict access to a list of IP
*
* @param array $ip Array with IP to allow access
* @since V2.0.0 - 11 Apr 2006
* @see $options, isAllowed()
*/
function restrictAccess($ip)
{
$this->options['allowed_ip'] = $ip;
}
/**
* Test if the client is allowed to access the debug information
* There are several possibilities :
* - 'restrict_access' flag is set to false
* - 'restrict_access' flag is set to true and client IP is the
* allowed ip in the options 'allowed_ip'
* - Access by url is allowed with flag 'allow_url_access' then
* the client must enter the good key and password in the url
*
* @since V2.0.0 - 20 apr 2006
* @see $options, restrictAcess()
*/
protected function isAllowed()
{
if ($this->options['restrict_access'] == true) {
// Check if client IP is among the allowed ones
if (in_array(
$_SERVER['REMOTE_ADDR'],
$this->options['allowed_ip']
)) {
return true;
}
// Check if instant access is allowed and test key and password
elseif ($this->options['allow_url_access'] == true) {
$key = $this->options['url_key'];
if (!empty($_GET[$key])) {
if ($_GET[$key] == $this->options['url_pass']) {
return true;
} else {
return false;
}
}
else {
return false;
}
} else {
return false;
}
} else {
// Access is not restricted
return true;
}
}
/**
* Return microtime from a timestamp
*
* @param $time Timestamp to retrieve micro time
* @return numeric Microtime of timestamp param
*
* @since V1.1.0 - 14 Nov 2003
* @see $DebugMode
*/
public static function getMicroTime($time)
{
list($usec, $sec) = explode(' ', $time);
return (float)$usec + (float)$sec;
}
/**
* Alias for getMicroTime(microtime()
*
* @see getMicroTime()
* @since V2.0.0 - 19 apr 2006
*/
public static function getMicroTimeNow()
{
return PHP_Debug::getMicroTime(microtime());
}
/**
* Get elapsed time between 2 timestamp
*
* @param float $timeStart Start time
* @param float $timeEnd End time
* @return float Numeric difference between the two times
* ref in format 00.0000 sec
*
* @see getMicroTime()
* @since V1.0.0 - 20 Oct 2003
*/
public static function getElapsedTime($timeStart, $timeEnd)
{
return round($timeEnd - $timeStart, 4);
}
/**
* Returns Uri prefix, including protocol, hostname and server port.
*
* @return string Uniform resource identifier prefix
*/
public static function getUriPrefix()
{
$pathArray = $_SERVER;
if (PHP_Debug::isSecure()) {
$standardPort = '443';
$proto = 'https';
} else {
$standardPort = '80';
$proto = 'http';
}
$port = $pathArray['SERVER_PORT'] == $standardPort || !$pathArray['SERVER_PORT'] ? '' : ':'.$pathArray['SERVER_PORT'];
return $proto.'://'. $pathArray['SERVER_NAME']. $port;
}
/**
* Test if url is secured
*
* @since V2.1.1 - 23 avr. 2007
*/
public static function isSecure()
{
return $_SERVER['SERVER_PORT'] != 80;
}
/**
* Returns current host name.
*
* @since V2.1.1 - 23 avr. 2007
*/
public static function getHost()
{
$pathArray = $_SERVER;
return isset($pathArray['HTTP_X_FORWARDED_HOST']) ? $pathArray['HTTP_X_FORWARDED_HOST'] : (isset($pathArray['HTTP_HOST']) ? $pathArray['HTTP_HOST'] : '');
}
/**
* Returns current script name.
*
* @return string
* @since V2.1.1 - 23 avr. 2007
*/
public static function getScriptName()
{
$pathArray = $_SERVER;
return isset($pathArray['SCRIPT_NAME']) ? $pathArray['SCRIPT_NAME'] : (isset($pathArray['ORIG_SCRIPT_NAME']) ? $pathArray['ORIG_SCRIPT_NAME'] : '');
}
/**
* Return the query string
*
* @author Vernet Loic
* @since 2.1.1 - 23 avr. 2007
*/
public static function getQueryString()
{
return $_SERVER['QUERY_STRING'] ? '?'. $_SERVER['QUERY_STRING'] : '';
}
/**
* Return the full url
*
* @author Vernet Loi
* @since 2.1.1 - 23 avr. 2007
*/
public static function getUrl()
{
return self::getUriPrefix(). self::getScriptName(). self::getQueryString();
}
/**
* Set the endtime for a DebugLine in order to monitor the performance
* of a part of script
*
* @see PHP_DebugLine::endTime
* @since V2.0.0 - 19 apr 2006
*/
public function stopTimer()
{
$this->debugLineBuffer[count($this->debugLineBuffer)-1]->setEndTime();
}
/**
* Display the content of any kind of variable
*
* - Mode PHP_DEBUG_DUMP_ARR_DISP display the array
* - Mode PHP_DEBUG_DUMP_ARR_STR return the infos as a string
*
* @param mixed $var Variable to dump
* @param string $varname Name of the variable
* @param integer $mode Mode of function
* @param boolean $stopExec Stop the process after display of debug
* @return mixed Nothing or string depending on the mode
*
* @since V2.0.0 - 25 Apr 2006
*/
public static function dumpVar(
$var,
$varName = self::DUMP_VARNAME,
$stopExec = false,
$mode = self::DUMP_DISP) {
$dumpMethod = self::$staticOptions['dump_method'];
ob_start();
$dumpMethod($var);
$dbgBuffer = htmlentities(ob_get_contents());
ob_end_clean();
switch ($mode) {
default:
case self::DUMP_DISP:
if (empty($varName)) {
if (is_array($var)) {
$varName = 'Array';
} elseif (is_object($var)) {
$varName = get_class($var);
} else {
$varName = 'Variable';
}
}
$dbgBuffer = '<pre><b>dump of \''. $varName. '\'</b> :'.
CR. $dbgBuffer. '</pre>';
echo $dbgBuffer;
break;
case PHP_Debug::DUMP_STR:
return($dbgBuffer);
}
// Check process stop
if ($stopExec) {
$backtrace = debug_backtrace();
$dieMsg = '<pre><b>Process stopped by PHP_Debug</b>'. CR;
$dieMsg .= $backtrace[0]['file'] ? '» file : <b>'.
$backtrace[0]['file'] .'</b>'. CR : '';
$dieMsg .= $backtrace[0]['line'] ? '» line : <b>'.
$backtrace[0]['line'] .'</b>'. CR : '';
$dieMsg .= $backtrace[1]['class'] ? '» class : <b>'.
$backtrace[1]['class'] .'</b>'. CR : '';
$dieMsg .= $backtrace[1]['function'] ? '» function : <b>'.
$backtrace[1]['function'] .'</b>'. CR : '';
$dieMsg .= '</pre>';
die($dieMsg);
}
}
/**
* Get one option
*
* @param string $optionsIdx Name of the option to get
* @since V2.0.0 - 13 apr 2006
*/
public function getOption($optionIdx)
{
return $this->options[$optionIdx];
}
/**
* Getter of requiredFiles property
*
* @return array Array with the included/required files
* @since V2.0.0 - 13 apr 2006
* @see requiredFiles
*/
public function getRequiredFiles()
{
return $this->requiredFiles;
}
/**
* Getter of debugString property
*
* @since V2.0.0 - 13 apr 2006
* @see debugLineBuffer
*/
public function getDebugBuffer()
{
return $this->debugLineBuffer;
}
/**
* Getter of queryCount property
*
* @since V2.0.0 - 21 Apr 2006
* @see queryCount
*/
public function getQueryCount()
{
return $this->queryCount;
}
/**
* Debug default output function, simply uses the static dump fonction
* of this class
*
* @since V2.0.0 - 11 apr 2006
* @see dump
*/
public function __toString()
{
return '<pre>'. PHP_Debug::dumpVar(
$this,
__CLASS__. ' class instance',
false,
PHP_Debug::DUMP_STR
). '</pre>';
}
}
PHP/DebugLine.php
<?php
/**
* A loader class for the renderers.
*
* @package PHP_Debug
* @category PHP
* @author Loic Vernet <qrf_coil at yahoo dot fr>
* @since V2.0.0 - 10 Apr 2006
*
* @package PHP_Debug
* @filesource
* @version CVS: $Id: DebugLine.php,v 1.1 2008/05/02 14:26:37 c0il Exp $
*/
class PHP_DebugLine
{
/**
* PHP_DEBUGLINE Types
*
* - TYPE_ANY : All available types (for search mode)
* - TYPE_STD : Standart debug
* - TYPE_QUERY : Query debug
* - TYPE_REL : Database related debug
* - TYPE_ENV : Environment debug ($GLOBALS...)
* - TYPE_APPERROR : Custom application error
* - TYPE_CREDITS : Credits information
* - TYPE_SEARCH : Search mode in debug
* - TYPE_DUMP : Dump any kind of variable
* - TYPE_PROCESSPERF : Performance analysys
* - TYPE_TEMPLATES : Included templates of the calling script
* - TYPE_PAGEACTION : Store main page action
* - TYPE_SQLPARSE : SQL Parse error
* - TYPE_WATCH : A variable to watch
* - TYPE_PHPERROR : A debug generated by the custom error handler
*
* @category DebugLine
*/
const TYPE_ANY = 0;
const TYPE_STD = 1;
const TYPE_QUERY = 2;
const TYPE_QUERYREL = 3;
const TYPE_ENV = 4;
const TYPE_APPERROR = 5;
const TYPE_CREDITS = 6;
const TYPE_SEARCH = 7;
const TYPE_DUMP = 8;
const TYPE_PROCESSPERF = 9;
const TYPE_TEMPLATES = 10;
const TYPE_PAGEACTION = 11;
const TYPE_SQLPARSE = 12;
const TYPE_WATCH = 13;
const TYPE_PHPERROR = 14;
const TYPE_DEFAULT = self::TYPE_STD;
/**
* PHP_DEBUGLINE info levels
*/
const INFO_LEVEL = 1;
const WARNING_LEVEL = 2;
const ERROR_LEVEL = 3;
/**
* Labels for debugline types
*/
public static $debugLineLabels = array(
self::TYPE_ANY => 'ALL',
self::TYPE_STD => 'Standart',
self::TYPE_QUERY => 'Query',
self::TYPE_QUERYREL => 'Database related',
self::TYPE_ENV => 'Environment',
self::TYPE_APPERROR => 'Application error',
self::TYPE_CREDITS => 'Credits',
self::TYPE_SEARCH => 'Search',
self::TYPE_DUMP => 'Variable dump',
self::TYPE_PROCESSPERF => 'Performance analysis',
self::TYPE_TEMPLATES => 'Included files',
self::TYPE_PAGEACTION => 'Page main action',
self::TYPE_SQLPARSE => 'SQL parse error',
self::TYPE_WATCH => 'Watch',
self::TYPE_PHPERROR => 'PHP error'
);
/**
* Properties that stores the non formatted debug information
*
* @since V2.0.0 - 11 apr 2006
* @var string
*/
protected $info;
/**
* Type of the debug information
*
* @since V2.0.0 - 11 apr 2006
* @see Debug_Line constants
* @var integer
*/
protected $type;
/**
* File of debug info
*
* @since V2.0.0 - 11 apr 2006
* @var integer
*/
protected $file;
/**
* Line of debug info
*
* @since V2.0.0 - 11 apr 2006
* @var integer
*/
protected $line;
/**
* Class from witch the debug was called
*
* @since V2.0.0 - 13 apr 2006
* @var integer
*/
protected $class;
/**
* Function from wich the debug was called
*
* @var integer
* @since V2.0.0 - 11 apr 2006
*/
protected $function;
/**
* Exection time for debug info
*
* @var float
* @see stopTimer()
* @since V2.0.0 - 16 apr 2006
*/
protected $startTime;
/**
* Exection end time for debug info
*
* @see PHP_Debug::stopTimer(), setEndTime()
* @since V2.0.0 - 16 apr 2006
* @var float
*/
protected $endTime;
/**
* PHP_DebugLine class constructor
*
* Here it is set :
* - the start time of the debug info
* - the traceback information
*
* @since V2.0.0 - 11 apr 2006
* @see PHP_Debug::add()
*/
public function __construct($info, $type = self::TYPE_DEFAULT)
{
$this->setStartTime();
$this->info = $info;
$this->type = $type;
$this->setTraceback();
}
/**
* Fills properties of debug line with backtrace informations
*
* @since V2.0.0 - 15 apr 2006
*/
protected function setTraceback()
{
$callStack = debug_backtrace();
$idx = 0;
// Get max id of 'add' debug functions
foreach($callStack as $lkey => $lvalue) {
if (in_array($callStack[$lkey]['function'],
PHP_Debug::$excludedBackTraceFunctions) == true
) {
$idx = $lkey;
}
}
$this->file = !empty($callStack[$idx] ['file'])
? $callStack[$idx]['file'] : '';
$this->line = !empty($callStack[$idx] ['line'])
? $callStack[$idx]['line'] : '';
$this->function = !empty($callStack[$idx+1]['function'])
? $callStack[$idx+1]['function'] : '';
$this->class = !empty($callStack[$idx+1]['class'])
? $callStack[$idx+1]['class'] : '';
}
/**
* Getter of all properties of Debug_Line object
*
* @return array Array containg all the properties of the debugline
* @since V2.0.0 - 21 apr 2006
*/
public function getProperties()
{
return array(
'class' => $this->class,
'file' => $this->file,
'function' => $this->function,
'line' => $this->line,
'info' => $this->info,
'type' => $this->type,
'startTime' => $this->startTime,
'endTime' => $this->endTime
);
}
/**
* setter of endTime
*
* @since V2.0.0 - 19 apr 2006
*/
public function setEndTime($endTime = '')
{
$this->endTime = $endTime ? $endTime : PHP_Debug::getMicroTimeNow();
}
/**
* setter of startTime
*
* @see pear bug http://pear.php.net/bugs/10919
*
* @since V2.1.2 - 04 may 2006
*/
public function setStartTime($startTime = '')
{
$this->startTime = $startTime ? $startTime : PHP_Debug::getMicroTimeNow();
}
/**
* Debug_Line default output function
*
* @since V2.0.0 - 11 apr 2006
* @see PHP_Debug::dumpVar()
*/
public function __toString()
{
return '<pre>'.
PHP_Debug::dumpVar(
$this,
__CLASS__,
false,
PHP_DEBUG_DUMP_ARR_STR
)
. '</pre>';
}
/**
* Function that give the debug type lable
*
* @author COil
* @since V2.0.0 - 2 apr 2007
*/
public static function getDebugLabel($type)
{
return self::$debugLineLabels[$type];
}
}
PHP/Debug/Renderer.php
<?php
require_once 'PHP/Debug/Renderer/Common.php';
/**
* A loader class for the renderers.
*
* @package PHP_Debug
* @category PHP
* @author Loic Vernet <qrf_coil at yahoo dot fr>
* @since V2.0.0 - 10 Apr 2006
*
* @package PHP_Debug
* @filesource
* @version CVS: $Id: Renderer.php,v 1.1 2008/05/02 14:26:37 c0il Exp $
*/
class PHP_Debug_Renderer
{
/**
* Attempt to return a concrete Debug_Renderer instance.
*
* @param string $mode Name of the renderer.
* @param array $options Parameters for the rendering.
* @access public
*/
public static function factory($debugObject, $options)
{
$className = 'PHP_Debug_Renderer_'. $options['render_type'].
'_'. $options['render_mode'];
$classPath = 'PHP/Debug/Renderer/'. $options['render_type'].
'/'. $options['render_mode']. '.php';
include_once $classPath;
if (class_exists($className)) {
$obj = new $className($debugObject, $options);
} else {
include_once 'PEAR.php';
PEAR::raiseError('PHP_Debug: renderer >' .
$options['DEBUG_render_mode'] . '< not found', true);
return NULL;
}
return $obj;
}
}
PHP/Debug/Renderer/Common.php
<?php
/**
* A base class for Debug renderers, must be inherited by all such.
*
* @package PHP_Debug
* @category PHP
* @author Loic Vernet <qrf_coil at yahoo dot fr>
* @since V2.0.0 - 10 Apr 2006
*
* @package PHP_Debug
* @filesource
* @version CVS: $Id: Common.php,v 1.1 2008/05/02 14:26:37 c0il Exp $
*/
class PHP_Debug_Renderer_Common
{
/**
*
* @var Debug object
* This is the debug object to render
*/
protected $DebugObject = null;
/**
* Run-time configuration options.
*
* @var array
* @access public
*/
protected $options = array();
/**
* Default configuration options.
*
* @See Debug/Renderer/*.php for the complete list of options
* @var array
* @access public
*/
protected $defaultOptions = array();
/**
* Set run-time configuration options for the renderer
*
* @param array $options Run-time configuration options.
* @access public
*/
public function setOptions($options = array())
{
$this->options = array_merge($this->defaultOptions, $options);
}
/**
* Default output function
*/
public function __toString()
{
return '<pre>'.
PHP_Debug::dumpVar(
$this,
__CLASS__,
PHP_DEBUG_DUMP_ARR_STR
) . '<pre>';
}
/**
* PHP_DebugOutput class destructor
*/
function __destruct()
{
}
}
PHP/Debug/Renderer/HTML/DivConfig.php
<?php
/**
* Configuration file for HTML_Div renderer
*
* @package PHP_Debug
* @category PHP
* @author Loïc Vernet <qrf_coil at yahoo dot fr>
* @since V2.1.0 - 29 march 2007
*
* @package PHP_Debug
* @filesource
*
* @version CVS: $Id: DivConfig.php,v 1.2 2008/08/31 19:24:17 c0il Exp $
*/
class PHP_Debug_Renderer_HTML_DivConfig
{
/**
* Config container for Debug_Renderer_HTML_Div
*
* @var array
* @since V2.0.0 - 11 apr 2006
*/
protected static $options = array();
/**
* Static Instance of class
*
* @var array
* @since V2.0.0 - 11 apr 2006
*/
protected static $instance = null;
/**
* Debug_Renderer_HTML_DIV_Config class constructor
*
* @since V2.0.0 - 11 apr 2006
*/
protected function __construct()
{
/**
* Enable or disable Credits in debug infos
*/
self::$options['HTML_DIV_disable_credits'] = false;
/**
* Enable or disable pattern removing in included files
*/
self::$options['HTML_DIV_remove_templates_pattern'] = false;
/**
* Pattern list to remove in the display of included files
* if HTML_DIV_remove_templates_pattern is set to true
*/
self::$options['HTML_DIV_templates_pattern'] = array();
/**
* View Source script path
*/
self::$options['HTML_DIV_view_source_script_path'] = '.';
/**
* View source script file name
*/
self::$options['HTML_DIV_view_source_script_name'] = 'PHP_Debug_ShowSource.php';
/**
* Tabsize for view source script
*/
self::$options['HTML_DIV_view_source_tabsize'] = 4;
/**
* Tabsize for view source script
*/
self::$options['HTML_DIV_view_source_numbers'] = 2; //HL_NUMBERS_TABLE
/**
* images
*/
self::$options['HTML_DIV_images_path'] = 'images';
self::$options['HTML_DIV_image_info'] = 'info.png';
self::$options['HTML_DIV_image_warning'] = 'warning.png';
self::$options['HTML_DIV_image_error'] = 'error.png';
/**
* css path
*/
self::$options['HTML_DIV_css_path'] = 'css';
/**
* js path
*/
self::$options['HTML_DIV_js_path'] = 'js';
/**
* Class name of the debug info levels
*/
self::$options['HTML_DIV_debug_level_classes'] = array(
PHP_DebugLine::INFO_LEVEL => 'sfWebDebugInfo',
PHP_DebugLine::WARNING_LEVEL => 'sfWebDebugWarning',
PHP_DebugLine::ERROR_LEVEL => 'sfWebDebugError',
);
/**
* After this goes all HTML related variables
*
* HTML code for header
*/
self::$options['HTML_DIV_header'] = '
<div id="sfWebDebug">
<div id="sfWebDebugBar" class="sfWebDebugInfo">
<div id="title">
<a href="#" onclick="sfWebDebugToggleMenu(); return false;"><b>» PHP_Debug</b></a>
</div>
<ul id="sfWebDebugDetails" class="menu">
<li>{$phpDebugVersion}</li>
<li><a href="#" onclick="sfWebDebugShowDetailsFor(\'sfWebDebugConfig\'); return false;"><img src="{$imagesPath}/config.png" alt="Config" /> vars & config</a></li>
<li><a href="#" onclick="sfWebDebugShowDetailsFor(\'sfWebDebugLog\'); return false;"><img src="{$imagesPath}/comment.png" alt="Comment" /> logs & msgs</a></li>
<li><a href="#" onclick="sfWebDebugShowDetailsFor(\'sfWebDebugDatabaseDetails\'); return false;"><img src="{$imagesPath}/database.png" alt="Database" /> {$nb_queries}</a></li>
<li><a href="#" onclick="sfWebDebugShowDetailsFor(\'sfWebDebugW3CDetails\'); return false;">W3C</a></li>
<li class="last"><a href="#" onclick="sfWebDebugShowDetailsFor(\'sfWebDebugTimeDetails\'); return false;"><img src="{$imagesPath}/time.png" alt="Time" /> {$exec_time} ms</a></li>
</ul>
<a href="#" onclick="document.getElementById(\'sfWebDebug\').style.display=\'none\'; return false;"><img src="{$imagesPath}/close.png" alt="Close" /></a>
</div> <!-- End sfWebDebugBar -->
';
/**
* HTML code for validation debug tab
*/
self::$options['HTML_DIV_sfWebDebugW3CDetails'] = '
<div id="sfWebDebugW3CDetails" class="top" style="display:none">
<h1>W3C validation</h1>
<p>Click on the WC3 logo to verify the validation or to check the errors</p>
<p>
<a href="http://validator.w3.org/check?uri=referer"><img
src="{$imagesPath}/w3c_home_nb.png"
alt="W3C Validator" /></a>
</p>
or copy paste the source here <a href="http://validator.w3.org/#validate_by_input">http://validator.w3.org/#validate_by_input</a>
</div> <!-- End sfWebDebugW3CDetails -->
';
/**
* HTML code for a row of a validation error
*/
self::$options['HTML_DIV_sfWebDebugW3CTableHeader'] = '
<h2>{$title}</h2>
<table class="sfWebDebugLogs" style="width:600px">
<tr>
<th>n°</th>
<th>Line</th>
<th>Col</th>
<th>Message</th>
</tr>
';
/**
* HTML code for a row of a validation error
*/
self::$options['HTML_DIV_sfWebDebugW3CErrorRow'] = '
<tr class="sfWebDebugLogLine {$type}">
<td class="sfWebDebugLogNumber">{$cpt}</td>
<td class="sfWebDebugLogLine">{$line}</td>
<td class="sfWebDebugLogCol">{$col}</td>
<td class="sfWebDebugLogMessage">
{$message}
</td>
</tr>
';
/**
* HTML code for debug time tab
*/
self::$options['HTML_DIV_sfWebDebugTimeDetails'] = '
<div id="sfWebDebugTimeDetails" class="top" style="display: none">
<h1>Timers</h1>
<table class="sfWebDebugLogs" style="width: 300px">
<tr>
<th>type</th>
<th>time (ms)</th>
<th>percent</th>
</tr>
<tr>
<td class="sfWebDebugLogTypePerf">{$txtExecutionTime}</td>
<td style="text-align: right">{$processTime}</td>
<td style="text-align: right">100%</td>
</tr>
<tr>
<td class="sfWebDebugLogTypePerf">{$txtPHP}</td>
<td style="text-align: right">{$phpTime}</td>
<td style="text-align: right">{$phpPercent}%</td>
</tr>
<tr>
<td class="sfWebDebugLogTypePerf">{$txtSQL}</td>
<td style="text-align: right">{$sqlTime}</td>
<td style="text-align: right">{$sqlPercent}% : {$queryCount} {$txtQuery}</td>
</tr>
{$buffer}
</table>
</div> <!-- End sfWebDebugTimeDetails -->
';
/**
* HTML code for database tab
*/
self::$options['HTML_DIV_sfWebDebugDatabaseDetails'] = '
<div id="sfWebDebugDatabaseDetails" class="top" style="display: none">
<h1>Database / SQL queries</h1>
<div id="sfWebDebugDatabaseLogs">
<ol>
{$buffer}
</ol>
</div>
</div> <!-- End sfWebDebugDatabaseDetails -->
';
/**
* HTML code for Log & msg tab
*/
self::$options['HTML_DIV_sfWebDebugLog'] = '
<div id="sfWebDebugLog" class="top" style="display: none"><h1>Log and debug messages</h1>
<ul id="sfWebDebugLogMenu">
<li><a href="#" onclick="sfWebDebugToggleAllLogLines(true, \'sfWebDebugLogLine\'); return false;">[all]</a></li>
<li><a href="#" onclick="sfWebDebugToggleAllLogLines(false, \'sfWebDebugLogLine\'); return false;">[none]</a></li>
<li><a href="#" onclick="sfWebDebugShowOnlyLogLines(\'info\'); return false;"><img src="{$imagesPath}/info.png" alt="Info" /></a></li>
<li><a href="#" onclick="sfWebDebugShowOnlyLogLines(\'warning\'); return false;"><img src="{$imagesPath}/warning.png" alt="Warning" /></a></li>
<li><a href="#" onclick="sfWebDebugShowOnlyLogLines(\'error\'); return false;"><img src="{$imagesPath}/error.png" alt="Error" /></a></li>
</ul>
<div id="sfWebDebugLogLines">
<table class="sfWebDebugLogs">
<tr>
<th>#</th>
<th>type</th>
<th>file</th>
<th>line</th>
<th>class</th>
<th>function</th>
<th>time</th>
<th>message</th>
</tr>
{$buffer}
</table>
</div>
</div> <!-- End sfWebDebugLog -->
';
/**
* HTML code for Vars & config tab
*/
self::$options['HTML_DIV_sfWebDebugConfig'] = '
<div id="sfWebDebugConfig" class="top" style="display: none">
<h1>Configuration and request variables</h1>
<h2>Request <a href="#" onclick="sfWebDebugToggle(\'sfWebDebugRequest\'); return false;"><img src="{$imagesPath}/toggle.gif" alt="Toggle" /></a></h2>
<div id="sfWebDebugRequest" style="display: none">
{$sfWebDebugRequest}
</div>
<h2>Response <a href="#" onclick="sfWebDebugToggle(\'sfWebDebugResponse\'); return false;"><img src="{$imagesPath}/toggle.gif" alt="Toggle" /></a></h2>
<div id="sfWebDebugResponse" style="display: none">
{$sfWebDebugResponse}
</div>
<h2>Settings <a href="#" onclick="sfWebDebugToggle(\'sfWebDebugSettings\'); return false;"><img src="{$imagesPath}/toggle.gif" alt="Toggle" /></a></h2>
<div id="sfWebDebugSettings" style="display: none">
{$sfWebDebugSettings}
</div>
<h2>Globals <a href="#" onclick="sfWebDebugToggle(\'sfWebDebugGlobals\'); return false;"><img src="{$imagesPath}/toggle.gif" alt="Toggle" /></a></h2>
<div id="sfWebDebugGlobals" style="display: none">
{$sfWebDebugGlobals}
</div>
<h2>Php <a href="#" onclick="sfWebDebugToggle(\'sfWebDebugPhp\'); return false;"><img src="{$imagesPath}/toggle.gif" alt="Toggle" /></a></h2>
<div id="sfWebDebugPhp" style="display: none">
{$sfWebDebugPhp}
</div>
<h2>Files <a href="#" onclick="sfWebDebugToggle(\'sfWebDebugFiles\'); return false;"><img src="{$imagesPath}/toggle.gif" alt="Toggle" /></a></h2>
<div id="sfWebDebugFiles" style="display: none">
{$sfWebDebugFiles}
</div>
</div> <!-- End sfWebDebugConfig -->
';
/**
* HTML code for credits
*/
self::$options['HTML_DIV_credits'] = '
PHP_Debug ['. PHP_Debug::PEAR_RELEASE .'] | By COil (2008) |
<a href="http://www.strangebuzz.com">http://www.strangebuzz.com</a> |
<a href="http://phpdebug.sourceforge.net/">PHP_Debug Project Home</a> |
Original idea from the <a href="http://www.symfony-project.org/">symfony framework</a>
';
/**
* HTML code for a basic header
*/
self::$options['HTML_DIV_simple_header'] = '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Pear::PHP_Debug</title>
';
/**
* HTML code for a basic footer
*/
self::$options['HTML_DIV_simple_footer'] = '
</body>
</html>
';
/**
* HTML code for footer
*/
self::$options['HTML_DIV_footer'] = '
</div> <!-- End div sfWebDebug -->
';
}
/**
* returns the static instance of the class
*
* @since V2.0.0 - 11 apr 2006
* @see PHP_Debug
*/
public static function singleton()
{
if (!isset(self::$instance)) {
$class = __CLASS__;
self::$instance = new $class;
}
return self::$instance;
}
/**
* returns the configuration
*
* @since V2.0.0 - 07 apr 2006
* @see PHP_Debug
*/
public static function getConfig()
{
return self::$options;
}
/**
* HTML_DIV_Config
*
* @since V2.0.0 - 26 Apr 2006
*/
public function __toString()
{
return '<pre>'. PHP_Debug::dumpVar(
$this->singleton()->getConfig(),
__CLASS__,
false,
PHP_DEBUG_DUMP_ARR_STR). '</pre>';
}
}
PHP/Debug/Renderer/HTML/Div.php
<?php
/**
* Class of the HTML_Div renderer
*
* Idea from the debug system of the symfony PHP framework
* @see http://www.symfony-project.org
* @author Fabien Potencier
* @author François Zaninotto
*
* @author Vernet Loïc
*
* @version CVS: $Id: Div.php,v 1.2 2008/08/31 19:24:17 c0il Exp $
*/
require_once 'PHP/Debug/Renderer/HTML/DivConfig.php';
/**
* A floating div renderer for PHP_Debug
*
* Returns a floating based representation of the debug infos in XHTML sctrict
* format
*
* @package PHP_Debug
* @category PHP
* @author Loïc Vernet <qrf_coil at yahoo dot fr>
* @since V2.1.0 - 30 march 2007
*
* @package PHP_Debug
* @filesource
*/
class PHP_Debug_Renderer_HTML_Div extends PHP_Debug_Renderer_Common
{
// debug types for Vars & Config
protected static $settingsType = array(
PHP_DebugLine::TYPE_ENV,
);
// debug types for Log & Message tab
protected static $msgTypes = array(
PHP_DebugLine::TYPE_STD,
PHP_DebugLine::TYPE_PAGEACTION,
PHP_DebugLine::TYPE_APPERROR,
PHP_DebugLine::TYPE_CREDITS,
PHP_DebugLine::TYPE_DUMP,
PHP_DebugLine::TYPE_WATCH,
PHP_DebugLine::TYPE_PHPERROR
);
// debug types for Database tab
protected static $databaseTypes = array(
PHP_DebugLine::TYPE_QUERY,
PHP_DebugLine::TYPE_QUERYREL,
PHP_DebugLine::TYPE_SQLPARSE,
);
/**
* Debug_Renderer_HTML_Div class constructor
*
* @since V2.1.0 - 3 apr 2007
*/
function __construct($DebugObject, $options)
{
$this->DebugObject = $DebugObject;
$this->defaultOptions = PHP_Debug_Renderer_HTML_DivConfig::singleton()->getConfig();
$this->setOptions($options);
if ($this->options['HTML_DIV_disable_credits'] == false) {
$this->DebugObject->addDebugFirst($this->options['HTML_DIV_credits'],
PHP_DebugLine::TYPE_CREDITS);
}
// Add execution time
$this->DebugObject->addProcessPerf();
}
/**
* This is the function to display the debug informations
*
* @since V2.0.0 - 07 Apr 2006
* @see PHP_Debug::Render()
*/
public function display()
{
$buffer = '';
// Header
$buffer .= $this->displayHeader();
// Infos
$debugInfos = $this->DebugObject->getDebugBuffer();
// Vars & config
$buffer .= $this->showVarsAndConfig($debugInfos);
// Logs & msg
$buffer .= $this->showLogsAndMsg($debugInfos);
// Database
$buffer .= $this->showDatabaseInfos($debugInfos);
// W3C Validation
$buffer .= $this->showW3cValidation($debugInfos);
// Process time
$buffer .= $this->showProcessTime($debugInfos);
// Footer
$buffer .= $this->displayFooter();
return $buffer;
}
/**
* Show W3C validator tab
*
* @author COil
* @since V2.1.1 - 23 apr 2007
*/
protected function showW3cValidation()
{
return str_replace(
array(
'{$imagesPath}',
),
array(
$this->options['HTML_DIV_images_path']
),
$this->options['HTML_DIV_sfWebDebugW3CDetails']
);
}
/**
* Add the debug informations of the W3C validation process
*
* @author Vernet Loïc
* @since 2.1.0 - 23 avr. 2007
*/
protected function addW3CErrorInfos($res, $key)
{
$title = ucwords($key);
$type = 'sfW3C'. $title;
$errorCpt = 1;
$results = str_replace(
'{$title}',
$title,
$this->options['HTML_DIV_sfWebDebugW3CTableHeader']
);
foreach ($res->$key as $error) {
$id = $errorCpt. ($error->messageid ? ' ('. $error->messageid. ')' : '');
$results .= str_replace(
array(
'{$type}',
'{$cpt}',
'{$line}',
'{$col}',
'{$message}',
'{$source}',
),
array(
$type,
$id,
$error->line,
$error->col,
$error->message,
' ',
),
$this->options['HTML_DIV_sfWebDebugW3CErrorRow']
);
$errorCpt++;
}
$results .= '</table>';
return $results;
}
/**
* Shows vars & config
*
* @param array debug row
*
* @author COil
* @since V2.1.0 - 30 march 2007
*/
protected function showDatabaseInfos($debugInfos)
{
$idx = 1;
$buffer = '';
foreach ($debugInfos as $debugInfo) {
$properties = $debugInfo->getProperties();
if (in_array($properties['type'], self::$databaseTypes)) {
$buffer.= '<li>['. $this->processExecTime($properties). '] '.
$this->processDebugInfo($properties) .'</li>'. CR;
}
}
return str_replace(
array('{$buffer}'),
array($buffer ? $buffer : '<li>No database debug available</li>'),
$this->options['HTML_DIV_sfWebDebugDatabaseDetails']
);
}
/**
* Shows vars & config
*
* @author COil
* @since V2.1.0 - 30 march 2007
*/
protected function showLogsAndMsg($debugInfos)
{
$idx = 1;
$buffer = '';
foreach($debugInfos as $debugInfo) {
$properties = $debugInfo->getProperties();
if (in_array($properties['type'], self::$msgTypes)) {
// Error level of debug information
$level = $this->getLogInfoLevel($properties);
$infoImg = $this->getImageInfo($level);
$buffer .= '<tr class=\'sfWebDebugLogLine '. $this->getDebugLevelClass($level). '\'>
<td class="sfWebDebugLogNumber"># '. $idx. '</td>
<td class="sfWebDebugLogType">
<img src="'. $this->options['HTML_DIV_images_path']. '/'. $infoImg .'" alt="" /> '. $this->processType($properties).
'</td>
<td class="sfWebDebugLogFile">'. $this->processFile($properties). '</td>
<td class="sfWebDebugLogLine">'. $this->processLine($properties). '</td>
<td class="sfWebDebugLogClass">'. $this->processClass($properties). '</td>
<td class="sfWebDebugLogFunction">'. $this->processFunction($properties). '</td>
<td class="sfWebDebugLogTime">'. $this->processExecTime($properties). '</td>
<td class="sfWebDebugLogMessage">'. $this->processDebugInfo($properties). '</td>
</tr>'. CR;
$idx++;
}
}
return str_replace(
array(
'{$buffer}',
'{$imagesPath}',
),
array(
$buffer,
$this->options['HTML_DIV_images_path']
),
$this->options['HTML_DIV_sfWebDebugLog']
);
}
/**
* Get the log level of the debug info
*
* @author COil
* @since V2.1.0 - 2 avr. 2007
*
* @param array debug row
*/
protected function getLogInfoLevel($properties)
{
$level = PHP_DebugLine::INFO_LEVEL;
switch ($properties['type']) {
case PHP_DebugLine::TYPE_PAGEACTION:
case PHP_DebugLine::TYPE_CREDITS:
case PHP_DebugLine::TYPE_DUMP:
case PHP_DebugLine::TYPE_WATCH:
break;
case PHP_DebugLine::TYPE_APPERROR:
$level = PHP_DebugLine::ERROR_LEVEL;
break;
case PHP_DebugLine::TYPE_PHPERROR:
$level = $this->getPhpErrorLevel($properties);
break;
}
return $level;
}
/**
* Return the global error level corresponding to the related php error
* level
*
* @param array debug row
*
* @author COil
* @since 2.1.0 - 3 apr 2007
*/
protected function getPhpErrorLevel($properties)
{
$infos = $properties['info'];
switch ($infos[0]) {
case E_ERROR:
case E_PARSE:
case E_CORE_ERROR:
case E_COMPILE_ERROR:
case E_USER_ERROR:
return PHP_DebugLine::ERROR_LEVEL;
break;
case E_WARNING:
case E_CORE_WARNING:
case E_NOTICE:
case E_COMPILE_WARNING:
case E_USER_WARNING:
case E_USER_NOTICE:
case E_ALL:
case E_STRICT:
case E_RECOVERABLE_ERROR:
return PHP_DebugLine::WARNING_LEVEL;
break;
default:
return PHP_DebugLine::ERROR_LEVEL;
break;
}
}
/**
* Get the image info for the current debug type
*
* @author COil
* @since V2.1.0 - 2 avp 2007
*/
protected function getDebugLevelClass($debug_level)
{
return $this->options['HTML_DIV_debug_level_classes'][$debug_level];
}
/**
* Get the image info for the current debug type
*
* @author COil
* @since V2.1.0 - 2 avp 2007
*/
protected function getImageInfo($debug_level)
{
$info = $this->options['HTML_DIV_image_info'];
$warning = $this->options['HTML_DIV_image_warning'];
$error = $this->options['HTML_DIV_image_error'];
switch ($debug_level) {
case PHP_DebugLine::INFO_LEVEL:
$level = $info;
break;
case PHP_DebugLine::WARNING_LEVEL:
$level = $warning;
break;
case PHP_DebugLine::ERROR_LEVEL:
$level = $error;
break;
}
return $level;
}
/**
* Shows vars & config
*
* @author COil
* @since V2.1.0 - 30 march 2007
*/
protected function showVarsAndConfig($debugInfos)
{
return str_replace(
array(
'{$sfWebDebugRequest}',
'{$sfWebDebugResponse}',
'{$sfWebDebugSettings}',
'{$sfWebDebugGlobals}',
'{$sfWebDebugPhp}',
'{$sfWebDebugFiles}',
'{$imagesPath}',
),
array(
$this->showSuperArray(PHP_Debug::GLOBAL_REQUEST),
$this->showSuperArray(PHP_Debug::GLOBAL_COOKIE),
$this->showArray($this->settingsAsArray($debugInfos), 'Settings'),
$this->showArray($this->globalsAsArray(), 'Globals'),
$this->showArray($this->phpInfoAsArray(), 'PHP Infos'),
$this->showTemplates(),
$this->options['HTML_DIV_images_path'],
),
$this->options['HTML_DIV_sfWebDebugConfig']
);
}
/**
* Return all settings of application
*
* @author COil
* @since V2.1.0 - 2 apr 2007
*/
public function settingsAsArray($debugInfos)
{
$settings = array();
foreach($debugInfos as $debugInfo) {
$infos = $debugInfo->getProperties();
if (in_array($infos['type'], self::$settingsType)) {
$settings[] = $infos['info'];
}
}
return $settings;
}
/**
* Returns PHP globals variables as a sorted array.
*
* @return array PHP globals
* @since V2.1.0 - 2 apr 2007
*/
public static function globalsAsArray()
{
$values = array();
foreach (array('cookie', 'server', 'get', 'post', 'files', 'env', 'session') as $name) {
if (!isset($GLOBALS['_'.strtoupper($name)])) {
continue;
}
$values[$name] = array();
foreach ($GLOBALS['_'. strtoupper($name)] as $key => $value) {
$values[$name][$key] = $value;
}
ksort($values[$name]);
}
ksort($values);
return $values;
}
/**
* Returns PHP information as an array.
*
* @return array An array of php information
* @since V2.1.0 - 2 apr 2007
*/
public static function phpInfoAsArray()
{
$values = array(
'php' => phpversion(),
'os' => php_uname(),
'extensions' => get_loaded_extensions(),
);
// assign extension version if available
if ($values['extensions']) {
foreach ($values['extensions'] as $lkey => $extension) {
$values['extensions'][$lkey] = phpversion($extension) ? $extension.
' ('. phpversion($extension). ')' : $extension;
}
}
return $values;
}
/**
* Add the process time information to the debug information
*
* @since V2.0.0 - 18 Apr 2006
*/
protected function showProcessTime($debugInfos)
{
// Lang
$txtExecutionTime = 'Global execution time ';
$txtPHP = 'PHP';
$txtSQL = 'SQL';
$txtSECOND = 's';
$txtOneQry = ' query';
$txtMultQry = ' queries';
$queryCount = $this->DebugObject->getQueryCount();
$txtQuery = $queryCount > 1 ? $txtMultQry : $txtOneQry;
$buffer = '';
// Performance Debug
$processTime = $this->DebugObject->getProcessTime();
$sqlTime = $this->DebugObject->getQueryTime();
$phpTime = $processTime - $sqlTime;
$sqlPercent = round(($sqlTime / $processTime) * 100, 2);
$phpPercent = round(($phpTime / $processTime) * 100, 2);
$processTime = $processTime*1000;
$sqlTime = $sqlTime*1000;
$phpTime = $phpTime*1000;
if ($debugInfos) {
$buffer .= '
<tr>
<th>message</th>
<th>time (ms)</th>
<th>percent</th>
</tr>'. CR;
foreach($debugInfos as $debugInfo) {
$properties = $debugInfo->getProperties();
if ($properties['startTime'] && $properties['endTime']) {
$localPercent = round((($properties['endTime'] -
$properties['startTime'])*1000 / $processTime) * 100, 2);
$buffer .= '
<tr>
<td class="sfWebDebugLogMessagePerf">'. $this->ProcessDebugInfo($properties). '</td>
<td style="text-align: right">'. $this->ProcessExecTime($properties). '</td>
<td style="text-align: right">'. $localPercent. '%</td>
</tr>'. CR;
}
}
}
return str_replace(
array(
'{$txtExecutionTime}',
'{$processTime}',
'{$txtPHP}',
'{$phpTime}',
'{$phpPercent}',
'{$txtSQL}',
'{$sqlTime}',
'{$sqlPercent}',
'{$queryCount}',
'{$txtQuery}',
'{$buffer}'
),
array(
$txtExecutionTime,
$processTime,
$txtPHP,
$phpTime,
$phpPercent,
$txtSQL,
$sqlTime,
$sqlPercent,
$queryCount,
$txtQuery,
$buffer
),
$this->options['HTML_DIV_sfWebDebugTimeDetails']
);
}
/**
* Default render function for HTML_Div renderer
*
* @since V2.0.0 - 11 Apr 2006
* @see Renderer
*/
public function render()
{
return $this->display();
}
/**
* Displays the header of the PHP_Debug object
*
* @since V2.0.0 - 08 Apr 2006
* @see PHP_Debug
*/
protected function displayHeader()
{
return str_replace(
array(
'{$nb_queries}',
'{$exec_time}',
'{$imagesPath}',
'{$phpDebugVersion}'
),
array(
$this->DebugObject->getQueryCount(),
$this->DebugObject->getProcessTime() * 1000,
$this->options['HTML_DIV_images_path'],
PHP_Debug::PEAR_RELEASE
),
$this->options['HTML_DIV_header']);
}
/**
* Diplays the footer of the PHP_Debug object
*
* @since V2.0.0 - 08 Apr 2006
* @see PHP_Debug
*/
protected function displayFooter()
{
return $this->options['HTML_DIV_footer'];
}
/**
* process display of the execution time of debug information
*
* @param array $properties Properties of the debug line
* @return string Formatted string containing the main debug info
* @since V2.0.0 - 28 Apr 2006
*/
protected function processExecTime($properties)
{
// Lang
$txtPHP = 'PHP';
$txtSQL = 'SQL';
$txtSECOND = 's';
if (!empty($properties['endTime'])) {
$time = round(PHP_Debug::getElapsedTime(
$properties['startTime'],
$properties['endTime']
) * 1000);
$buffer = $this->span($time > 1 ? $time. ' ms' : '< 1 ms', 'time');
} else {
$buffer = ' ';
}
return $buffer;
}
/**
* process display of the main information of debug
*
* @param array $properties Properties of the debug line
* @return string Formatted string containing the main debug info
* @since V2.0.0 - 28 Apr 2006
*/
protected function processDebugInfo($properties)
{
$buffer = '';
switch($properties['type']) {
// Case for each of the debug lines types
// 1 : Standard
case PHP_DebugLine::TYPE_STD:
$buffer .= $this->span($properties['info'], 'std');
break;
// 2 : Query
case PHP_DebugLine::TYPE_QUERY:
$buffer .= preg_replace('/\b(SELECT|FROM|AS|LIMIT|ASC|COUNT|DESC|WHERE|LEFT JOIN|INNER JOIN|RIGHT JOIN|ORDER BY|GROUP BY|IN|LIKE|DISTINCT|DELETE|INSERT|INTO|VALUES)\b/',
'<span class="sfWebDebugLogInfo">\\1</span>',
$properties['info']);
break;
// 3 : Query related
case PHP_DebugLine::TYPE_QUERYREL:
$buffer .= $this->span($properties['info'], 'query');
break;
// 4 : Environment
case PHP_DebugLine::TYPE_ENV:
$buffer .= $this->showSuperArray($properties['info']);
break;
// 6 : User app error
case PHP_DebugLine::TYPE_APPERROR:
$buffer .= $this->span('/!\\ User error : '.
$properties['info']. ' /!\\', 'app-error');
break;
// 7
case PHP_DebugLine::TYPE_CREDITS:
$buffer .= $this->span($properties['info'], 'credits');
break;
// 9
case PHP_DebugLine::TYPE_DUMP:
$buffer .= $this->showDump($properties);
break;
// 10
case PHP_DebugLine::TYPE_PROCESSPERF:
$buffer .= $this->showProcessTime();
break;
// 12 : Main Page Action
case PHP_DebugLine::TYPE_PAGEACTION;
$buffer .= $this->span('[Action : '.
$properties['info']. ']', 'pageaction');
break;
// 14 : SQL parse
case PHP_DebugLine::TYPE_SQLPARSE:
$buffer .= $properties['info'];
break;
// 15 : Watches
case PHP_DebugLine::TYPE_WATCH:
$infos = $properties['info'];
$buffer .= 'Variable '. $this->span($infos[0], 'watch').
' changed from value '.
$this->span($infos[1], 'watch-val'). ' ('. gettype($infos[1]).
') to value '. $this->span($infos[2], 'watch-val').
' ('. gettype($infos[2]). ')';
break;
// 16 : PHP errors
case PHP_DebugLine::TYPE_PHPERROR:
$buffer .= $this->showError($properties['info']);
break;
default:
$buffer .= '<b>Default('. $properties['type'].
')</b>: TO IMPLEMENT OR TO CORRECT : >'.
$properties['info']. '<';
break;
}
return $buffer;
}
/**
* Return a string with applying a span style on it
*
* @param string $info String to apply the style
* @param string $class CSS style to apply to the string
* @return string Formatted string with style applied
* @since V2.0.0 - 05 May 2006
*/
protected function span($info, $class)
{
return '<span class="'. $class .'">'. $info .'</span>';
}
/**
* process display of the type of the debug information
*
* @param array $properties Properties of the debug line
* @return string Formatted string containing the debug type
* @since V2.0.0 - 26 Apr 2006
*/
protected function processType($properties)
{
$buffer = PHP_DebugLine::$debugLineLabels[$properties['type']];
return $buffer;
}
/**
* process display of Class
*
* @param array $properties Properties of the debug line
* @return string Formatted string containing the class
* @since V2.0.0 - 26 Apr 2006
*/
protected function processClass($properties)
{
$buffer = '';
switch ($properties['type'])
{
case PHP_DebugLine::TYPE_STD:
case PHP_DebugLine::TYPE_QUERY:
case PHP_DebugLine::TYPE_QUERYREL:
case PHP_DebugLine::TYPE_APPERROR:
case PHP_DebugLine::TYPE_PAGEACTION:
case PHP_DebugLine::TYPE_PHPERROR:
case PHP_DebugLine::TYPE_SQLPARSE:
case PHP_DebugLine::TYPE_WATCH:
case PHP_DebugLine::TYPE_DUMP:
if (!empty($properties['class'])) {
$buffer .= $properties['class'];
} else {
$buffer .= ' ';
}
break;
case PHP_DebugLine::TYPE_CREDITS:
case PHP_DebugLine::TYPE_SEARCH:
case PHP_DebugLine::TYPE_PROCESSPERF:
case PHP_DebugLine::TYPE_TEMPLATES:
case PHP_DebugLine::TYPE_ENV:
$buffer .= ' ';
break;
default:
break;
}
return $buffer;
}
/**
* process display of function
*
* @param array $properties Properties of the debug line
* @return string Formatted string containing the function
* @since V2.0.0 - 26 Apr 2006
*/
protected function processFunction($properties)
{
$buffer = '';
switch ($properties['type'])
{
case PHP_DebugLine::TYPE_STD:
case PHP_DebugLine::TYPE_QUERY:
case PHP_DebugLine::TYPE_QUERYREL:
case PHP_DebugLine::TYPE_APPERROR:
case PHP_DebugLine::TYPE_PAGEACTION:
case PHP_DebugLine::TYPE_PHPERROR:
case PHP_DebugLine::TYPE_SQLPARSE:
case PHP_DebugLine::TYPE_WATCH:
case PHP_DebugLine::TYPE_DUMP:
if (!empty($properties['function'])) {
if ($properties['function'] != 'unknown') {
$buffer .= $properties['function']. '()';
} else {
$buffer .= ' ';
}
} else {
$buffer .= ' ';
}
break;
case PHP_DebugLine::TYPE_CREDITS:
case PHP_DebugLine::TYPE_SEARCH:
case PHP_DebugLine::TYPE_PROCESSPERF:
case PHP_DebugLine::TYPE_TEMPLATES:
case PHP_DebugLine::TYPE_ENV:
$buffer .= ' ';
break;
default:
break;
}
return $buffer;
}
/**
* process display of line number
*
* @param array $properties Properties of the debug line
* @return string Formatted string containing the line number
* @since V2.0.0 - 26 Apr 2006
*/
protected function processLine($properties)
{
$buffer = '';
switch ($properties['type'])
{
case PHP_DebugLine::TYPE_STD:
case PHP_DebugLine::TYPE_QUERY:
case PHP_DebugLine::TYPE_QUERYREL:
case PHP_DebugLine::TYPE_APPERROR:
case PHP_DebugLine::TYPE_PAGEACTION:
case PHP_DebugLine::TYPE_PHPERROR:
case PHP_DebugLine::TYPE_SQLPARSE:
case PHP_DebugLine::TYPE_WATCH:
case PHP_DebugLine::TYPE_DUMP:
if (!empty($properties['line'])) {
$buffer.= '<span class="line">'.
$properties['line']. '</span>';
} else {
$buffer.= ' ';
}
break;
case PHP_DebugLine::TYPE_CREDITS:
case PHP_DebugLine::TYPE_SEARCH:
case PHP_DebugLine::TYPE_PROCESSPERF:
case PHP_DebugLine::TYPE_TEMPLATES:
case PHP_DebugLine::TYPE_ENV:
$buffer.= ' ';
break;
default:
break;
}
return $buffer;
}
/**
* process display of file name
*
* @param array $properties Properties of the debug line
* @return string Formatted string containing the file
* @since V2.0.0 - 26 Apr 2006
*/
protected function processFile($properties)
{
$buffer = '';
switch ($properties['type'])
{
case PHP_DebugLine::TYPE_STD:
case PHP_DebugLine::TYPE_QUERY:
case PHP_DebugLine::TYPE_QUERYREL:
case PHP_DebugLine::TYPE_APPERROR:
case PHP_DebugLine::TYPE_PAGEACTION:
case PHP_DebugLine::TYPE_PHPERROR:
case PHP_DebugLine::TYPE_SQLPARSE:
case PHP_DebugLine::TYPE_WATCH:
case PHP_DebugLine::TYPE_DUMP:
if (!empty($properties['file'])) {
if (!empty($this->options['HTML_DIV_view_source_script_path']) &&
!empty($this->options['HTML_DIV_view_source_script_name'])) {
$buffer .= '<a href="'.
$this->options['HTML_DIV_view_source_script_path'].
'/'.
$this->options['HTML_DIV_view_source_script_name'].
'?file='. urlencode($properties['file']);
$buffer .= '">'. basename($properties['file']). '</a>';
} else {
$buffer .= basename($properties['file']);
}
} else {
$buffer .= ' ';
}
break;
case PHP_DebugLine::TYPE_CREDITS:
case PHP_DebugLine::TYPE_SEARCH:
case PHP_DebugLine::TYPE_PROCESSPERF:
case PHP_DebugLine::TYPE_TEMPLATES:
case PHP_DebugLine::TYPE_ENV:
$buffer .= ' ';
break;
default:
break;
}
return $buffer;
}
/**
* Dump of a variable
*
* @since V2.0.0 - 26 Apr 2006
*/
protected function showDump($properties)
{
$buffer = '';
// Check display with a <pre> design
if (is_array($properties['info'][1])) {
$preDisplay = true;
} elseif (is_object($properties['info'][1])) {
$preDisplay = true;
} else {
$preDisplay = false;
}
// Check var name
if (empty($properties['info'][0])) {
if (is_array($properties['info'][1])) {
$varName = 'Array';
} elseif (is_object($properties['info'][1])) {
$varName = get_class($properties['info'][1]);
} else {
$varName = 'Variable';
}
} else {
$varName = $properties['info'][0];
}
// Output
if ($properties['type'] != PHP_DebugLine::TYPE_ENV) {
$title = 'dump of \'';
}
$title .= $varName. '\' ('. gettype($properties['info'][1]) .') : ';
$buffer .= $this->span($title , 'dump-title');
if ($preDisplay == true){
$buffer .= '<pre>';
$buffer .= PHP_Debug::dumpVar(
$properties['info'][1],
'',
false,
PHP_Debug::DUMP_STR);
} else {
$buffer .= $this->span(
PHP_Debug::dumpVar(
$properties['info'][1],
'',
false,
PHP_Debug::DUMP_STR
), 'dump-val');
}
if ($preDisplay == true) {
$buffer .= '</pre>';
}
return $buffer;
}
/**
* Get the templates info
*
* @since V2.0.0 - 26 Apr 2006
*/
protected function showTemplates()
{
$txtMainFile = 'MAIN File';
$idx = 1;
$buffer = '<br />';
foreach($this->DebugObject->getRequiredFiles() as $lvalue) {
$isToDisplay = true;
if ($this->options['HTML_DIV_view_source_excluded_template']) {
foreach ($this->options['HTML_DIV_view_source_excluded_template'] as $template) {
if (stristr($lvalue, $template)) {
$isToDisplay = false;
}
}
}
if ($isToDisplay == true) {
$buffer .= '<div class="source">';
$buffer .= $this->span($this->truncate($lvalue), 'files');
$buffer .= ' <a href="'.
$this->options['HTML_DIV_view_source_script_path'].
'/'. $this->options['HTML_DIV_view_source_script_name'].
'?file='. urlencode($lvalue). '">View source</a> ';
// main file
if ($idx == 1) {
$buffer .= $this->span('« '. $txtMainFile, 'main-file');
}
$idx++;
$buffer .= '</div><br />'. CR;
}
}
$buffer .= '<br />'. CR;
return $buffer;
}
/**
* Truncate/replace a pattern from the file path
*
* @param string full file path
*
* @author COil
* @since V2.1.0 - 3 apr 2007
*
* @see
* - HTML_DIV_remove_templates_pattern
* - HTML_DIV_templates_pattern
*/
protected function truncate($file)
{
if ($this->options['HTML_DIV_remove_templates_pattern'] &&
$this->options['HTML_DIV_templates_pattern']) {
return strtr($file, $this->options['HTML_DIV_templates_pattern']);
}
return $file;
}
/**
* Process an error info
*
* @param array $info Array containing information about the error
*
* @since V2.0.0 - 25 Apr 2006
* @see PHP_DebugLine::TYPE_PHPERROR
*/
protected function showError($infos)
{
$buffer = '';
$infos[1] = str_replace("'", '"', $infos[1]);
$infos[1] = str_replace(
'href="function.',
' href="http://www.php.net/'.
$this->options['lang']. '/', $infos[1]);
switch ($infos[0])
{
case E_WARNING:
$errorlevel = 'PHP WARNING : ';
$buffer .= '<span class="pd-php-warning"> /!\\ '.
$errorlevel. $infos[1] . ' /!\\ </span>';
break;
case E_NOTICE:
$errorlevel = 'PHP notice : ';
$buffer .= '<span class="pd-php-notice">'.
$errorlevel. $infos[1] . '</span>';
break;
case E_USER_ERROR:
$errorlevel = 'PHP User error : ';
$buffer .= '<span class="pd-php-user-error"> /!\\ '.
$errorlevel. $infos[1] . ' /!\\ </span>';
break;
case E_STRICT:
$errorlevel = 'PHP STRICT error : ';
$buffer .= '<span class="pd-php-user-error"> /!\\ '.
$errorlevel. $infos[1] . ' /!\\ </span>';
break;
default:
$errorlevel = 'PHP errorlevel = '. $infos[0]. ' : ';
$buffer .= $errorlevel.
' is not implemented in PHP_Debug ('. __FILE__. ','. __LINE__. ')';
break;
}
return $buffer;
}
/**
* Show a super array
*
* @param string $SuperArrayType Type of super en array to add
* @since V2.0.0 - 07 Apr 2006
*/
protected function showSuperArray($SuperArrayType)
{
// Lang
$txtVariable = 'Var';
$txtNoVariable = 'NO VARIABLE';
$NoVariable = ' -- '. $txtNoVariable. ' -- ';
$SuperArray = null;
$buffer = '';
$ArrayTitle = PHP_Debug::$globalEnvConstantsCorresp[$SuperArrayType];
$SuperArray = $GLOBALS[$ArrayTitle];
$Title = $ArrayTitle. ' '. $txtVariable;
$SectionBasetitle = '<b>'. $Title. '('. count($SuperArray). ') :';
if (count($SuperArray)) {
$buffer .= $SectionBasetitle. '</b>';
$buffer .= '<pre>'.
PHP_Debug::dumpVar(
$SuperArray,
$ArrayTitle,
false,
PHP_Debug::DUMP_STR
). '</pre>';
} else {
$buffer .= $SectionBasetitle. $NoVariable. '</b>';
}
return $buffer;
}
/**
* Show a super array
*
* @param string $SuperArrayType Type of super en array to add
* @since V2.0.0 - 07 Apr 2006
*/
protected function showArray($array, $name)
{
// Lang
$txtNoVariable = 'NO VARIABLE';
$NoVariable = ' -- '. $txtNoVariable. ' -- ';
$buffer = '';
$SectionBasetitle = '<b>'. $name. '('. count($array). ') :';
if (count($array)) {
$buffer .= $SectionBasetitle. '</b>';
$buffer .= '<pre>'. PHP_Debug::dumpVar(
$array,
$name,
false,
PHP_Debug::DUMP_STR). '</pre>';
} else {
$buffer .= $SectionBasetitle. $NoVariable. '</b>';
}
return $buffer;
}
}
PHP/Debug/Renderer/HTML/TableConfig.php
<?php
/**
* Configuration file for HTML_Table renderer
*
* @package PHP_Debug
* @category PHP
* @author Loic Vernet <qrf_coil at yahoo dot fr>
* @since V2.0.0 - 10 Apr 2006
*
* @package PHP_Debug
* @filesource
*
* @version CVS: $Id: TableConfig.php,v 1.1 2008/05/02 14:26:37 c0il Exp $
*/
class PHP_Debug_Renderer_HTML_TableConfig
{
/**
* Config container for Debug_Renderer_HTML_Table
*
* @var array
* @since V2.0.0 - 11 apr 2006
*/
protected static $options = array();
/**
* Static Instance of class
*
* @var array
* @since V2.0.0 - 11 apr 2006
*/
protected static $instance = null;
/**
* Debug_Renderer_HTML_Table_Config class constructor
*
* @since V2.0.0 - 11 apr 2006
*/
protected function __construct()
{
/**
* Enable or disable Credits in debug infos
*/
self::$options['HTML_TABLE_disable_credits'] = false;
/**
* Enable or disable included and required files
*/
self::$options['HTML_TABLE_show_templates'] = true;
/**
* Enable or disable pattern removing in included files
*/
self::$options['HTML_TABLE_remove_templates_pattern'] = false;
/**
* Pattern list to remove in the display of included files
* if HTML_TABLE_remove_templates_pattern is set to true
*/
self::$options['HTML_TABLE_templates_pattern'] = array();
/**
* Enable or disable visualisation of $globals var in debug
*/
self::$options['HTML_TABLE_show_globals'] = false;
/**
* Enable or disable search in debug
*/
self::$options['HTML_TABLE_enable_search'] = true;
/**
* Enable or disable view of super arrays
*/
self::$options['HTML_TABLE_show_super_array'] = true;
/**
* Enable or disable the use of $_REQUEST array instead of
* $_POST + _$GET + $_COOKIE + $_FILES
*/
self::$options['HTML_TABLE_use_request_arr'] = false;
/**
* View Source script path
*/
self::$options['HTML_TABLE_view_source_script_path'] = '.';
/**
* View source script file name
*/
self::$options['HTML_TABLE_view_source_script_name'] = 'PHP_Debug_ShowSource.php';
/**
* css path
*/
self::$options['HTML_TABLE_css_path'] = 'css';
/**
* Tabsize for view source script
*/
self::$options['HTML_TABLE_view_source_tabsize'] = 4;
/**
* Tabsize for view source script
*/
self::$options['HTML_TABLE_view_source_numbers'] = 2; //HL_NUMBERS_TABLE
/**
* Define wether the display must be forced for the debug type when
* in search mode
*/
self::$options['HTML_TABLE_search_forced_type'] = array(
PHP_DebugLine::TYPE_STD => false,
PHP_DebugLine::TYPE_QUERY => false,
PHP_DebugLine::TYPE_QUERYREL => false,
PHP_DebugLine::TYPE_ENV => false,
PHP_DebugLine::TYPE_APPERROR => false,
PHP_DebugLine::TYPE_CREDITS => false,
PHP_DebugLine::TYPE_SEARCH => true,
PHP_DebugLine::TYPE_DUMP => false,
PHP_DebugLine::TYPE_PROCESSPERF => false,
PHP_DebugLine::TYPE_TEMPLATES => false,
PHP_DebugLine::TYPE_PAGEACTION => false,
PHP_DebugLine::TYPE_SQLPARSE => false,
PHP_DebugLine::TYPE_WATCH => false,
PHP_DebugLine::TYPE_PHPERROR => false
);
/**
* After this goes all HTML related variables
*
*
* HTML code for header
*/
self::$options['HTML_TABLE_header'] = '
<div id="pd-div">
<br />
<a name="pd-anchor" id="pd-anchor" />
<table class="pd-table" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td class="pd-table-header" align="center">File</td>
<td class="pd-table-header" align="center">Line</td>
<td class="pd-table-header" align="center">Inside/From function</td>
<td class="pd-table-header" align="center">Inside/From Class</td>
<td class="pd-table-header" align="center">Type</td>
<td class="pd-table-header" align="center">Debug information</td>
<td class="pd-table-header" align="center">Execution time (sec)</td>
</tr>
';
/**
* HTML code for footer
*/
self::$options['HTML_TABLE_credits'] = '
PHP_Debug ['. PHP_Debug::PEAR_RELEASE .'] | By COil (2007) |
<a href="http://www.coilblog.com">http://www.coilblog.com</a> |
<a href="http://phpdebug.sourceforge.net/">PHP_Debug Project Home</a>
';
/**
* HTML code for a basic header
*/
self::$options['HTML_TABLE_simple_header'] = '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Pear::PHP_Debug</title>
';
/**
* HTML code for a basic footer
*/
self::$options['HTML_TABLE_simple_footer'] = '
</body>
</html>
';
/**
* HTML pre-row code for debug column file
*/
self::$options['HTML_TABLE_prerow'] = '
<tr>';
/**
* HTML pre-row code for debug column file
*/
self::$options['HTML_TABLE_interrow_file'] = '
<td class="pd-td" align="center">';
/**
* HTML post-row code for debug column line (centered)
*/
self::$options['HTML_TABLE_interrow_line'] = '
</td>
<td class="pd-td" align="center">';
self::$options['HTML_TABLE_interrow_function'] = self::$options['HTML_TABLE_interrow_line'];
self::$options['HTML_TABLE_interrow_class'] = self::$options['HTML_TABLE_interrow_line'];
self::$options['HTML_TABLE_interrow_type'] = self::$options['HTML_TABLE_interrow_line'];
self::$options['HTML_TABLE_interrow_time'] = self::$options['HTML_TABLE_interrow_line'];
/**
* HTML pre-row code for debug column info
*/
self::$options['HTML_TABLE_interrow_info'] = '
</td>
<td class="pd-td" align="left">';
/**
* HTML post-row code for debugline
*/
self::$options['HTML_TABLE_postrow'] = '
</td>
</tr>
';
/**
* HTML code for footer
*/
self::$options['HTML_TABLE_footer'] = '
</table>
</div>
';
}
/**
* returns the static instance of the class
*
* @since V2.0.0 - 11 apr 2006
* @see PHP_Debug
*/
public static function singleton()
{
if (!isset(self::$instance)) {
$class = __CLASS__;
self::$instance = new $class;
}
return self::$instance;
}
/**
* returns the configuration
*
* @since V2.0.0 - 07 apr 2006
* @see PHP_Debug
*/
public static function getConfig()
{
return self::$options;
}
/**
* HTML_Table_Config
*
* @since V2.0.0 - 26 Apr 2006
*/
public function __toString()
{
return '<pre>'. PHP_Debug::dumpVar(
$this->singleton()->getConfig(),
__CLASS__,
false,
PHP_DEBUG_DUMP_ARR_STR). '</pre>';
}
}
PHP/Debug/Renderer/HTML/Table.php
<?php
/**
* Class of the HTML_Table renderer
*/
require_once 'PHP/Debug/Renderer/HTML/TableConfig.php';
/**
* A concrete renderer for Debug
*
* Returns a table-based representation of the debug infos in HTML 4
*
* @package PHP_Debug
* @category PHP
* @author Loic Vernet <qrf_coil at yahoo dot fr>
* @since V2.0.0 - 10 Apr 2006
*
* @package PHP_Debug
* @filesource
*
* @version CVS: $Id: Table.php,v 1.1 2008/05/02 14:26:37 c0il Exp $
*/
class PHP_Debug_Renderer_HTML_Table extends PHP_Debug_Renderer_Common
{
/**
* Debug_Renderer_HTML_Table class constructor
*
* @since V2.0.0 - 13 apr 2006
*/
function __construct($DebugObject, $options)
{
$this->DebugObject = $DebugObject;
$this->defaultOptions = PHP_Debug_Renderer_HTML_TableConfig::singleton()->getConfig();
$this->setOptions($options);
// Now add in first the predefined debugline depending on the configuration
if ($this->options['HTML_TABLE_enable_search'] == true)
$this->DebugObject->addDebugFirst('', PHP_DebugLine::TYPE_SEARCH);
if ($this->options['HTML_TABLE_disable_credits'] == false)
$this->DebugObject->addDebugFirst(
$this->options['HTML_TABLE_credits'],
PHP_DebugLine::TYPE_CREDITS);
// Now add in last positions the others predefined debuglines
// Add execution time
$this->DebugObject->addDebug('', PHP_DebugLine::TYPE_PROCESSPERF);
// Add templates
if ($this->options['HTML_TABLE_show_templates'] == true)
$this->DebugObject->addDebug(STR_N, PHP_DebugLine::TYPE_TEMPLATES);
// Add env variables
$this->addSuperArray();
}
/**
* This is the function to display the debug information
*
* @since V2.0.0 - 07 Apr 2006
* @see PHP_Debug::Render()
*/
public function display()
{
$buffer = '';
// Header
$buffer .= $this->displayHeader();
// Body
foreach ($this->DebugObject->getDebugBuffer() as $lvalue) {
// Check if the debug must be displayed
if ($this->checkType($lvalue) == true) {
$tmpBuff = $this->displayDebugLine($lvalue);
// Check if we have a search criteria
if ($this->checkSearch($tmpBuff)) {
// Pre-row
$buffer .= $this->options['HTML_TABLE_prerow'];
// Row body
$buffer .= $this->highlight($tmpBuff);
// Post-row
$buffer .= $this->options['HTML_TABLE_postrow'];
}
}
}
// Footer
$buffer .= $this->displayFooter();
// Output Buffer
echo $buffer;
}
/**
* This function highligth the searched keyword
*
* @param string $debugLineStr The formatted debug line object to check
* @return string Formatted string with keyword highligthed
*
* @since V2.0.0 - 2 May 2006
*/
protected function highlight($debugLineStr)
{
// Check if search is activated
if (!empty($_GET['PHPDEBUG_SEARCH']) &&
trim($_GET['PHPDEBUG_SEARCH']) != '') {
if (!empty($_GET['PHPDEBUG_SEARCH_CS'])) {
$replaceFunction = 'str_replace';
} else {
$replaceFunction = 'str_ireplace';
}
return $replaceFunction($_GET['PHPDEBUG_SEARCH'],
'<span class="pd-search-hl">'. $_GET['PHPDEBUG_SEARCH'].
'</span>' , $debugLineStr);
} else {
return $debugLineStr;
}
}
/**
* This function check if the user has chosen a search criteria and
* make the search on the formatted debug info
*
* @param string $debugLineStr The formatted debug line object to check
* @return boolean Search criteria has been found of search is disabled
*
* @since V2.0.0 - 2 May 2006
*/
protected function checkSearch($debugLineStr)
{
// Check if search is activated
if (!empty($_GET['PHPDEBUG_SEARCH']) &&
trim($_GET['PHPDEBUG_SEARCH']) != '') {
if (!empty($_GET['PHPDEBUG_SEARCH_CS'])) {
$searchFunction = 'strstr';
} else {
$searchFunction = 'stristr';
}
return $searchFunction($debugLineStr, trim($_GET['PHPDEBUG_SEARCH']));
} else {
return true;
}
}
/**
* This function check if the user has chosen a filter in the debug type
* combobox and it returns of the debug line is allowed to be output or no
*
* @param DebugLine $debugLine The debug line object to check
* @return boolean true type is allowed to be
*
* @since V2.0.0 - 26 Apr 2006
*/
protected function checkType($debugLine)
{
$properties = $debugLine->getProperties();
// Check if we must only show debug information of a kind
if ($this->options['HTML_TABLE_search_forced_type'][$properties['type']] == false) {
if (!empty($_GET['PHPDEBUG_SEARCH_TYPE'])) {
if ($properties['type'] == $_GET['PHPDEBUG_SEARCH_TYPE']) {
return true;
} else {
return false;
}
} else {
return true;
}
} else {
return true;
}
}
/**
* Default render function for HTML_Table renderer
*
* @since V2.0.0 - 11 Apr 2006
* @see Renderer
*/
public function render()
{
$this->display();
}
/**
* Displays the header of the PHP_Debug object
*
* @since V2.0.0 - 08 Apr 2006
* @see PHP_Debug
*/
protected function displayHeader()
{
return $this->options['HTML_TABLE_header'];
}
/**
* Diplays the footer of the PHP_Debug object
*
* @since V2.0.0 - 08 Apr 2006
* @see PHP_Debug
*/
protected function displayFooter()
{
return $this->options['HTML_TABLE_footer'];
}
/**
* This is the function that displays a debug line, each step correspond
* to a new cell, actully there are 6 types :
* - File
* - Line
* - Function
* - Class
* - Debug main information
* - Execution time
*
* @param DebugLine DebugLine, the debug line to process
*
* @since V2.0.0 - 07 Apr 2006
*/
protected function displayDebugLine($DebugLine)
{
// DebugLine properties
$properties = $DebugLine->getProperties();
// 1 - File
$buffer = $this->processFile($properties);
// 2 - Line
$buffer .= $this->processLine($properties);
// 3 - Function
$buffer .= $this->processFunction($properties);
// 4 - Class
$buffer .= $this->processClass($properties);
// 5 - Type
$buffer .= $this->processType($properties);
// 6 - Debug info
$buffer .= $this->processDebugInfo($properties);
// 7 - Execution time
$buffer .= $this->processExecTime($properties);
// Output display buffer
return $buffer;
}
/**
* process display of the execution time of debug information
*
* @param array $properties Properties of the debug line
* @return string Formatted string containing the main debug info
* @since V2.0.0 - 28 Apr 2006
*/
protected function processExecTime($properties)
{
// Lang
$txtPHP = 'PHP';
$txtSQL = 'SQL';
$txtSECOND = 's';
$buffer = $this->options['HTML_TABLE_interrow_time'];
if (!empty($properties['endTime'])) {
$buffer .= $this->span(PHP_Debug::getElapsedTime(
$properties['startTime'],
$properties['endTime']),
'time');
} else {
$buffer .= ' ';
}
return $buffer;
}
/**
* process display of the main information of debug
*
* @param array $properties Properties of the debug line
* @return string Formatted string containing the main debug info
* @since V2.0.0 - 28 Apr 2006
*/
protected function processDebugInfo($properties)
{
switch($properties['type'])
{
// Case for each of the debug lines types
// 1 : Standard
case PHP_DebugLine::TYPE_STD:
$buffer = $this->options['HTML_TABLE_interrow_info'];
$buffer .= $this->span($properties['info'], 'std');
break;
// 2 : Query
case PHP_DebugLine::TYPE_QUERY:
$buffer = $this->options['HTML_TABLE_interrow_info'];
$buffer .= $this->span($properties['info'], 'query');
break;
// 3 : Query related
case PHP_DebugLine::TYPE_QUERYREL:
$buffer = $this->options['HTML_TABLE_interrow_info'];
$buffer .= $this->span($properties['info'], 'query');
break;
// 4 : Environment
case PHP_DebugLine::TYPE_ENV:
$buffer = $this->options['HTML_TABLE_interrow_info'];
$buffer .= $this->showSuperArray($properties['info']);
break;
// 6 : User app error
case PHP_DebugLine::TYPE_APPERROR:
$buffer = $this->options['HTML_TABLE_interrow_info'];
$buffer .= $this->span('/!\\ User error : '.
$properties['info'] . ' /!\\', 'app-error');
break;
// 7
case PHP_DebugLine::TYPE_CREDITS:
$buffer = $this->options['HTML_TABLE_interrow_info'];
$buffer .= $this->span($properties['info'], 'credits');
break;
// 8
case PHP_DebugLine::TYPE_SEARCH:
$buffer = $this->options['HTML_TABLE_interrow_info'];
$buffer .= $this->showSearch();
break;
// 9
case PHP_DebugLine::TYPE_DUMP:
$buffer = $this->options['HTML_TABLE_interrow_info'];
$buffer .= $this->showDump($properties);
break;
// 10
case PHP_DebugLine::TYPE_PROCESSPERF:
$buffer = $this->options['HTML_TABLE_interrow_info'];
$buffer .= $this->showProcessTime();
break;
// 11
case PHP_DebugLine::TYPE_TEMPLATES:
$buffer = $this->options['HTML_TABLE_interrow_info'];
$buffer .= $this->showTemplates();
break;
// 12 : Main Page Action
case PHP_DebugLine::TYPE_PAGEACTION;
$buffer = $this->options['HTML_TABLE_interrow_info'];
$txtPageAction = 'Page Action';
$buffer .= $this->span("[ $txtPageAction : ".
$properties['info']. ' ]', 'pageaction');
break;
// 14 : SQL parse
case PHP_DebugLine::TYPE_SQLPARSE:
$buffer = $this->options['HTML_TABLE_interrow_info'];
$buffer .= $properties['info'];
break;
// 15 : Watches
case PHP_DebugLine::TYPE_WATCH:
$buffer = $this->options['HTML_TABLE_interrow_info'];
$infos = $properties['info'];
$buffer .= 'Variable '. $this->span($infos[0], 'watch').
' changed from value '. $this->span($infos[1], 'watch-val').
' ('. gettype($infos[1]).
') to value '. $this->span($infos[2], 'watch-val').
' ('. gettype($infos[2]). ')';
break;
// 16 : PHP errors
case PHP_DebugLine::TYPE_PHPERROR:
$buffer = $this->options['HTML_TABLE_interrow_info'];
$buffer .= $this->showError($properties['info']);
break;
default:
$buffer = $this->options['HTML_TABLE_interrow_info'];
$buffer .= "<b>Default(". $properties['type'].
")</b>: TO IMPLEMENT OR TO CORRECT : >".
$properties['info']. '<';
break;
}
return $buffer;
}
/**
* Return a string with applying a span style on it
*
* @param string $info String to apply the style
* @param string $class CSS style to apply to the string
* @return string Formatted string with style applied
* @since V2.0.0 - 05 May 2006
*/
protected function span($info, $class)
{
return '<span class="pd-'. $class .'">'. $info .'</span>';
}
/**
* process display of the type of the debug information
*
* @param array $properties Properties of the debug line
* @return string Formatted string containing the debug type
* @since V2.0.0 - 26 Apr 2006
*/
protected function processType($properties)
{
$buffer = $this->options['HTML_TABLE_interrow_type'];
$buffer .= PHP_DebugLine::$debugLineLabels[$properties['type']];
return $buffer;
}
/**
* process display of Class
*
* @param array $properties Properties of the debug line
* @return string Formatted string containing the class
* @since V2.0.0 - 26 Apr 2006
*/
protected function processClass($properties)
{
$buffer = '';
switch ($properties['type'])
{
case PHP_DebugLine::TYPE_STD:
case PHP_DebugLine::TYPE_QUERY:
case PHP_DebugLine::TYPE_QUERYREL:
case PHP_DebugLine::TYPE_APPERROR:
case PHP_DebugLine::TYPE_PAGEACTION:
case PHP_DebugLine::TYPE_PHPERROR:
case PHP_DebugLine::TYPE_SQLPARSE:
case PHP_DebugLine::TYPE_WATCH:
case PHP_DebugLine::TYPE_DUMP:
$buffer .= $this->options['HTML_TABLE_interrow_class'];
if (!empty($properties['class'])) {
$buffer .= $properties['class'];
} else {
$buffer .= ' ';
}
break;
case PHP_DebugLine::TYPE_CREDITS:
case PHP_DebugLine::TYPE_SEARCH:
case PHP_DebugLine::TYPE_PROCESSPERF:
case PHP_DebugLine::TYPE_TEMPLATES:
case PHP_DebugLine::TYPE_ENV:
$buffer .= $this->options['HTML_TABLE_interrow_class'];
$buffer .= ' ';
break;
default:
break;
}
return $buffer;
}
/**
* process display of function
*
* @param array $properties Properties of the debug line
* @return string Formatted string containing the function
* @since V2.0.0 - 26 Apr 2006
*/
protected function processFunction($properties)
{
$buffer = '';
switch ($properties['type'])
{
case PHP_DebugLine::TYPE_STD:
case PHP_DebugLine::TYPE_QUERY:
case PHP_DebugLine::TYPE_QUERYREL:
case PHP_DebugLine::TYPE_APPERROR:
case PHP_DebugLine::TYPE_PAGEACTION:
case PHP_DebugLine::TYPE_PHPERROR:
case PHP_DebugLine::TYPE_SQLPARSE:
case PHP_DebugLine::TYPE_WATCH:
case PHP_DebugLine::TYPE_DUMP:
$buffer .= $this->options['HTML_TABLE_interrow_function'];
if (!empty($properties['function'])) {
if ($properties['function'] != 'unknown') {
$buffer .= $properties['function']. '()';
} else {
$buffer .= ' ';
}
} else {
$buffer .= ' ';
}
break;
case PHP_DebugLine::TYPE_CREDITS:
case PHP_DebugLine::TYPE_SEARCH:
case PHP_DebugLine::TYPE_PROCESSPERF:
case PHP_DebugLine::TYPE_TEMPLATES:
case PHP_DebugLine::TYPE_ENV:
$buffer .= $this->options['HTML_TABLE_interrow_function'];
$buffer .= ' ';
break;
default:
break;
}
return $buffer;
}
/**
* process display of line number
*
* @param array $properties Properties of the debug line
* @return string Formatted string containing the line number
* @since V2.0.0 - 26 Apr 2006
*/
protected function processLine($properties)
{
$buffer = '';
switch ($properties['type'])
{
case PHP_DebugLine::TYPE_STD:
case PHP_DebugLine::TYPE_QUERY:
case PHP_DebugLine::TYPE_QUERYREL:
case PHP_DebugLine::TYPE_APPERROR:
case PHP_DebugLine::TYPE_PAGEACTION:
case PHP_DebugLine::TYPE_PHPERROR:
case PHP_DebugLine::TYPE_SQLPARSE:
case PHP_DebugLine::TYPE_WATCH:
case PHP_DebugLine::TYPE_DUMP:
$buffer.= $this->options['HTML_TABLE_interrow_line'];
if (!empty($properties['line'])) {
$buffer.= '<span class="pd-line">'. $properties['line']. '</span>';
} else {
$buffer.= ' ';
}
break;
case PHP_DebugLine::TYPE_CREDITS:
case PHP_DebugLine::TYPE_SEARCH:
case PHP_DebugLine::TYPE_PROCESSPERF:
case PHP_DebugLine::TYPE_TEMPLATES:
case PHP_DebugLine::TYPE_ENV:
$buffer.= $this->options['HTML_TABLE_interrow_line'];
$buffer.= ' ';
break;
default:
break;
}
return $buffer;
}
/**
* process display of file name
*
* @param array $properties Properties of the debug line
* @return string Formatted string containing the file
* @since V2.0.0 - 26 Apr 2006
*/
protected function processFile($properties)
{
$buffer = '';
switch ($properties['type'])
{
case PHP_DebugLine::TYPE_STD:
case PHP_DebugLine::TYPE_QUERY:
case PHP_DebugLine::TYPE_QUERYREL:
case PHP_DebugLine::TYPE_APPERROR:
case PHP_DebugLine::TYPE_PAGEACTION:
case PHP_DebugLine::TYPE_PHPERROR:
case PHP_DebugLine::TYPE_SQLPARSE:
case PHP_DebugLine::TYPE_WATCH:
case PHP_DebugLine::TYPE_DUMP:
$buffer .= $this->options['HTML_TABLE_interrow_file'];
if (!empty($properties['file'])) {
if (!empty($this->options['HTML_TABLE_view_source_script_path']) &&
!empty($this->options['HTML_TABLE_view_source_script_name'])) {
$buffer .= '<a href="'. $this->options['HTML_TABLE_view_source_script_path']
. '/'. $this->options['HTML_TABLE_view_source_script_name']
.'?file='. urlencode($properties['file']);
$buffer .= '">'. basename($properties['file']). '</a>';
} else {
$buffer .= basename($properties['file']);
}
} else {
$buffer .= ' ';
}
break;
case PHP_DebugLine::TYPE_CREDITS:
case PHP_DebugLine::TYPE_SEARCH:
case PHP_DebugLine::TYPE_PROCESSPERF:
case PHP_DebugLine::TYPE_TEMPLATES:
case PHP_DebugLine::TYPE_ENV:
$buffer .= $this->options['HTML_TABLE_interrow_file'];
$buffer .= ' ';
break;
default:
break;
}
return $buffer;
}
/**
* Dump a variable
*
* @since V2.0.0 - 26 Apr 2006
*/
protected function showDump($properties)
{
$buffer = '';
// Check display with a <pre> design
if (is_array($properties['info'][1])) {
$preDisplay = true;
} elseif (is_object($properties['info'][1])) {
$preDisplay = true;
} else {
$preDisplay = false;
}
// Check var name
if (empty($properties['info'][0])) {
if (is_array($properties['info'][1])) {
$varName = 'Array';
} elseif (is_object($properties['info'][1])) {
$varName = get_class($properties['info'][1]);
} else {
$varName = 'Variable';
}
} else {
$varName = $properties['info'][0];
}
// Output
if ($properties['type'] != PHP_DebugLine::TYPE_ENV) {
$title = "dump of '";
}
$title .= $varName. "' (". gettype($properties['info'][1]) .") : ";
$buffer .= $this->span($title , 'dump-title');
if ($preDisplay == true){
$buffer .= '<pre>';
$buffer .= PHP_Debug::dumpVar($properties['info'][1],
'', false, PHP_Debug::DUMP_STR);
} else {
$buffer .= $this->span(PHP_Debug::dumpVar(
$properties['info'][1],
'',
false,
PHP_Debug::DUMP_STR), 'dump-val');
}
if ($preDisplay == true){
$buffer .= '</pre>';
}
return $buffer;
}
/**
* Process the search combo box
*
* @since V2.0.0 - 26 Apr 2006
*/
protected function showSearch()
{
// Repost all posted data
$txtGo = 'Go !';
$txtStringToSearch = 'Search for';
$txtCaseSensitive = 'Case sensitive';
$txtSelectByType = 'Select only info of type';
$buffer = '';
$debugSearchVal = isset($_REQUEST["PHPDEBUG_SEARCH"]) ? trim($_REQUEST["PHPDEBUG_SEARCH"]) : '';
$debugSearchCSVal = isset($_REQUEST["PHPDEBUG_SEARCH_CS"]) ? ' checked="checked"' : '';
$buffer .= '
<form id="phpDebugForm" action="'. $_SERVER['PHP_SELF']. '">
<table>
<tr>
<td class="pd-search">'. $txtStringToSearch .'</td>
<td class="pd-search">:</td>
<td class="pd-search">
<input class="pd-search" type="text" name="PHPDEBUG_SEARCH" value="'. $debugSearchVal. '" />
</td>
<td class="pd-search">'. $txtCaseSensitive .'</td>
<td class="pd-search">:</td>
<td class="pd-search">
<input class="pd-search" type="checkbox" name="PHPDEBUG_SEARCH_CS" '. $debugSearchCSVal .' />
</td>
</tr>
<tr>
<td class="pd-search">'. $txtSelectByType. '</td>
<td class="pd-search">:</td>
<td class="pd-search">
<select class="pd-search" name="PHPDEBUG_SEARCH_TYPE">';
foreach (PHP_DebugLine::$debugLineLabels as $lkey => $lvalue) {
$debugSearchTypeVal = (!empty($_REQUEST["PHPDEBUG_SEARCH_TYPE"])
& $lkey == $_REQUEST["PHPDEBUG_SEARCH_TYPE"]) ? ' selected="selected"' : '';
$buffer .= " <option value=\"$lkey\"$debugSearchTypeVal>» $lvalue</option>". CR;
}
$buffer .= '
</select>
</td>
<td class="pd-search"> </td>
<td class="pd-search"> </td>
<td class="pd-search">
<input class="pd-search" type="submit" value="'. $txtGo. '" />
</td>
</tr>
</table>
</form>';
return $buffer;
}
/**
* Process the templates
*
* @since V2.0.0 - 26 Apr 2006
*/
protected function showTemplates()
{
$txtMainFile = 'MAIN File';
$idx = 1;
$buffer = '<br />';
foreach($this->DebugObject->getRequiredFiles() as $lvalue) {
$isToDisplay = true;
if ($this->options['HTML_TABLE_view_source_excluded_template']) {
foreach ($this->options['HTML_TABLE_view_source_excluded_template'] as $template) {
if (stristr($lvalue, $template)) {
$isToDisplay = false;
}
}
}
if ($isToDisplay == true) {
$buffer .= $this->span($lvalue, 'files');
$buffer .= ' <a href="'. $this->options['HTML_TABLE_view_source_script_path']
. '/'. $this->options['HTML_TABLE_view_source_script_name']
.'?file='. urlencode($lvalue). '">View source</a> ';
// Mark main file
if ($idx == 1) {
$buffer .= $this->span('« '. $txtMainFile, 'main-file');
}
$idx++;
$buffer .= '<br />'. CR;
}
}
$buffer .= '<br />'. CR;
return $buffer;
}
/**
* Process an error info
*
* @param array $info Array containing information about the error
*
* @since V2.0.0 - 25 Apr 2006
* @see PHP_DEBUGLINE_PHPERROR
*/
protected function showError($infos)
{
$buffer = '';
$infos[1] = str_replace("'", '"', $infos[1]);
$infos[1] = str_replace('href="function.', ' href="http://www.php.net/'. $this->options['lang']. '/', $infos[1]);
switch ($infos[0])
{
case E_WARNING:
$errorlevel = 'PHP WARNING : ';
$buffer .= '<span class="pd-php-warning"> /!\\ '.
$errorlevel. $infos[1] . ' /!\\ </span>';
break;
case E_NOTICE:
$errorlevel = 'PHP notice : ';
$buffer .= '<span class="pd-php-notice">'.
$errorlevel. $infos[1] . '</span>';
break;
case E_USER_ERROR:
$errorlevel = 'PHP User error : ';
$buffer .= '<span class="pd-php-user-error"> /!\\ '.
$errorlevel. $infos[1] . ' /!\\ </span>';
break;
case E_STRICT:
$errorlevel = 'PHP STRICT error : ';
$buffer .= '<span class="pd-php-user-error"> /!\\ '.
$errorlevel. $infos[1] . ' /!\\ </span>';
break;
default:
$errorlevel = 'PHP errorlevel = '. $infos[0]. ' : ';
$buffer .= $errorlevel. ' is not implemented in PHP_Debug ('.
__FILE__. ','. __LINE__. ')';
break;
}
return $buffer;
}
/**
* Show a super array
*
* @param string $SuperArrayType Type of super en array to add
* @since V2.0.0 - 07 Apr 2006
*/
protected function showSuperArray($SuperArrayType)
{
// Lang
$txtVariable = 'Var';
$txtNoVariable = 'NO VARIABLE';
$NoVariable = ' -- '. $txtNoVariable. ' -- ';
$SuperArray = null;
$buffer = '';
$ArrayTitle = PHP_Debug::$globalEnvConstantsCorresp[$SuperArrayType];
$SuperArray = $GLOBALS[$ArrayTitle];
$Title = $ArrayTitle. ' '. $txtVariable;
$SectionBasetitle = '<b>$Title ('. count($SuperArray). ') :';
if (count($SuperArray)) {
$buffer .= $SectionBasetitle. '</b>';
$buffer .= '<pre>'. PHP_Debug::dumpVar(
$SuperArray,
$ArrayTitle,
false,
PHP_Debug::DUMP_STR). '</pre>';
}
else {
$buffer .= $SectionBasetitle. "$NoVariable</b>";
}
return $buffer;
}
/**
* Add the environment display depending on the current configuration
*
* @since V2.0.0 - 18 apr 2006
*/
protected function addSuperArray()
{
if ($this->options['HTML_TABLE_show_super_array'] == true) {
// Divide Request tab
if ($this->options['HTML_TABLE_use_request_arr'] == false) {
// Include Post Var
$this->DebugObject->addDebug(PHP_Debug::GLOBAL_POST, PHP_DebugLine::TYPE_ENV);
// Include Get Var
$this->DebugObject->addDebug(PHP_Debug::GLOBAL_GET, PHP_DebugLine::TYPE_ENV);
// Include File Var
$this->DebugObject->addDebug(PHP_Debug::GLOBAL_FILES, PHP_DebugLine::TYPE_ENV);
// Include Cookie Var
$this->DebugObject->addDebug(PHP_Debug::GLOBAL_COOKIE, PHP_DebugLine::TYPE_ENV);
}
else {
// Only display Request Tab
$this->DebugObject->addDebug(PHP_Debug::GLOBAL_REQUEST, PHP_DebugLine::TYPE_ENV);
}
// Include sessions variabmes, check if we have any
if (!empty($_SESSION)) {
$this->DebugObject->addDebug(PHP_Debug::GLOBAL_SESSION, PHP_DebugLine::TYPE_ENV);
}
}
}
/**
* Add the process time information to the debug information
*
* @since V2.0.0 - 18 Apr 2006
*/
protected function showProcessTime()
{
// Lang
$txtExecutionTime = 'Global execution time ';
$txtPHP = 'PHP';
$txtSQL = 'SQL';
$txtSECOND = 's';
$txtOneQry = ' query';
$txtMultQry = ' queries';
$queryCount = $this->DebugObject->getQueryCount();
$txtQuery = $queryCount > 1 ? $txtMultQry : $txtOneQry;
$buffer = '';
// Performance Debug
$processTime = $this->DebugObject->getProcessTime();
$sqlTime = $this->DebugObject->getQueryTime();
$phpTime = $processTime - $sqlTime;
$sqlPercent = round(($sqlTime / $processTime) * 100, 2);
$phpPercent = round(($phpTime / $processTime) * 100, 2);
$buffer .= '<div><table class="pd-perf-table"><tr><td class="pd-perf" align="center">'. $txtExecutionTime;
$buffer .= '</td><td class="pd-perf" align="center">'. $processTime . $txtSECOND;
$buffer .= '</td><td class="pd-perf" align="center">100%';
$buffer .= '</td><td class="pd-perf" align="center"> </td></tr>';
$buffer .= '<tr><td class="pd-perf" align="center">'. $txtPHP;
$buffer .= '</td><td class="pd-perf" align="center">'. $phpTime . $txtSECOND;
$buffer .= '</td><td class="pd-perf" align="center">'. $phpPercent .'%';
$buffer .= '</td><td class="pd-perf" align="center"> </td></tr>';
$buffer .= '<tr><td class="pd-perf" align="center">'. $txtSQL;
$buffer .= '</td><td class="pd-perf" align="center">'. $sqlTime. $txtSECOND;
$buffer .= '</td><td class="pd-perf" align="center">'. $sqlPercent . '%';
$buffer .= '</td><td class="pd-perf" align="center">'. $queryCount. $txtQuery. '</td></tr>';
$buffer .= '</table></div>';
return $buffer;
}
}