00001 <?php
00002
00003 class CorujaDebug
00004 {
00011 private function privateXMLEntities($intNum)
00012 {
00013 $chars = array(
00014 128 => '€', 130 => '‚', 131 => 'ƒ', 132 => '„',
00015 133 => '…', 134 => '†', 135 => '‡', 136 => 'ˆ',
00016 137 => '‰', 138 => 'Š', 139 => '‹', 140 => 'Œ',
00017 142 => 'Ž', 145 => '‘', 146 => '’', 147 => '“',
00018 148 => '”', 149 => '•', 150 => '–', 151 => '—',
00019 152 => '˜', 153 => '™', 154 => 'š', 155 => '›',
00020 156 => 'œ', 158 => 'ž', 159 => 'Ÿ'
00021 );
00022 $num = ord($intNum);
00023 return (($intNum > 127 && $intNum < 160) ? $chars[$intNum] : "&#".$intNum.";" );
00024 }
00025
00033 private static function removeRecursiveProblem( $mixExpression )
00034 {
00035 $mixExpression = serialize( $mixExpression );
00036 $arrExpression = explode( ";" , $mixExpression );
00037 foreach( $arrExpression as $intKey => $strExpression )
00038 {
00039 $arrElement = explode( ":" , $strExpression );
00040 if( $arrElement[0] == "r" )
00041 {
00042 $arrElement[0] = "s";
00043 $arrElement[2] = '"<b>*recursive*</b>"';
00044 $arrElement[1] = strlen( $arrElement[2] ) - 2;
00045 }
00046 $arrExpression[ $intKey ] = implode( ":" , $arrElement );
00047 }
00048
00049 $mixExpression = implode( ";" , $arrExpression );
00050 $mixExpression = unserialize( $mixExpression );
00051
00052 $mixExpression = ( var_export( $mixExpression , 1 ) );
00053 $arrClasses = explode( "::" , $mixExpression );
00054
00055 foreach( $arrClasses as $intKey => $strClass )
00056 {
00057 $arrClass = explode( " " , $strClass );
00058 $intLast = sizeof( $arrClass ) - 1;
00059 $arrClass[ $intLast ] = '<b>'. $arrClass[ $intLast ] . '</b>';
00060 $strClass = implode( " " , $arrClass );
00061 $arrClasses[ $intKey ] = $strClass;
00062 }
00063
00064 $mixExpression = implode( "::" , $arrClasses );
00065
00066 return $mixExpression;
00067
00068 }
00069
00070 private static function highlightXml( $strXmlContent , $booCssInLine = true )
00071 {
00072 $booHasHeader = ( ( strpos( $strXmlContent , "<" . "?" . "xml" ) ) !== false );
00073 $strXmlContent = htmlentities( $strXmlContent , true );
00074
00075
00076
00077
00078 if( $booCssInLine )
00079 {
00080 $strStartTagStyle = "color:olive;";
00081 $strNameTagStyle = "color:olive";
00082 $strOutTagStyle = "";
00083 $strInsideTagStyle = "color:black";
00084 $strNextStyle = "color:navy";
00085 $strValueTagStyle = "color:red";
00086 $strNone = "display:none";
00087 $strAttribute = "span style=";
00088 }
00089 else
00090 {
00091 $strStartTagStyle = "start_tag";
00092 $strNameTagStyle = "name_tag";
00093 $strOutTagStyle = "out_tag";
00094 $strInsideTagStyle = "inside_tag";
00095 $strNextStyle = "next_tag";
00096 $strValueTagStyle = "value_tag";
00097 $strNone = "none_tag";
00098 $strAttribute = "span class=";
00099 }
00100
00101 $strXmlContent = str_replace(
00102 Array(
00103 ">?" ,
00104 "?>" ,
00105 "<" ,
00106 "/>" ,
00107 ">" ,
00108 " ",
00109 "=",
00110 "span_style",
00111 ),
00112 Array(
00113 "</span></span><span_style'$strStartTagStyle'\n><<span_style'$strNameTagStyle'><span_style'$strNone'> </span>" ,
00114 "</span>?></span><span_style'$strOutTagStyle'\n><span_style'$strNone'> </span>",
00115
00116 "</span></span><span_style'$strStartTagStyle'\n><<span_style'$strNameTagStyle'><span_style'$strNone'> </span><span><span_style'$strNone'> </span>" ,
00117
00118 "</span>/></span></span></span\n><span_style'$strOutTagStyle'\n><span_style'$strNone'> </span>",
00119
00120 "</span>><span_style'$strInsideTagStyle'><span_style'$strNone'> </span>",
00121
00122 "</span> <span_style'$strNextStyle'><span_style'$strNone'> </span>",
00123
00124 "</span>=<span_style'$strValueTagStyle'><span_style'$strNone'> </span>",
00125 $strAttribute,
00126 ),
00127 $strXmlContent
00128 );
00129
00130 $strXmlContent = "<div class='xml'><span><$strAttribute'$strNone'> </span><span><$strAttribute'$strNone'> </span>" . $strXmlContent;
00131
00132 if( $booHasHeader )
00133 {
00134 $strXmlContent .= '</span></span>';
00135 }
00136 $strXmlContent .= "</span></span></div>";
00137
00138 return $strXmlContent;
00139
00140 }
00141
00148 private static function getBackTraceCaller( $intDeeper = 0 )
00149 {
00150 $arrBackTrace = CorujaArrayManipulation::getArrayField( debug_backtrace() , $intDeeper );
00151 unset( $arrBackTrace[ "object" ] );
00152 return $arrBackTrace;
00153 }
00154
00161 public static function show( $strExpression , $boolExit = FALSE )
00162 {
00163 $arrBacktraceCaller = self::getBackTraceCaller(2);
00164 print $strExpression;
00165 print "\n<!--";
00166 foreach( $arrBacktraceCaller as $strKey => $mixValue )
00167 {
00168 print $strKey . " = " . serialize($mixValue) . "\n";
00169 }
00170 print "--><br/>\n";
00171 }
00172
00179 public static function debug( $mixExpression , $boolExit = FALSE )
00180 {
00181 self::display( self::removeRecursiveProblem( $mixExpression ) ,$boolExit );
00182 }
00183
00190 public static function debugPhpCode( $strPhpExpression, $boolExit = FALSE )
00191 {
00192 if( substr( $strPhpExpression , 0 , 2 ) != "<?" )
00193 {
00194 $strPhpExpression = "<?php \n" . $strPhpExpression;
00195 }
00196 $strPhpExpression = highlight_string( $strPhpExpression , true );
00197 self::display( $strPhpExpression, $boolExit );
00198
00199 }
00200
00207 public static function debugXmlCode( $strXmlExpression, $boolExit = FALSE )
00208 {
00209 $strXmlExpression = preg_replace('/[^\x09\x0A\x0D\x20-\x7F]/e', 'CorujaDebug::privateXMLEntities("$0")', $strXmlExpression);
00210 self::display( self::highlightXml( $strXmlExpression ) , $boolExit );
00211 }
00212
00219 public static function printXmlCode( $strXmlExpression, $boolCssInLine = FALSE, $boolExit = FALSE )
00220 {
00221 $strXmlExpression = preg_replace('/[^\x09\x0A\x0D\x20-\x7F]/e', 'CorujaDebug::privateXMLEntities("$0")', $strXmlExpression);
00222 self::prints( self::highlightXml( $strXmlExpression , $boolCssInLine ) , $boolExit );
00223 }
00224
00231 public static function debugHtmlCode( $strHtmlExpression, $boolExit = FALSE )
00232 {
00233 self::display( self::highlightXml( $strHtmlExpression ) , $boolExit );
00234 }
00235
00243 public static function display( $mixExpression , $boolExit = FALSE)
00244 {
00245 $arrBacktraceCaller = self::getBackTraceCaller(2);
00246 $strMessage = "/*";
00247 $strMessage .= "<fieldset><legend><font color=\"#007000\">debug</font></legend><pre>" ;
00248 foreach( $arrBacktraceCaller as $strAttribute => $mixValue )
00249 {
00250 $strMessage .= "<b>" . $strAttribute . "</b>: ". $mixValue ."\n";
00251 }
00252
00253 $strMessage .= "<div style='background-color: #F0F0F0; float:left'>";
00254 $strMessage .= $mixExpression;
00255 $strMessage .= "</div>";
00256
00257 $strMessage .= "</pre>";
00258 $strMessage .= "</fieldset> */";
00259
00260 print $strMessage;
00261
00262 if( $boolExit )
00263 {
00264 print "<br /><font color=\"#700000\" size=\"4\"><b>D I E</b></font>";
00265
00266 }
00267 }
00268
00276 public static function prints( $mixExpression , $boolExit = FALSE)
00277 {
00278 $strMessage = "";
00279 $strMessage .= $mixExpression;
00280
00281 $strMessage .= "";
00282
00283 print $strMessage;
00284
00285 if( $boolExit )
00286 {
00287 print "<br /><font color=\"#700000\" size=\"4\"><b>D I E</b></font>";
00288 throw new Exception( var_export( $mixExpression , 1 ) );
00289 }
00290 }
00291 }
00292 ?>