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

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