NewsFeaturesDownloadsDevelopmentSupportAbout Us

lifetype/branches/lifetype-1.0.6/debug.php

Go to the documentation of this file.
00001 <?php
00002 
00003         include_once( PLOG_CLASS_PATH."class/logger/loggermanager.class.php" );
00004 
00015         define( "DEBUG_ENABLED", true );
00016         
00017         function _debug( $params )
00018         {
00019                 $log = LoggerManager::getLogger();
00020                 $log->debug( $params );
00021         }
00022 
00023         function __debug( $params )
00024     {
00025         if( DEBUG_ENABLED ) {
00026                         if( function_exists("debug_backtrace")) {
00027                         $info = debug_backtrace();
00028                 $last = $info[0];
00029                                 $line = $last["file"].":".$last["line"];
00030                                 if( is_array($params) || is_object($params)) {
00031                                         print($line.":");
00032                                         print table_var_dump($params);
00033                                         print("<br/>");
00034                                 }
00035                                 else 
00036                                         print($line.":".$params."<br/>");
00037                 }
00038             else {
00039                 print($params."<br/>");
00040             }
00041         }
00042 
00043         return true;
00044     }
00045         
00050 
00051 
00052         //        available at http://www.silisoftware.com          ///
00054         //                                                           //
00055         // Requires:                                                 //
00056         //   PHP 3.0.7 (or higher)                                   //
00057         //                                                           //
00058         //                                                           //
00059         //         This code is released under the GNU GPL:          //
00060         //           http://www.gnu.org/copyleft/gpl.html            //
00061         //                                                           //
00062         //      +---------------------------------------------+      //
00063         //      | If you do use this code somewhere, send me  |      //
00064         //      | an email and tell me how/where you used it. |      //
00065         //      +---------------------------------------------+      //
00066         //                                                           //
00069         // v1.0.1 - September 19, 2003                               //
00070         //   * Bugfix: included missing string_var_dump() function   //
00071         //     (thanks Andrei Verovski)                              //
00072         //                                                           //
00073         // v1.0.0 - May 8, 2003                                      //
00074         //   * initial public release                                //
00075         //                                                          ///
00077 
00078         function table_var_dump($variable) {
00079                 $returnstring = '';
00080                 switch (gettype($variable)) {
00081                         case 'array':
00082                                 $returnstring .= '<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="2">';
00083                                 foreach ($variable as $key => $value) {
00084                                         $returnstring .= '<TR><TD VALIGN="TOP"><B>'.str_replace("\x00", ' ', $key).'</B></TD>';
00085                                         $returnstring .= '<TD VALIGN="TOP">'.gettype($value);
00086                                         if (is_array($value)) {
00087                                                 $returnstring .= '&nbsp;('.count($value).')';
00088                                         } elseif (is_string($value)) {
00089                                                 $returnstring .= '&nbsp;('.strlen($value).')';
00090                                         }
00091                                         $returnstring .= '</TD><TD>'.table_var_dump($value).'</TD></TR>';
00092                                 }
00093                                 $returnstring .= '</TABLE>';
00094                                 break;
00095 
00096                         case 'boolean':
00097                                 $returnstring .= ($variable ? 'TRUE' : 'FALSE');
00098                                 break;
00099 
00100                         case 'integer':
00101                         case 'double':
00102                         case 'float':
00103                                 $returnstring .= $variable;
00104                                 break;
00105 
00106                         case 'object':
00107                         case 'null':
00108                                 $returnstring .= string_var_dump($variable);
00109                                 break;
00110 
00111                         case 'string':
00112                                 $variable = str_replace("\x00", ' ', $variable);
00113                                 $varlen = strlen($variable);
00114                                 for ($i = 0; $i < $varlen; $i++) {
00115                                         if (ereg('['.chr(0x0A).chr(0x0D).' -;0-9A-Za-z]', $variable{$i})) {
00116                                                 $returnstring .= $variable{$i};
00117                                         } else {
00118                                                 $returnstring .= '&#'.str_pad(ord($variable{$i}), 3, '0', STR_PAD_LEFT).';';
00119                                         }
00120                                 }
00121                                 $returnstring = nl2br($returnstring);
00122                                 break;
00123 
00124                         default:
00125                                 $returnstring .= nl2br(htmlspecialchars(str_replace("\x00", ' ', $variable)));
00126                                 break;
00127                 }
00128                 return $returnstring;
00129         }
00130 
00131 
00132         function string_var_dump($variable) {
00133                 ob_start();
00134                 var_dump($variable);
00135                 $dumpedvariable = ob_get_contents();
00136                 ob_end_clean();
00137                 return $dumpedvariable;
00138         }       
00139 ?>