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

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