<?php class Debugger{ var $start; var $last; function &getInstance($time = null){ $instance = new Debugger($time); $instance->AddLog('Init - (created instance of Debbuger)'); } return $instance; } function Debugger($time = null){ if($time == null){ } '_POST' => $_POST, '_GET' => $_GET, '_SESSION' => $_SESSION, '_FILES' => $_FILES, '_COOKIE' => $_COOKIE, ); $this->start = $time; $this->last = $time; } function AddQuery($query){ $this->queries[] = $query; } function AddVar(&$var, $name){ $this->toDebug[$name] =& $var; } function AddLog($Value, $die = false){ $add->from_start = number_format(((substr($time,0,9)) + (substr($time,-10)) - (substr($this->start,0,9)) - (substr($this->start,-10))),4); $add->from_last = number_format(((substr($time,0,9)) + (substr($time,-10)) - (substr($this->last,0,9)) - (substr($this->last,-10))),4); $add->value = $Value; $this->logs[] = $add; $this->last = $time; if($die == true){ } return $add; } function ShowLogs(){ $this =& Debugger::getInstance(); ?> <script type="text/javascript"> <!-- function deb_SetCookie(cookieName,cookieValue,nDays) { var today = new Date(); var expire = new Date(); if (nDays==null || nDays==0) nDays=1; expire.setTime(today.getTime() + 3600000*24*nDays); document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString(); } function deb_myGetCookie(name) { if (document.cookie) { var cookies=document.cookie.split(";"); for (var i=0; i<cookies.length; i++) { var varName=(cookies[i].split("=")[0]); var varValue=(cookies[i].split("=")[1]); while (varName.charAt(0)==" ") varName=varName.substr(1,varName.length); // the escape() function will url encode the value if (varName==name) return escape(varValue); } } return 'block'; } function deb_switch(id){ if(document.getElementById('deb_'+id).style.display == 'none'){ document.getElementById('deb_'+id).style.display = 'block'; deb_SetCookie('deb_state_'+id, 'block'); } else{ document.getElementById('deb_'+id).style.display = 'none'; deb_SetCookie('deb_state_' + id, 'none'); } } --> </script> <? echo ' <div style="width: 780px; margin: auto; clear: both; border: 1px solid black; margin: 1
0px; font-family: tahoma; font-size: 11px;">'; foreach ($this->toDebug as $key=>$val){ echo ' <div style="font-weight: bold; background-color: #4C71EA; border-bottom: 1px solid #090064; padding: 2px;"> <div style="float: right;"><a style="color: black; font-weight: bold; font-size: 13px;text-decoration: none;" href="#" onclick="deb_switch(''.$key.'');return false;"><div style="width: 50px; background-color: black; text-align: center; color: white; font-weight: normal;">rozwin</div></a></div> $'.$key.' </div> } echo' <div style="font-weight: bold; background-color: #4C71EA; border-bottom: 1px solid #090064; border-top: 1px solid #090064; padding: 2px;"> <div style="float: right;"><a style="color: black; font-weight: bold; font-size: 13px;text-decoration: none;" href="#" onclick="deb_switch('queries');return false;"><div style="width: 50px; background-color: black; text-align: center; color: white; font-weight: normal;">rozwin</div></a></div> Queries</div> <div id="deb_queries"> <table style="width: 100%; font-family: tahoma; font-size: 11px;"> <tr style="text-align: left;"><th>Query<th>Execution time<th>num_rows<th>affected_rows'; echo '<tr '.($key%2==0?'style="background-color:#efefef;"':'').'><td>'.$val->query.'<td>'.$val->time.'<td>'.$val->num_rows.'<td>'.$val->affected_rows; } echo '</table> </div> <div style="font-weight: bold; background-color: #4C71EA; border-bottom: 1px solid #090064; border-top: 1px solid #090064; padding: 2px;"> <div style="float: right;"><a style="color: black; font-weight: bold; font-size: 13px;text-decoration: none;" href="#" onclick="deb_switch('db_msg');return false;"><div style="width: 50px; background-color: black; text-align: center; color: white; font-weight: normal;">rozwin</div></a></div>DEBUGER MESSAGES</div> <div id="deb_db_msg"> <table style="width: 100%; font-family: tahoma; font-size: 11px;"> <tr style="text-align: left;"><th>From start<th>From last<th>Message '; echo '<tr '.($key%2==0?'style="background-color:#efefef;"':'').'><td>'.$val->from_start.'<td>'.$val->from_last.'<td>'.$val->value; } echo ' </table> </div> <div style="font-weight: bold; background-color: #4C71EA; border-top: 1px solid #090064; padding: 2px;">Total execution time: '.number_format(((substr($time,0,9)) + (substr($time,-10)) - (substr($this->start,0,9)) - (substr($this->start,-10))),4).'</div> </div> '; ?> <script type="text/javascript"> <!-- document.getElementById('deb_queries').style.display = deb_myGetCookie('deb_state_queries'); document.getElementById('deb_db_msg').style.display = deb_myGetCookie('deb_state_db_msg'); <? foreach ($this->toDebug as $key=>$val){ } ?> --> </script> <? } function SaveLogs(){ $this =& Debugger::getInstance(); return false; } // write logs todo } function Destroy(){ $this =& Debugger::getInstance(); $this->AddLog('Application ended'); if(DEBUG & DT_SHOW){ Debugger::ShowLogs(); } if(DEBUG & DT_LOG){ Debugger::SaveLogs(); } } } ?>
kod oczywiscie nieudokumentowany zbytnio (my style

obiekt $query wysylany przed AddQuery u mnie w db layerze wyglada tak:
<?php $q->query = $this->query; $q->time = number_format(((substr($after,0,9)) + (substr($after,-10)) - (substr($before,0,9)) - (substr($before,-10))),4); ?>
zeby kazdy wiedzial ocobe proponuje pobawic sie guzikiem 'odswie¿' przegl±darki