Source for file Div.php
Documentation is available at Div.php
* Class of the HTML_Div renderer
* Idea from the debug system of the symfony PHP framework
* @package linea21.externals
* @author Vernet Loïc <qrf_coil[at]yahoo.fr>, Fabien Potencier, François Zaninotto
* @see http://www.symfony-project.org
* @version CVS: $Id: Div.php,v 1.3 2008/10/05 14:41:37 c0il Exp $
require_once dirname(__FILE__ ) . '/DivConfig.php';
* A floating div renderer for PHP_Debug
* Returns a floating based representation of the debug infos in XHTML sctrict
* @package linea21.externals
* @author Loïc Vernet <qrf_coil at yahoo dot fr>
* @since V2.1.0 - 30 march 2007
// debug types for Vars & Config
protected static $settingsType = array(
// debug types for Log & Message tab
protected static $msgTypes = array(
// debug types for Database tab
protected static $databaseTypes = array(
* Debug_Renderer_HTML_Div class constructor
* @since V2.1.0 - 3 apr 2007
if ($this->options['HTML_DIV_disable_credits'] == false) {
* This is the function to display the debug informations
* @since V2.0.0 - 07 Apr 2006
* @see PHP_Debug::Render()
* @since V2.1.1 - 23 apr 2007
$this->options['HTML_DIV_images_path']
$this->options['HTML_DIV_sfWebDebugW3CDetails']
* Add the debug informations of the W3C validation process
* @since 2.1.0 - 23 avr. 2007
$this->options['HTML_DIV_sfWebDebugW3CTableHeader']
foreach ($res->$key as $error) {
$id = $errorCpt. ($error->messageid ? ' ('. $error->messageid. ')' : '');
$this->options['HTML_DIV_sfWebDebugW3CErrorRow']
* @since V2.1.0 - 30 march 2007
foreach ($debugInfos as $debugInfo) {
$properties = $debugInfo->getProperties();
if (in_array($properties['type'], self::$databaseTypes)) {
array($buffer ? $buffer : '<li>No database debug available</li>'),
$this->options['HTML_DIV_sfWebDebugDatabaseDetails']
* @since V2.1.0 - 30 march 2007
foreach($debugInfos as $debugInfo) {
$properties = $debugInfo->getProperties();
if (in_array($properties['type'], self::$msgTypes)) {
// Error level of debug information
<td class="sfWebDebugLogNumber"># '. $idx. '</td>
<td class="sfWebDebugLogType">
<img src="'. $this->options['HTML_DIV_images_path']. '/'. $infoImg . '" alt="" /> '. $this->processType($properties).
<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>
$this->options['HTML_DIV_images_path']
$this->options['HTML_DIV_sfWebDebugLog']
* Get the log level of the debug info
* @since V2.1.0 - 2 avr. 2007
switch ($properties['type']) {
* Return the global error level corresponding to the related php error
* @since 2.1.0 - 3 apr 2007
$infos = $properties['info'];
case E_RECOVERABLE_ERROR:
* Get the image info for the current debug type
* @since V2.1.0 - 2 avp 2007
return $this->options['HTML_DIV_debug_level_classes'][$debug_level];
* Get the image info for the current debug type
* @since V2.1.0 - 2 avp 2007
$info = $this->options['HTML_DIV_image_info'];
$warning = $this->options['HTML_DIV_image_warning'];
$error = $this->options['HTML_DIV_image_error'];
* @since V2.1.0 - 30 march 2007
'{$sfWebDebugConstants}',
$this->options['HTML_DIV_images_path'],
$this->options['HTML_DIV_sfWebDebugConfig']
* Return all settings of application
* @since V2.1.0 - 2 apr 2007
foreach($debugInfos as $debugInfo) {
$infos = $debugInfo->getProperties();
if (in_array($infos['type'], self::$settingsType)) {
$settings[] = $infos['info'];
* Returns PHP globals variables as a sorted array.
* @return array PHP globals
* @since V2.1.0 - 2 apr 2007
foreach (array('cookie', 'server', 'get', 'post', 'files', 'env', 'session') as $name) {
if (!isset ($GLOBALS['_'. strtoupper($name)])) {
$values[$name] = array();
foreach ($GLOBALS['_'. strtoupper($name)] as $key => $value) {
$values[$name][$key] = $value;
* Returns PHP information as an array.
* @return array An array of php information
* @since V2.1.0 - 2 apr 2007
// assign extension version if available
if ($values['extensions']) {
foreach ($values['extensions'] as $lkey => $extension) {
$values['extensions'][$lkey] = phpversion($extension) ? $extension.
* Add the process time information to the debug information
* @since V2.0.0 - 18 Apr 2006
$txtExecutionTime = 'Global execution time ';
$txtMultQry = ' queries';
$txtQuery = $queryCount > 1 ? $txtMultQry : $txtOneQry;
$phpTime = $processTime - $sqlTime;
$sqlPercent = round(($sqlTime / $processTime) * 100, 2);
$phpPercent = round(($phpTime / $processTime) * 100, 2);
$processTime = $processTime* 1000;
$sqlTime = $sqlTime* 1000;
$phpTime = $phpTime* 1000;
foreach($debugInfos as $debugInfo) {
$properties = $debugInfo->getProperties();
if ($properties['startTime'] && $properties['endTime']) {
$localPercent = round((($properties['endTime'] -
$properties['startTime'])* 1000 / $processTime) * 100, 2);
<td class="sfWebDebugLogMessagePerf">'. $this->ProcessDebugInfo($properties). '</td>
<td style="text-align: right">'. $this->ProcessExecTime($properties). '</td>
<td style="text-align: right">'. $localPercent. '%</td>
$this->options['HTML_DIV_sfWebDebugTimeDetails']
* Default render function for HTML_Div renderer
* @since V2.0.0 - 11 Apr 2006
* Displays the header of the PHP_Debug object
* @since V2.0.0 - 08 Apr 2006
$this->options['HTML_DIV_images_path'],
$this->options['HTML_DIV_header']);
* Diplays the footer of the PHP_Debug object
* @since V2.0.0 - 08 Apr 2006
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
if (!empty($properties['endTime'])) {
$properties['startTime'],
$buffer = $this->span($time > 1 ? $time. ' ms' : '< 1 ms', 'time');
* 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
switch($properties['type']) {
// Case for each of the debug lines types
$buffer .= $this->span($properties['info'], 'std');
$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>',
$buffer .= $this->span($properties['info'], 'query');
$buffer .= $this->span('/!\\ User error : '.
$properties['info']. ' /!\\', 'app-error');
$buffer .= $this->span($properties['info'], 'credits');
$buffer .= $this->showDump($properties);
$buffer .= $this->span('[Action : '.
$properties['info']. ']', 'pageaction');
$buffer .= $properties['info'];
$infos = $properties['info'];
$buffer .= 'Variable '. $this->span($infos[0], 'watch').
$this->span($infos[1], 'watch-val'). ' ('. gettype($infos[1]).
') to value '. $this->span($infos[2], 'watch-val').
$buffer .= $this->showError($properties['info']);
$buffer .= '<b>Default('. $properties['type'].
')</b>: TO IMPLEMENT OR TO CORRECT : >'.
$properties['info']. '<';
* 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
* 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
switch ($properties['type'])
case PHP_DebugLine::TYPE_STD:
if (!empty($properties['class'])) {
$buffer .= $properties['class'];
* 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
switch ($properties['type'])
if (!empty($properties['function'])) {
if ($properties['function'] != 'unknown') {
$buffer .= $properties['function']. '()';
* 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
switch ($properties['type'])
if (!empty($properties['line'])) {
$buffer.= '<span class="line">'.
$properties['line']. '</span>';
* 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
switch ($properties['type'])
if (!empty($properties['file'])) {
if (!empty($this->options['HTML_DIV_view_source_script_path']) &&
!empty($this->options['HTML_DIV_view_source_script_name'])) {
$this->options['HTML_DIV_view_source_script_path'].
$this->options['HTML_DIV_view_source_script_name'].
$buffer .= '">'. basename($properties['file']). '</a>';
$buffer .= basename($properties['file']);
* @since V2.0.0 - 26 Apr 2006
protected function showDump($properties)
// Check display with a <pre> design
} elseif (is_object($properties['info'][1])) {
if (empty($properties['info'][0])) {
} elseif (is_object($properties['info'][1])) {
$varName = get_class($properties['info'][1]);
$varName = $properties['info'][0];
$title .= $varName. '\' ('. gettype($properties['info'][1]) . ') : ';
$buffer .= $this->span($title , 'dump-title');
if ($preDisplay == true){
if ($preDisplay == true) {
* @since V2.0.0 - 26 Apr 2006
$txtMainFile = 'MAIN File';
foreach($this->DebugObject->getRequiredFiles() as $lvalue) {
if ($this->options['HTML_DIV_view_source_excluded_template']) {
foreach ($this->options['HTML_DIV_view_source_excluded_template'] as $template) {
if ($isToDisplay == true) {
$buffer .= '<div class="source">';
if (!empty($this->options['HTML_DIV_view_source_script_path']) &&
!empty($this->options['HTML_DIV_view_source_script_name'])) {
$this->options['HTML_DIV_view_source_script_path'].
'/'. $this->options['HTML_DIV_view_source_script_name'].
'?file='. urlencode($lvalue). '">View source</a> ';
$buffer .= $this->span('« '. $txtMainFile, 'main-file');
$buffer .= '</div><br />'. CR;
* Truncate/replace a pattern from the file path
* @param string full file path
* @since V2.1.0 - 3 apr 2007
* - HTML_DIV_remove_templates_pattern
* - HTML_DIV_templates_pattern
if ($this->options['HTML_DIV_remove_templates_pattern'] &&
$this->options['HTML_DIV_templates_pattern']) {
return strtr($file, $this->options['HTML_DIV_templates_pattern']);
* @param array $info Array containing information about the error
* @since V2.0.0 - 25 Apr 2006
* @see PHP_DebugLine::TYPE_PHPERROR
' href="http://www.php.net/'.
$this->options['lang']. '/', $infos[1]);
$errorlevel = 'PHP WARNING : ';
$buffer .= '<span class="pd-php-warning"> /!\\ '.
$errorlevel. $infos[1] . ' /!\\ </span>';
$errorlevel = 'PHP notice : ';
$buffer .= '<span class="pd-php-notice">'.
$errorlevel. $infos[1] . '</span>';
$errorlevel = 'PHP User error : ';
$buffer .= '<span class="pd-php-user-error"> /!\\ '.
$errorlevel. $infos[1] . ' /!\\ </span>';
$errorlevel = 'PHP STRICT error : ';
$buffer .= '<span class="pd-php-user-error"> /!\\ '.
$errorlevel. $infos[1] . ' /!\\ </span>';
$errorlevel = 'PHP errorlevel = '. $infos[0]. ' : ';
' is not implemented in PHP_Debug ('. __FILE__. ','. __LINE__. ')';
* @param string $SuperArrayType Type of super en array to add
* @since V2.0.0 - 07 Apr 2006
$txtNoVariable = 'NO VARIABLE';
$NoVariable = ' -- '. $txtNoVariable. ' -- ';
$ArrayTitle = PHP_Debug::$globalEnvConstantsCorresp[$SuperArrayType];
$SuperArray = $GLOBALS[$ArrayTitle];
$Title = $ArrayTitle. ' '. $txtVariable;
$SectionBasetitle = '<b>'. $Title. '('. count($SuperArray). ') :';
if (count($SuperArray)) {
$buffer .= $SectionBasetitle. '</b>';
$buffer .= $SectionBasetitle. $NoVariable. '</b>';
* @param string $SuperArrayType Type of super en array to add
* @since V2.0.0 - 07 Apr 2006
$txtNoVariable = 'NO VARIABLE';
$NoVariable = ' -- '. $txtNoVariable. ' -- ';
$SectionBasetitle = '<b>'. $name. '('. count($array). ') :';
$buffer .= $SectionBasetitle. '</b>';
$buffer .= $SectionBasetitle. $NoVariable. '</b>';
|