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

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