. */ /** * plugin_gestionuser classe de gestion user * @author Mika * @link http://mkf.mkdevs.com/ */ class plugin_debug{ private $iStartMicrotime; private $sHtml; private static $tSpy; private static $tTime; private static $tTimeById; public static $enabled=0; public function __construct($sMicrotime){ if(!self::$enabled){ return; } $this->iStartMicrotime=self::microtime($sMicrotime); $iEndTime=self::microtime(); self::$tTime[]=array('End',$iEndTime); $iDiff=($iEndTime-$this->iStartMicrotime); $this->add('Time',sprintf('%0.3f',$iDiff).'s'); $this->addComplexTimes('times',self::$tTime); $this->addComplex('$_GET',print_r($_GET,1)); if(isset($_POST)){ $this->addComplex('$_POST',print_r($_POST,1)); } if(isset($_SESSION)){ $this->addComplex('$_SESSION',print_r($_SESSION,1)); } if(isset($_SERVER)){ $this->addComplex('$_SERVER',print_r($_SERVER,1)); } $oRequest=_root::getRequest(); $this->add('Module',$oRequest->getModule()); $this->add('Action',$oRequest->getAction()); $oFileLog=new _file(_root::getConfigVar('path.log','data/log/').date('Y-m-d').'_log.csv'); if($oFileLog->exist()){ $oFileLog->load(); $sContentLog=$oFileLog->getContent(); $this->addFileLog('File log',$sContentLog); } $sVarIniConfig=_root::getConfigVar('model.ini.var','db'); $tClassSgbd=_root::getConfigVar($sVarIniConfig); $this->addComplexIni('Connexions',array($sVarIniConfig=>$tClassSgbd)); $tConfigSection=array( 'path' , 'cache' , 'language', 'auth', 'acl', 'navigation', 'urlrewriting', 'security', 'log', 'check', 'path', 'model', ); $tConfig=array(); foreach($tConfigSection as $sSection){ $tConfig[$sSection]=_root::getConfigVar($sSection); } $this->addComplexIni('Config',$tConfig); if(self::$tSpy){ $this->addComplexSpy('Spy variables',self::$tSpy); } $tSessionSpy=self::getListSessionSpy(); if($tSessionSpy){ $this->addComplexSpy('Spy Session variables',$tSessionSpy); } $this->addAcl(); } /** ajoute dans la barre de debug l'affichage d'une variable (tableau,objet..) * @access public * @return void * @param string $uLabel nom de la variable a afficher * @param mixte $uVar la variable a afficher dans la barre */ public static function addSpy($uLabel,$uVar){ if(!self::$enabled){ return; } self::$tSpy[][$uLabel]=$uVar; } public static function getIpHash(){ return sha1($_SERVER['REMOTE_ADDR']); } public static function getSessionSpyVarFilename(){ $sIP=self::getIpHash(); return _root::getConfigVar('path.log','data/log/').'spyVar'.$sIP; } public static function addSessionSpy($uLabel,$uVar){ if(!self::$enabled){ return; } $sFilename=self::getSessionSpyVarFilename(); $tSpy=array(); if(file_exists($sFilename)){ $tSpy=unserialize(file_get_contents( $sFilename )); } $tSpy[][$uLabel]=$uVar; file_put_contents($sFilename, serialize($tSpy)); } public static function getListSessionSpy(){ $sFilename=self::getSessionSpyVarFilename(); $tSpy=array(); if(file_exists($sFilename)){ $tSpy=unserialize(file_get_contents( $sFilename )); } //file_put_contents($sFilename, null); return $tSpy; } public static function getListSpy(){ return self::$tSpy; } /** ajoute un chrono * @access public * @return void * @param string $uLabel nom du chrono */ public static function addChrono($uLabel){ if(!self::$enabled){ return; } $iTime=self::microtime(); self::$tTime[]=array($uLabel,$iTime); } /** demarre un chrono (pour chronometre le temps d'un point A a un point B) * @access public * @return void * @param string $uLabel nom du chrono */ public static function startChrono($uLabel){ if(!self::$enabled){ return; } $iTime=self::microtime(); self::$tTimeById[$uLabel]['start']=$iTime; } /** arrete le chrono de l'id passe (pour chronometre le temps d'un point A a un point B) * @access public * @return void * @param string $uLabel nom du chrono (qui doit etre le meme que le chrono demarre) */ public static function stopChrono($uLabel){ if(!self::$enabled){ return; } $iTime=self::microtime(); self::$tTimeById[$uLabel]['end']=$iTime; } public function display(){ echo ''; echo '
Action | Component |
---|---|
'.$tVal[0].' | '.$tVal[1].' |
'; $sHtml.=''.$sDate.' '; $sHtml.=''.$sTime.''; $sHtml.=$sep; $sHtml.=''.$sType.''; $sHtml.=$sep; if(substr($sLog,0,3)=='sql'){ $sHtml.='SQL '.substr($sLog,3).''; }else{ $sHtml.=$sLog; } $sHtml.='
'; if(preg_match('/module a appeler/',$sLog)){ $sHtml.=''; } } return $sHtml; } private function parseSpy($tValue){ $sHtml=null; foreach($tValue as $tDetail){ foreach($tDetail as $ref => $value){ $sHtml.='
'.customHtmlentities(print_r($value,1)).''; } } return $sHtml; } private function parseIni($tValue){ $sHtml=null; foreach($tValue as $sSection => $tDetail){ $sHtml.='
'; $sHtml.=''.$sKey.' = '.$sValue.''; $sHtml.='
'; } } return $sHtml; } private function parseTime($tValue){ $sHtml=null; $iPreviousTime=$this->iStartMicrotime; $sPreviousStep='Start'; foreach($tValue as $tDetail){ list($sLabel,$iTime)=$tDetail; $iDelta=($iTime-$iPreviousTime); $sHtml.=''.$sPreviousStep.' >> '.$sLabel.' : '.sprintf('%0.3f',$iDelta).'s
'; $iPreviousTime=$iTime; $sPreviousStep=$sLabel; } $sHtml.=''; $sHtml.='Total '.sprintf('%0.3f',($iTime-$this->iStartMicrotime)).'s'; $sHtml.='
'; if(self::$tTimeById){ $sHtml.=''; foreach(self::$tTimeById as $sLabel => $tValue){ if(isset($tValue['end']) and isset($tValue['start'])){ $iDelta=($tValue['end']-$tValue['start']); $sHtml.='
'.$sLabel.' : '.sprintf('%0.3f',$iDelta).'s
'; }else{ $sHtml.=''.$sLabel.' : '; $sHtml.=' Erreur il manque startChrono ou stopChrono
'; } } } return $sHtml; } public static function microtime($sMicrotime=null){ return microtime(true); } } if(_root::getConfigVar('site.mode')=='dev'){ plugin_debug::$enabled=1; }