Debugger
This commit is contained in:
parent
0929870cc9
commit
c3f11a4c66
@ -1,6 +1,11 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
// import configs
|
||||
require_once '../library/Debugger.php';
|
||||
|
||||
Debugger::flag('loaders');
|
||||
|
||||
//Autoloader
|
||||
class Autoloader {
|
||||
protected static $extension = ".php";
|
||||
@ -50,6 +55,8 @@ class ErrorHandler {
|
||||
}
|
||||
set_exception_handler("ErrorHandler::exception");
|
||||
|
||||
Debugger::flag('preload');
|
||||
|
||||
$json = file_get_contents('php://input');
|
||||
$obj = json_decode($json, true);
|
||||
|
||||
@ -73,21 +80,13 @@ mb_internal_encoding ("UTF-8");
|
||||
// import configs
|
||||
require_once '../config/config.php';
|
||||
|
||||
// Logs
|
||||
$logManager = new LogManager();
|
||||
|
||||
// Language
|
||||
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
|
||||
$langTag = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
|
||||
$langMng = new LanguageManager($langTag);
|
||||
$langMng->load();
|
||||
}
|
||||
|
||||
Debugger::flag('dbconnect');
|
||||
//D B Conector
|
||||
Db::connect (DBHOST, DBUSER, DBPASS, DBNAME);
|
||||
|
||||
// TODO: Přesunout do Login Pohledu
|
||||
$userManager = new UserManager();
|
||||
|
||||
Debugger::flag('routes');
|
||||
// import routes
|
||||
require_once '../app/Routes.php';
|
||||
|
||||
Debugger::flag('done');
|
||||
// echo Debugger::showFlags(false);
|
||||
|
63
library/Debugger.php
Normal file
63
library/Debugger.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
class Debugger {
|
||||
private static $flags = [];
|
||||
private static $tracker = [];
|
||||
private static $backtrace;
|
||||
|
||||
public static function trackStart ($key){
|
||||
self::$tracker[$key] = array(
|
||||
'start' => microtime(true),
|
||||
'stop' => 0
|
||||
);
|
||||
}
|
||||
|
||||
public static function trackStop ($key){
|
||||
self::$tracker[$key]['stop'] = microtime(true);
|
||||
}
|
||||
|
||||
public static function showTracker(){
|
||||
$ret = '';
|
||||
|
||||
foreach(self::$tracker as $key => $track){
|
||||
$ret .= $key.': '.number_format($track['stop']-$track['start'], 4, '.', ' ') .' ms<br>';
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public static function flag ($text) {
|
||||
$flag = array(
|
||||
'time' => microtime(true)*1000,
|
||||
'flag' => $text
|
||||
);
|
||||
self::$flags[] = $flag;
|
||||
}
|
||||
|
||||
public static function showFlags($asHtml = true){
|
||||
$ret = '';
|
||||
$nl = $asHtml ? "<br>\n": "\n";
|
||||
|
||||
$size = count(self::$flags);
|
||||
for($i=0; $i<$size - 1; $i++){
|
||||
$ret .= self::$flags[$i]['flag'];
|
||||
$ret .= '-';
|
||||
$ret .= self::$flags[$i+1]['flag'];
|
||||
$ret .= ' '. number_format(self::$flags[$i+1]['time'] - self::$flags[$i]['time'], 0, '.', ' ') .' ms';
|
||||
$ret .= $nl;
|
||||
}
|
||||
if($size > 1){
|
||||
$ret .= 'TOTAL: '.number_format(self::$flags[$size-1]['time'] - self::$flags[0]['time'], 0, '.' ,' ') .' ms';
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public static function debug($backtrace){
|
||||
self::$backtrace = $backtrace;
|
||||
}
|
||||
|
||||
public static function showDebug(){
|
||||
return self::$backtrace;
|
||||
}
|
||||
}
|
||||
?>
|
@ -60,6 +60,7 @@ class Router{
|
||||
}
|
||||
|
||||
if($this->function !== NULL){
|
||||
Debugger::flag('execution');
|
||||
if(is_string($this->function)){
|
||||
if(strpos($this->function, '@') !== false){
|
||||
list($class, $function) = explode('@', $this->function);
|
||||
|
Loading…
Reference in New Issue
Block a user