PHP_Debug
[ class tree: PHP_Debug ] [ index: PHP_Debug ] [ all elements ]

Source for file Div.php

Documentation is available at Div.php

  1. <?php
  2.  
  3. /**
  4.  * Class of the HTML_Div renderer
  5.  * 
  6.  * Idea from the debug system of the symfony PHP framework
  7.  * @see http://www.symfony-project.org
  8.  * @author Fabien Potencier
  9.  * @author François Zaninotto
  10.  * 
  11.  * @author  Vernet Loïc
  12.  * 
  13.  * @version CVS: $Id: Div.php,v 1.2 2008/08/31 19:24:17 c0il Exp $
  14.  */
  15.  
  16. require_once 'PHP/Debug/Renderer/HTML/DivConfig.php';
  17.  
  18.  
  19. /**
  20.  * A floating div renderer for PHP_Debug
  21.  *
  22.  * Returns a floating based representation of the debug infos in XHTML sctrict
  23.  * format
  24.  *
  25.  * @package PHP_Debug
  26.  * @category PHP
  27.  * @author Loïc Vernet <qrf_coil at yahoo dot fr>
  28.  * @since V2.1.0 - 30 march 2007
  29.  * 
  30.  * @package PHP_Debug
  31.  * @filesource
  32.  */
  33.  
  34. {    
  35.     // debug types for Vars & Config
  36.     protected static $settingsType = array(
  37.         PHP_DebugLine::TYPE_ENV,
  38.     );
  39.  
  40.     // debug types for Log & Message tab
  41.     protected static $msgTypes = array(
  42.         PHP_DebugLine::TYPE_STD,
  43.         PHP_DebugLine::TYPE_PAGEACTION,
  44.         PHP_DebugLine::TYPE_APPERROR,
  45.         PHP_DebugLine::TYPE_CREDITS,
  46.         PHP_DebugLine::TYPE_DUMP,
  47.         PHP_DebugLine::TYPE_WATCH,
  48.         PHP_DebugLine::TYPE_PHPERROR
  49.     );
  50.  
  51.     // debug types for Database tab
  52.     protected static $databaseTypes = array(
  53.         PHP_DebugLine::TYPE_QUERY,
  54.         PHP_DebugLine::TYPE_QUERYREL,
  55.         PHP_DebugLine::TYPE_SQLPARSE,
  56.     );
  57.  
  58.     /**
  59.      * Debug_Renderer_HTML_Div class constructor
  60.      * 
  61.      * @since V2.1.0 - 3 apr 2007
  62.      */
  63.     function __construct($DebugObject$options)
  64.     {
  65.         $this->DebugObject = $DebugObject;
  66.         $this->defaultOptions = PHP_Debug_Renderer_HTML_DivConfig::singleton()->getConfig();
  67.         $this->setOptions($options);
  68.         
  69.         if ($this->options['HTML_DIV_disable_credits'== false{
  70.             $this->DebugObject->addDebugFirst($this->options['HTML_DIV_credits']
  71.                 PHP_DebugLine::TYPE_CREDITS);
  72.         }
  73.  
  74.         // Add execution time
  75.         $this->DebugObject->addProcessPerf();
  76.     }
  77.  
  78.     /**
  79.      * This is the function to display the debug informations
  80.      *
  81.      * @since V2.0.0 - 07 Apr 2006
  82.      * @see PHP_Debug::Render()
  83.      */
  84.     public function display()
  85.     {
  86.         $buffer '';
  87.  
  88.         // Header        
  89.         $buffer .= $this->displayHeader();
  90.  
  91.         // Infos
  92.         $debugInfos $this->DebugObject->getDebugBuffer()
  93.              
  94.         // Vars & config
  95.         $buffer .= $this->showVarsAndConfig($debugInfos);
  96.  
  97.         // Logs & msg
  98.         $buffer .= $this->showLogsAndMsg($debugInfos);
  99.  
  100.         // Database
  101.         $buffer .= $this->showDatabaseInfos($debugInfos);
  102.  
  103.         // W3C Validation
  104.         $buffer .= $this->showW3cValidation($debugInfos);
  105.  
  106.         // Process time
  107.         $buffer .= $this->showProcessTime($debugInfos);
  108.         
  109.         // Footer
  110.         $buffer .= $this->displayFooter();
  111.         
  112.         return $buffer;        
  113.     }
  114.  
  115.     /**
  116.      * Show W3C validator tab
  117.      * 
  118.      * @author COil
  119.      * @since V2.1.1 - 23 apr 2007
  120.      */
  121.     protected function showW3cValidation()
  122.     {
  123.         return str_replace(
  124.             array(
  125.                 '{$imagesPath}',
  126.             ),
  127.             array(
  128.                 $this->options['HTML_DIV_images_path']
  129.             ),
  130.             $this->options['HTML_DIV_sfWebDebugW3CDetails']
  131.         );
  132.     }
  133.  
  134.     /**
  135.      * Add the debug informations of the W3C validation process
  136.      * 
  137.      * @author Vernet Loïc
  138.      * @since 2.1.0 - 23 avr. 2007
  139.      */
  140.     protected function addW3CErrorInfos($res$key)
  141.     {
  142.         $title ucwords($key);  
  143.         $type 'sfW3C'$title;
  144.         $errorCpt = 1;
  145.         $results str_replace(
  146.           '{$title}'
  147.           $title
  148.           $this->options['HTML_DIV_sfWebDebugW3CTableHeader']
  149.         );
  150.  
  151.         foreach ($res->$key as $error{
  152.             $id $errorCpt($error->messageid ? ' ('$error->messageid. ')' '');
  153.             $results .= str_replace(
  154.                 array(
  155.                     '{$type}'
  156.                     '{$cpt}'
  157.                     '{$line}'
  158.                     '{$col}'
  159.                     '{$message}',
  160.                     '{$source}',
  161.                 ),
  162.                 array(
  163.                     $type,
  164.                     $id,
  165.                     $error->line,
  166.                     $error->col,
  167.                     $error->message,
  168.                     '&nbsp',
  169.                 ),
  170.                 $this->options['HTML_DIV_sfWebDebugW3CErrorRow']
  171.             );                        
  172.             $errorCpt++;        
  173.         }
  174.         $results .= '</table>';
  175.         
  176.         return $results;
  177.     }
  178.  
  179.     /**
  180.      * Shows vars & config
  181.      * 
  182.      * @param array debug row
  183.      * 
  184.      * @author COil
  185.      * @since V2.1.0 - 30 march 2007
  186.      */
  187.     protected function showDatabaseInfos($debugInfos)
  188.     {
  189.         $idx = 1;
  190.         $buffer '';
  191.  
  192.         foreach ($debugInfos as $debugInfo{
  193.             $properties $debugInfo->getProperties();
  194.             if (in_array($properties['type']self::$databaseTypes)) {                
  195.                 $buffer.= '<li>['$this->processExecTime($properties)'] '
  196.                     $this->processDebugInfo($properties.'</li>'. CR;
  197.             }
  198.         }
  199.  
  200.         return str_replace(
  201.             array('{$buffer}'),
  202.             array($buffer $buffer '<li>No database debug available</li>'),
  203.             $this->options['HTML_DIV_sfWebDebugDatabaseDetails']
  204.         );
  205.     }
  206.  
  207.     /**
  208.      * Shows vars & config
  209.      * 
  210.      * @author COil
  211.      * @since V2.1.0 - 30 march 2007
  212.      */
  213.     protected function showLogsAndMsg($debugInfos)
  214.     {
  215.         $idx = 1;
  216.         $buffer '';
  217.  
  218.         foreach($debugInfos as $debugInfo{
  219.             $properties $debugInfo->getProperties();
  220.             if (in_array($properties['type']self::$msgTypes)) {
  221.             
  222.                 // Error level of debug information
  223.                 $level $this->getLogInfoLevel($properties);   
  224.                 $infoImg $this->getImageInfo($level);
  225.             
  226.                 $buffer .= '<tr class=\'sfWebDebugLogLine '$this->getDebugLevelClass($level)'\'>
  227.                     <td class="sfWebDebugLogNumber"># '$idx'</td>
  228.                     <td class="sfWebDebugLogType">
  229.                         <img src="'$this->options['HTML_DIV_images_path']'/'$infoImg .'" alt="" />&nbsp;'$this->processType($properties).
  230.                     '</td>
  231.                     <td class="sfWebDebugLogFile">'$this->processFile($properties)'</td>
  232.                     <td class="sfWebDebugLogLine">'$this->processLine($properties)'</td>
  233.                     <td class="sfWebDebugLogClass">'$this->processClass($properties)'</td>
  234.                     <td class="sfWebDebugLogFunction">'$this->processFunction($properties)'</td>
  235.                     <td class="sfWebDebugLogTime">'$this->processExecTime($properties)'</td>
  236.                     <td class="sfWebDebugLogMessage">'$this->processDebugInfo($properties)'</td>
  237.                 </tr>'. CR;
  238.                 $idx++;
  239.             }
  240.         }
  241.  
  242.         return str_replace(
  243.             array(
  244.                 '{$buffer}',
  245.                 '{$imagesPath}',
  246.             ),
  247.             array(
  248.                 $buffer,
  249.                 $this->options['HTML_DIV_images_path']
  250.             ),
  251.             $this->options['HTML_DIV_sfWebDebugLog']
  252.         );
  253.     }
  254.  
  255.     /**
  256.      * Get the log level of the debug info
  257.      * 
  258.      * @author COil
  259.      * @since V2.1.0 - 2 avr. 2007
  260.      * 
  261.      * @param array debug row
  262.      */
  263.     protected function getLogInfoLevel($properties)
  264.     {
  265.         $level PHP_DebugLine::INFO_LEVEL;
  266.  
  267.         switch ($properties['type']{
  268.             case PHP_DebugLine::TYPE_PAGEACTION:
  269.             case PHP_DebugLine::TYPE_CREDITS:
  270.             case PHP_DebugLine::TYPE_DUMP:
  271.             case PHP_DebugLine::TYPE_WATCH:
  272.             break;
  273.  
  274.             case PHP_DebugLine::TYPE_APPERROR:
  275.                 $level PHP_DebugLine::ERROR_LEVEL;
  276.             break;
  277.  
  278.             case PHP_DebugLine::TYPE_PHPERROR:
  279.                 $level $this->getPhpErrorLevel($properties);
  280.             break;
  281.         }
  282.         
  283.         return $level;        
  284.     }
  285.  
  286.     /**
  287.      * Return the global error level corresponding to the related php error
  288.      * level
  289.      * 
  290.      * @param array debug row
  291.      * 
  292.      * @author COil
  293.      * @since 2.1.0 - 3 apr 2007
  294.      */
  295.     protected function getPhpErrorLevel($properties)
  296.     {
  297.         $infos $properties['info'];
  298.  
  299.         switch ($infos[0]{
  300.             case E_ERROR:
  301.             case E_PARSE:
  302.             case E_CORE_ERROR:
  303.             case E_COMPILE_ERROR:
  304.             case E_USER_ERROR:
  305.                 return PHP_DebugLine::ERROR_LEVEL;
  306.             break;                
  307.             
  308.             case E_WARNING:
  309.             case E_CORE_WARNING:
  310.             case E_NOTICE:
  311.             case E_COMPILE_WARNING:
  312.             case E_USER_WARNING:
  313.             case E_USER_NOTICE:
  314.             case E_ALL:
  315.             case E_STRICT:
  316.             case E_RECOVERABLE_ERROR:
  317.                 return PHP_DebugLine::WARNING_LEVEL;
  318.             break;                
  319.  
  320.             default:
  321.                 return PHP_DebugLine::ERROR_LEVEL;
  322.             break;                
  323.         }
  324.     }
  325.  
  326.     /**
  327.      * Get the image info for the current debug type
  328.      * 
  329.      * @author COil
  330.      * @since V2.1.0 - 2 avp 2007
  331.      */
  332.     protected function getDebugLevelClass($debug_level)
  333.     {
  334.         return $this->options['HTML_DIV_debug_level_classes'][$debug_level];
  335.     }
  336.  
  337.     /**
  338.      * Get the image info for the current debug type
  339.      * 
  340.      * @author COil
  341.      * @since V2.1.0 - 2 avp 2007
  342.      */
  343.     protected function getImageInfo($debug_level)
  344.     {
  345.         $info $this->options['HTML_DIV_image_info'];
  346.         $warning $this->options['HTML_DIV_image_warning'];
  347.         $error   $this->options['HTML_DIV_image_error'];
  348.  
  349.         switch ($debug_level{
  350.             case PHP_DebugLine::INFO_LEVEL:
  351.                 $level $info;
  352.             break;
  353.  
  354.             case PHP_DebugLine::WARNING_LEVEL:
  355.                 $level $warning;
  356.             break;
  357.  
  358.             case PHP_DebugLine::ERROR_LEVEL:
  359.                 $level $error;
  360.             break;
  361.         }
  362.         
  363.         return $level;
  364.     }
  365.  
  366.     /**
  367.      * Shows vars & config
  368.      * 
  369.      * @author COil
  370.      * @since V2.1.0 - 30 march 2007
  371.      */
  372.     protected function showVarsAndConfig($debugInfos)
  373.     {
  374.         return str_replace(
  375.             array(
  376.                 '{$sfWebDebugRequest}',
  377.                 '{$sfWebDebugResponse}',
  378.                 '{$sfWebDebugSettings}',
  379.                 '{$sfWebDebugGlobals}',
  380.                 '{$sfWebDebugPhp}',
  381.                 '{$sfWebDebugFiles}',
  382.                 '{$imagesPath}',
  383.             ),
  384.             array(
  385.                 $this->showSuperArray(PHP_Debug::GLOBAL_REQUEST),
  386.                 $this->showSuperArray(PHP_Debug::GLOBAL_COOKIE),
  387.                 $this->showArray($this->settingsAsArray($debugInfos)'Settings'),
  388.                 $this->showArray($this->globalsAsArray()'Globals'),
  389.                 $this->showArray($this->phpInfoAsArray()'PHP Infos'),
  390.                 $this->showTemplates(),
  391.                 $this->options['HTML_DIV_images_path'],
  392.             ),
  393.             $this->options['HTML_DIV_sfWebDebugConfig']
  394.         );
  395.     }
  396.  
  397.     /**
  398.      * Return all settings of application
  399.      * 
  400.      * @author COil
  401.      * @since V2.1.0 - 2 apr 2007
  402.      */
  403.     public function settingsAsArray($debugInfos)
  404.     {
  405.         $settings = array();
  406.         foreach($debugInfos as $debugInfo{
  407.             $infos $debugInfo->getProperties();
  408.             if (in_array($infos['type']self::$settingsType)) {
  409.                 $settings[$infos['info']
  410.             }
  411.         }    
  412.     
  413.         return $settings;
  414.     }
  415.  
  416.    /**
  417.     * Returns PHP globals variables as a sorted array.
  418.     *
  419.     * @return array PHP globals
  420.     * @since V2.1.0 - 2 apr 2007
  421.     */
  422.     public static function globalsAsArray()
  423.     {
  424.         $values = array();
  425.         foreach (array('cookie''server''get''post''files''env''session'as $name{
  426.  
  427.             if (!isset($GLOBALS['_'.strtoupper($name)])) {
  428.                 continue;
  429.             }
  430.     
  431.             $values[$name= array();
  432.             foreach ($GLOBALS['_'strtoupper($name)as $key => $value{
  433.                 $values[$name][$key$value;
  434.             }
  435.             ksort($values[$name]);
  436.         }   
  437.  
  438.         ksort($values);
  439.  
  440.         return $values;
  441.     }
  442.  
  443.     /**
  444.      * Returns PHP information as an array.
  445.      * 
  446.      * @return  array An array of php information
  447.      * @since V2.1.0 - 2 apr 2007
  448.      */
  449.     public static function phpInfoAsArray()
  450.     {
  451.         $values = array(
  452.             'php'        => phpversion(),
  453.             'os'         => php_uname(),
  454.             'extensions' => get_loaded_extensions(),
  455.         );
  456.  
  457.         // assign extension version if available
  458.         if ($values['extensions']{
  459.             foreach ($values['extensions'as $lkey => $extension{
  460.                 $values['extensions'][$lkeyphpversion($extension$extension
  461.                     ' ('phpversion($extension)')' $extension;
  462.             }
  463.         }
  464.  
  465.         return $values;
  466.     }
  467.  
  468.     /**
  469.      * Add the process time information to the debug information
  470.      * 
  471.      * @since V2.0.0 - 18 Apr 2006
  472.      */ 
  473.     protected function showProcessTime($debugInfos)
  474.     {
  475.         // Lang
  476.         $txtExecutionTime 'Global execution time ';
  477.         $txtPHP           'PHP';
  478.         $txtSQL           'SQL';              
  479.         $txtSECOND        's';
  480.         $txtOneQry        ' query';
  481.         $txtMultQry       ' queries';
  482.         $queryCount       $this->DebugObject->getQueryCount();
  483.         $txtQuery         $queryCount > 1 ? $txtMultQry $txtOneQry;
  484.         $buffer           '';
  485.  
  486.         // Performance Debug
  487.         $processTime $this->DebugObject->getProcessTime();
  488.         $sqlTime    $this->DebugObject->getQueryTime();
  489.         $phpTime    $processTime $sqlTime;
  490.     
  491.         $sqlPercent round(($sqlTime $processTime* 1002);                              
  492.         $phpPercent round(($phpTime $processTime* 1002);
  493.  
  494.         $processTime $processTime*1000;
  495.         $sqlTime    $sqlTime*1000;
  496.         $phpTime    $phpTime*1000;
  497.         
  498.         if ($debugInfos{
  499.             $buffer .= '
  500.             <tr>
  501.                 <th>message</th>
  502.                 <th>time (ms)</th>
  503.                 <th>percent</th>
  504.             </tr>'CR;
  505.  
  506.             foreach($debugInfos as $debugInfo{
  507.                 $properties $debugInfo->getProperties();
  508.                 if ($properties['startTime'&& $properties['endTime']{
  509.  
  510.                     $localPercent round((($properties['endTime'
  511.                         $properties['startTime'])*1000 / $processTime* 1002);
  512.                     $buffer .= '
  513.                     <tr>
  514.                         <td class="sfWebDebugLogMessagePerf">'$this->ProcessDebugInfo($properties)'</td>
  515.                         <td style="text-align: right">'$this->ProcessExecTime($properties)'</td>
  516.                         <td style="text-align: right">'$localPercent'%</td>
  517.                     </tr>'CR;
  518.                 }
  519.             }
  520.         }
  521.  
  522.         return str_replace(
  523.             array(
  524.                 '{$txtExecutionTime}',
  525.                 '{$processTime}',
  526.                 '{$txtPHP}',
  527.                 '{$phpTime}',
  528.                 '{$phpPercent}',
  529.                 '{$txtSQL}',
  530.                 '{$sqlTime}',
  531.                 '{$sqlPercent}',
  532.                 '{$queryCount}',
  533.                 '{$txtQuery}',
  534.                 '{$buffer}'
  535.                 
  536.             ),
  537.             array(
  538.                 $txtExecutionTime,
  539.                 $processTime,
  540.                 $txtPHP,
  541.                 $phpTime,
  542.                 $phpPercent,
  543.                 $txtSQL,
  544.                 $sqlTime,
  545.                 $sqlPercent,
  546.                 $queryCount,
  547.                 $txtQuery,
  548.                 $buffer
  549.             ),
  550.             $this->options['HTML_DIV_sfWebDebugTimeDetails']       
  551.         );
  552.     }
  553.  
  554.     /**
  555.      * Default render function for HTML_Div renderer
  556.      *
  557.      * @since V2.0.0 - 11 Apr 2006
  558.      * @see Renderer
  559.      */
  560.     public function render()
  561.     {
  562.         return $this->display();
  563.     }
  564.  
  565.     /**
  566.      * Displays the header of the PHP_Debug object
  567.      *
  568.      * @since V2.0.0 - 08 Apr 2006
  569.      * @see PHP_Debug
  570.      */
  571.     protected function displayHeader()
  572.     {
  573.         return str_replace(
  574.             array(
  575.                 '{$nb_queries}'
  576.                 '{$exec_time}',
  577.                 '{$imagesPath}',
  578.                 '{$phpDebugVersion}'
  579.             ),
  580.             array(
  581.                 $this->DebugObject->getQueryCount()
  582.                 $this->DebugObject->getProcessTime(* 1000,
  583.                 $this->options['HTML_DIV_images_path'],
  584.                 PHP_Debug::PEAR_RELEASE
  585.             ),        
  586.             $this->options['HTML_DIV_header']);  
  587.     }        
  588.  
  589.     /**
  590.      * Diplays the footer of the PHP_Debug object
  591.      *
  592.      * @since V2.0.0 - 08 Apr 2006
  593.      * @see PHP_Debug
  594.      */
  595.     protected function displayFooter()
  596.     {
  597.         return $this->options['HTML_DIV_footer'];
  598.     }        
  599.     
  600.     /**
  601.      * process display of the execution time of debug information
  602.      * 
  603.      * @param array $properties Properties of the debug line
  604.      * @return string Formatted string containing the main debug info
  605.      * @since V2.0.0 - 28 Apr 2006
  606.      */ 
  607.     protected function processExecTime($properties)
  608.     {   
  609.         // Lang
  610.         $txtPHP 'PHP';
  611.         $txtSQL 'SQL';
  612.         $txtSECOND 's';
  613.  
  614.         if (!empty($properties['endTime'])) {
  615.  
  616.             $time round(PHP_Debug::getElapsedTime(
  617.                 $properties['startTime']
  618.                 $properties['endTime']
  619.             * 1000);
  620.  
  621.             $buffer $this->span($time > 1 ? $time' ms' '&lt; 1 ms''time');
  622.  
  623.         else {
  624.             $buffer '&nbsp;';
  625.         }
  626.  
  627.         return $buffer
  628.     }
  629.     
  630.     /**
  631.      * process display of the main information of debug
  632.      * 
  633.      * @param array $properties Properties of the debug line
  634.      * @return string Formatted string containing the main debug info
  635.      * @since V2.0.0 - 28 Apr 2006
  636.      */ 
  637.     protected function processDebugInfo($properties)
  638.     {   
  639.         $buffer '';
  640.  
  641.         switch($properties['type']{
  642.  
  643.             // Case for each of the debug lines types
  644.             // 1 : Standard
  645.             case PHP_DebugLine::TYPE_STD:
  646.                 $buffer .= $this->span($properties['info']'std');
  647.                 break;
  648.             
  649.             // 2 : Query
  650.             case PHP_DebugLine::TYPE_QUERY:
  651.                 $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/'
  652.                     '<span class="sfWebDebugLogInfo">\\1</span>'
  653.                     $properties['info']);
  654.                 break;
  655.  
  656.             // 3 : Query related
  657.             case PHP_DebugLine::TYPE_QUERYREL:
  658.                 $buffer .= $this->span($properties['info']'query');
  659.                 break;
  660.                 
  661.             // 4 : Environment
  662.             case PHP_DebugLine::TYPE_ENV:
  663.                 $buffer .= $this->showSuperArray($properties['info']);
  664.                 break;
  665.  
  666.             // 6 : User app error
  667.             case PHP_DebugLine::TYPE_APPERROR:
  668.                 $buffer .= $this->span('/!\\ User error : '
  669.                     $properties['info']' /!\\''app-error');
  670.                 break;
  671.                 
  672.             // 7
  673.             case PHP_DebugLine::TYPE_CREDITS:
  674.                 $buffer .= $this->span($properties['info']'credits');            
  675.                 break;
  676.  
  677.             // 9
  678.             case PHP_DebugLine::TYPE_DUMP:
  679.                 $buffer .= $this->showDump($properties);
  680.                 break;
  681.  
  682.             // 10
  683.             case PHP_DebugLine::TYPE_PROCESSPERF:
  684.                 $buffer .= $this->showProcessTime();
  685.                 break;
  686.  
  687.             // 12 : Main Page Action
  688.             case PHP_DebugLine::TYPE_PAGEACTION;
  689.                 $buffer .= $this->span('[Action : '
  690.                     $properties['info']']''pageaction');
  691.                 break;
  692.  
  693.             // 14 : SQL parse 
  694.             case PHP_DebugLine::TYPE_SQLPARSE:
  695.                 $buffer .= $properties['info'];
  696.                 break;
  697.  
  698.             // 15 : Watches
  699.             case PHP_DebugLine::TYPE_WATCH:
  700.                 $infos $properties['info'];
  701.                 $buffer .= 'Variable '$this->span($infos[0]'watch').
  702.                            ' changed from value '
  703.                             $this->span($infos[1]'watch-val')' ('gettype($infos[1])
  704.                             ') to value '$this->span($infos[2]'watch-val')
  705.                             ' ('gettype($infos[2])')';
  706.                 break;
  707.  
  708.             // 16 : PHP errors
  709.             case PHP_DebugLine::TYPE_PHPERROR:                
  710.                 $buffer .= $this->showError($properties['info']);
  711.                 break;
  712.  
  713.             default:
  714.                 $buffer .= '<b>Default('$properties['type'].
  715.                            ')</b>: TO IMPLEMENT OR TO CORRECT : &gt;'
  716.                            $properties['info']'&lt;';
  717.                 break;
  718.         }
  719.  
  720.         return $buffer;
  721.     }
  722.  
  723.     /**
  724.      * Return a string with applying a span style on it
  725.      * 
  726.      * @param string $info String to apply the style
  727.      * @param string $class CSS style to apply to the string
  728.      * @return string Formatted string with style applied
  729.      * @since V2.0.0 - 05 May 2006
  730.      */ 
  731.     protected function span($info$class)
  732.     {   
  733.         return '<span class="'$class .'">'$info .'</span>'
  734.     }
  735.  
  736.     /**
  737.      * process display of the type of the debug information
  738.      * 
  739.      * @param array $properties Properties of the debug line
  740.      * @return string Formatted string containing the debug type
  741.      * @since V2.0.0 - 26 Apr 2006
  742.      */ 
  743.     protected function processType($properties)
  744.     {   
  745.         $buffer PHP_DebugLine::$debugLineLabels[$properties['type']];
  746.         return $buffer;
  747.     }
  748.  
  749.     /**
  750.      * process display of Class
  751.      * 
  752.      * @param array $properties Properties of the debug line
  753.      * @return string Formatted string containing the class
  754.      * @since V2.0.0 - 26 Apr 2006
  755.      */ 
  756.     protected function processClass($properties)
  757.     {
  758.         $buffer '';
  759.  
  760.         switch ($properties['type'])
  761.         {
  762.             case PHP_DebugLine::TYPE_STD:
  763.             case PHP_DebugLine::TYPE_QUERY:
  764.             case PHP_DebugLine::TYPE_QUERYREL:
  765.             case PHP_DebugLine::TYPE_APPERROR:             
  766.             case PHP_DebugLine::TYPE_PAGEACTION:
  767.             case PHP_DebugLine::TYPE_PHPERROR:
  768.             case PHP_DebugLine::TYPE_SQLPARSE:
  769.             case PHP_DebugLine::TYPE_WATCH:
  770.             case PHP_DebugLine::TYPE_DUMP:
  771.                         
  772.                 if (!empty($properties['class'])) {
  773.                     $buffer .= $properties['class'];
  774.                 else {
  775.                     $buffer .= '&nbsp;';
  776.                 }
  777.  
  778.                 break;
  779.                         
  780.             case PHP_DebugLine::TYPE_CREDITS: 
  781.             case PHP_DebugLine::TYPE_SEARCH:
  782.             case PHP_DebugLine::TYPE_PROCESSPERF:
  783.             case PHP_DebugLine::TYPE_TEMPLATES:
  784.             case PHP_DebugLine::TYPE_ENV:
  785.  
  786.                 $buffer .= '&nbsp;';
  787.  
  788.                 break;
  789.         
  790.             default:
  791.                 break;
  792.         }
  793.         
  794.         return $buffer;
  795.     }
  796.  
  797.     /**
  798.      * process display of function
  799.      * 
  800.      * @param array $properties Properties of the debug line
  801.      * @return string Formatted string containing the function
  802.      * @since V2.0.0 - 26 Apr 2006
  803.      */ 
  804.     protected function processFunction($properties)
  805.     {
  806.         $buffer '';
  807.  
  808.         switch ($properties['type'])
  809.         {
  810.             case PHP_DebugLine::TYPE_STD:
  811.             case PHP_DebugLine::TYPE_QUERY:
  812.             case PHP_DebugLine::TYPE_QUERYREL:
  813.             case PHP_DebugLine::TYPE_APPERROR:             
  814.             case PHP_DebugLine::TYPE_PAGEACTION:
  815.             case PHP_DebugLine::TYPE_PHPERROR:
  816.             case PHP_DebugLine::TYPE_SQLPARSE:
  817.             case PHP_DebugLine::TYPE_WATCH:
  818.             case PHP_DebugLine::TYPE_DUMP:
  819.                         
  820.                 if (!empty($properties['function'])) {                    
  821.                     if ($properties['function'!= 'unknown'
  822.                         $buffer .= $properties['function']'()';
  823.                     else {
  824.                         $buffer .= '&nbsp;';
  825.                 }
  826.                 else {
  827.                     $buffer .= '&nbsp;';
  828.                 }
  829.  
  830.                 break;
  831.                         
  832.             case PHP_DebugLine::TYPE_CREDITS: 
  833.             case PHP_DebugLine::TYPE_SEARCH:
  834.             case PHP_DebugLine::TYPE_PROCESSPERF:
  835.             case PHP_DebugLine::TYPE_TEMPLATES:
  836.             case PHP_DebugLine::TYPE_ENV:
  837.  
  838.                 $buffer .= '&nbsp;';
  839.                 break;
  840.         
  841.             default:
  842.                 break;
  843.         }
  844.         
  845.         return $buffer;
  846.     }
  847.  
  848.  
  849.     /**
  850.      * process display of line number
  851.      * 
  852.      * @param array $properties Properties of the debug line
  853.      * @return string Formatted string containing the line number
  854.      * @since V2.0.0 - 26 Apr 2006
  855.      */ 
  856.     protected function processLine($properties)
  857.     {
  858.         $buffer '';
  859.  
  860.         switch ($properties['type'])
  861.         {
  862.             case PHP_DebugLine::TYPE_STD:
  863.             case PHP_DebugLine::TYPE_QUERY:
  864.             case PHP_DebugLine::TYPE_QUERYREL:
  865.             case PHP_DebugLine::TYPE_APPERROR:             
  866.             case PHP_DebugLine::TYPE_PAGEACTION:
  867.             case PHP_DebugLine::TYPE_PHPERROR:
  868.             case PHP_DebugLine::TYPE_SQLPARSE:
  869.             case PHP_DebugLine::TYPE_WATCH:
  870.             case PHP_DebugLine::TYPE_DUMP:
  871.                         
  872.                 if (!empty($properties['line'])) {
  873.                     $buffer.= '<span class="line">'
  874.                         $properties['line']'</span>';
  875.                 else {
  876.                     $buffer.= '&nbsp;';
  877.                 }        
  878.  
  879.                 break;
  880.                         
  881.             case PHP_DebugLine::TYPE_CREDITS: 
  882.             case PHP_DebugLine::TYPE_SEARCH:
  883.             case PHP_DebugLine::TYPE_PROCESSPERF:
  884.             case PHP_DebugLine::TYPE_TEMPLATES:
  885.             case PHP_DebugLine::TYPE_ENV:
  886.  
  887.                 $buffer.= '&nbsp;';
  888.  
  889.                 break;
  890.         
  891.             default:
  892.                 break;
  893.         }
  894.         
  895.         return $buffer;
  896.     }
  897.  
  898.     /**
  899.      * process display of file name
  900.      * 
  901.      * @param array $properties Properties of the debug line
  902.      * @return string Formatted string containing the file
  903.      * @since V2.0.0 - 26 Apr 2006
  904.      */ 
  905.     protected function processFile($properties)
  906.     {
  907.         $buffer '';
  908.  
  909.         switch ($properties['type'])
  910.         {
  911.             case PHP_DebugLine::TYPE_STD:
  912.             case PHP_DebugLine::TYPE_QUERY:
  913.             case PHP_DebugLine::TYPE_QUERYREL:
  914.             case PHP_DebugLine::TYPE_APPERROR:             
  915.             case PHP_DebugLine::TYPE_PAGEACTION:
  916.             case PHP_DebugLine::TYPE_PHPERROR:
  917.             case PHP_DebugLine::TYPE_SQLPARSE:
  918.             case PHP_DebugLine::TYPE_WATCH:
  919.             case PHP_DebugLine::TYPE_DUMP:
  920.  
  921.                 if (!empty($properties['file'])) {
  922.                     if (!empty($this->options['HTML_DIV_view_source_script_path']&& 
  923.                         !empty($this->options['HTML_DIV_view_source_script_name'])) {
  924.                         $buffer .= '<a href="'
  925.                                 $this->options['HTML_DIV_view_source_script_path'].
  926.                                 '/'
  927.                                 $this->options['HTML_DIV_view_source_script_name'].  
  928.                                 '?file='urlencode($properties['file']);
  929.  
  930.                         $buffer .= '">'basename($properties['file'])'</a>'
  931.  
  932.                     else {
  933.                         $buffer .= basename($properties['file']);                        
  934.                     }
  935.                 else {
  936.                     $buffer .=  '&nbsp;';
  937.                 }        
  938.         
  939.                 break;
  940.                         
  941.             case PHP_DebugLine::TYPE_CREDITS: 
  942.             case PHP_DebugLine::TYPE_SEARCH:
  943.             case PHP_DebugLine::TYPE_PROCESSPERF:
  944.             case PHP_DebugLine::TYPE_TEMPLATES:
  945.             case PHP_DebugLine::TYPE_ENV:
  946.  
  947.                 $buffer .=  '&nbsp;';
  948.  
  949.                 break;
  950.         
  951.             default:
  952.                 break;
  953.         }
  954.         
  955.         return $buffer;
  956.     }
  957.  
  958.     /**
  959.      * Dump of a variable
  960.      * 
  961.      * @since V2.0.0 - 26 Apr 2006
  962.      */ 
  963.     protected function showDump($properties)
  964.     {
  965.         $buffer '';
  966.  
  967.         // Check display with a <pre> design
  968.         if (is_array($properties['info'][1])) {
  969.             $preDisplay = true;                      
  970.         elseif (is_object($properties['info'][1])) {
  971.             $preDisplay = true;                      
  972.         else {
  973.             $preDisplay = false;                      
  974.         }
  975.  
  976.         // Check var name
  977.         if (empty($properties['info'][0])) {
  978.             if (is_array($properties['info'][1])) {
  979.                 $varName 'Array';
  980.             elseif (is_object($properties['info'][1])) {
  981.                 $varName get_class($properties['info'][1]);
  982.             else {
  983.                 $varName 'Variable';                              
  984.             }
  985.         else {
  986.             $varName $properties['info'][0];
  987.         }
  988.         
  989.         // Output
  990.         if ($properties['type'!= PHP_DebugLine::TYPE_ENV
  991.             $title 'dump of \'';
  992.         
  993.         
  994.         $title .= $varName'\' ('.  gettype($properties['info'][1].') : ';
  995.         
  996.         $buffer .= $this->span($title 'dump-title');
  997.         
  998.         if ($preDisplay == true){
  999.             $buffer .= '<pre>';                   
  1000.             $buffer .= PHP_Debug::dumpVar(
  1001.                 $properties['info'][1]
  1002.                 ''
  1003.                 false
  1004.                 PHP_Debug::DUMP_STR);
  1005.         else {
  1006.             $buffer .= $this->span(
  1007.                 PHP_Debug::dumpVar(
  1008.                     $properties['info'][1]
  1009.                     ''
  1010.                     false
  1011.                     PHP_Debug::DUMP_STR
  1012.                 )'dump-val');
  1013.         }
  1014.  
  1015.         if ($preDisplay == true{
  1016.             $buffer .= '</pre>';                  
  1017.         }
  1018.  
  1019.         return $buffer;
  1020.     }
  1021.  
  1022.     /**
  1023.      * Get the templates info
  1024.      * 
  1025.      * @since V2.0.0 - 26 Apr 2006
  1026.      */ 
  1027.     protected function showTemplates()
  1028.     {
  1029.         $txtMainFile 'MAIN File';
  1030.         $idx = 1;
  1031.         $buffer '<br />';
  1032.  
  1033.         foreach($this->DebugObject->getRequiredFiles(as $lvalue{
  1034.             
  1035.             $isToDisplay = true;
  1036.  
  1037.             if ($this->options['HTML_DIV_view_source_excluded_template']{            
  1038.                 foreach ($this->options['HTML_DIV_view_source_excluded_template'as $template{                
  1039.                     if (stristr($lvalue$template)) {
  1040.                         $isToDisplay = false;
  1041.                     }
  1042.                 }
  1043.             }
  1044.  
  1045.             if ($isToDisplay == true{
  1046.  
  1047.                 $buffer .= '<div class="source">';
  1048.                 $buffer .= $this->span($this->truncate($lvalue)'files');
  1049.                 $buffer .= ' <a href="'
  1050.                              $this->options['HTML_DIV_view_source_script_path'].
  1051.                              '/'$this->options['HTML_DIV_view_source_script_name'].  
  1052.                              '?file='urlencode($lvalue)'">View source</a> ';
  1053.                     
  1054.                 // main file    
  1055.                 if ($idx == 1{
  1056.                     $buffer .= $this->span('&laquo; '$txtMainFile'main-file');
  1057.                 }                       
  1058.                 $idx++;
  1059.                 $buffer .= '</div><br />'CR;
  1060.             }            
  1061.         }        
  1062.  
  1063.         $buffer .= '<br />'CR;
  1064.         return $buffer
  1065.     }
  1066.     
  1067.     
  1068.     /**
  1069.      * Truncate/replace a pattern from the file path
  1070.      * 
  1071.      * @param string full file path
  1072.      * 
  1073.      * @author COil
  1074.      * @since V2.1.0 - 3 apr 2007
  1075.      * 
  1076.      * @see
  1077.      *  - HTML_DIV_remove_templates_pattern
  1078.      *  - HTML_DIV_templates_pattern
  1079.      */
  1080.     protected function truncate($file)
  1081.     {
  1082.         if ($this->options['HTML_DIV_remove_templates_pattern'&& 
  1083.             $this->options['HTML_DIV_templates_pattern']{
  1084.             return strtr($file$this->options['HTML_DIV_templates_pattern']);
  1085.         
  1086.  
  1087.         return $file;
  1088.     }
  1089.     
  1090.     /**
  1091.      * Process an error info
  1092.      * 
  1093.      * @param array $info Array containing information about the error
  1094.      * 
  1095.      * @since V2.0.0 - 25 Apr 2006
  1096.      * @see PHP_DebugLine::TYPE_PHPERROR
  1097.      */ 
  1098.     protected function showError($infos)    
  1099.     {
  1100.         $buffer '';
  1101.         $infos[1str_replace("'"'"'$infos[1]);
  1102.         $infos[1str_replace(
  1103.             'href="function.'
  1104.             ' href="http://www.php.net/'
  1105.             $this->options['lang']'/'$infos[1]);
  1106.  
  1107.         switch ($infos[0])
  1108.         {
  1109.             case E_WARNING:
  1110.                 $errorlevel 'PHP WARNING : ';
  1111.                 $buffer .= '<span class="pd-php-warning"> /!\\ '
  1112.                     $errorlevel$infos[1' /!\\ </span>';                
  1113.                 break;
  1114.  
  1115.             case E_NOTICE:
  1116.                 $errorlevel 'PHP notice : ';
  1117.                 $buffer .= '<span class="pd-php-notice">'
  1118.                     $errorlevel$infos[1'</span>';
  1119.                 break;
  1120.  
  1121.             case E_USER_ERROR:
  1122.                 $errorlevel 'PHP User error : ';
  1123.                 $buffer .= '<span class="pd-php-user-error"> /!\\ '
  1124.                     $errorlevel$infos[1' /!\\ </span>';
  1125.                 break;
  1126.  
  1127.             case E_STRICT:
  1128.                 
  1129.                 $errorlevel 'PHP STRICT error : ';
  1130.                 $buffer .= '<span class="pd-php-user-error"> /!\\ '
  1131.                     $errorlevel$infos[1' /!\\ </span>';
  1132.                 break;
  1133.  
  1134.             default:
  1135.                 $errorlevel 'PHP errorlevel = '$infos[0]' : ';
  1136.                 $buffer .= $errorlevel
  1137.                     ' is not implemented in PHP_Debug ('. __FILE__. ','. __LINE__. ')';
  1138.                 break;
  1139.         }
  1140.         
  1141.         return $buffer;
  1142.     }
  1143.  
  1144.     /**
  1145.      * Show a super array
  1146.      * 
  1147.      * @param string $SuperArrayType Type of super en array to add
  1148.      * @since V2.0.0 - 07 Apr 2006
  1149.      */ 
  1150.     protected function showSuperArray($SuperArrayType)    
  1151.     {
  1152.         // Lang
  1153.         $txtVariable   'Var';
  1154.         $txtNoVariable 'NO VARIABLE';
  1155.         $NoVariable    ' -- '$txtNoVariable' -- ';
  1156.         $SuperArray    = null;
  1157.         $buffer        '';
  1158.  
  1159.         $ArrayTitle = PHP_Debug::$globalEnvConstantsCorresp[$SuperArrayType];
  1160.         $SuperArray $GLOBALS[$ArrayTitle];
  1161.         $Title $ArrayTitle' '$txtVariable;
  1162.         $SectionBasetitle '<b>'$Title'('. count($SuperArray)') :';
  1163.  
  1164.         if (count($SuperArray)) {
  1165.             $buffer .= $SectionBasetitle'</b>';
  1166.             $buffer .= '<pre>'
  1167.                 PHP_Debug::dumpVar(
  1168.                     $SuperArray
  1169.                     $ArrayTitle
  1170.                     false
  1171.                     PHP_Debug::DUMP_STR
  1172.                     )'</pre>';
  1173.         else {
  1174.             $buffer .= $SectionBasetitle$NoVariable'</b>';
  1175.         }
  1176.         
  1177.         return $buffer;
  1178.     }
  1179.  
  1180.     /**
  1181.      * Show a super array
  1182.      * 
  1183.      * @param string $SuperArrayType Type of super en array to add
  1184.      * @since V2.0.0 - 07 Apr 2006
  1185.      */ 
  1186.     protected function showArray($array$name)    
  1187.     {
  1188.         // Lang
  1189.         $txtNoVariable 'NO VARIABLE';
  1190.         $NoVariable    ' -- '$txtNoVariable' -- ';
  1191.         $buffer        '';
  1192.         $SectionBasetitle '<b>'$name'('count($array)') :';
  1193.  
  1194.         if (count($array)) {
  1195.             $buffer .= $SectionBasetitle'</b>';
  1196.             $buffer .= '<pre>'. PHP_Debug::dumpVar(
  1197.                 $array
  1198.                 $name
  1199.                 false
  1200.                 PHP_Debug::DUMP_STR)'</pre>';
  1201.         else {
  1202.             $buffer .= $SectionBasetitle$NoVariable'</b>';
  1203.         }
  1204.         
  1205.         return $buffer;
  1206.     }
  1207.  
  1208. }

Documentation generated on Mon, 11 Mar 2019 15:25:20 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.