Пример #1
0
 /**
  * Generate debug html file from collected data
  */
 public static function generate()
 {
     if (!DRAGON_DEBUG) {
         return;
     }
     $path = BASE_PATH . DS . 'tmp' . DS . 'debug' . DS;
     if (!file_exists($path)) {
         mkdir($path, 0777, true);
     }
     //clear old files
     if (file_exists($path . 'last.html')) {
         unlink($path . 'last.html');
     }
     $files = glob($path . '*.html');
     if (count($files) >= 10) {
         rsort($files);
         for ($i = count($files) - 1; $i >= 10; $i--) {
             unlink($files[$i]);
             unset($files[$i]);
         }
     }
     self::history($files);
     $time = microtime(true);
     ob_start();
     self::echoHtml('<!DOCTYPE html>', '<html>', '<head>');
     self::htmlStyles();
     self::htmlScripts();
     self::echoHtml('</head>', '<body>');
     if (!empty($_SERVER['REQUEST_URI'])) {
         self::echoHtml('URI: <b>' . $_SERVER['REQUEST_URI'] . '</b><br>');
     }
     self::echoHtml('CM: <b>' . Dragon::$controller . '::' . Dragon::$method . '</b><br>');
     self::echoHtml('Time: <b>' . date('Y-m-d H:i:s', $time) . substr($time, strpos($time, '.')) . '</b><br>');
     //tabs switches
     $tabs = [];
     $class = 'active';
     foreach (array_keys(Debug::$tables) as $key) {
         $tabs[] = '<li class="' . $class . '" data-tab="' . $key . '">' . $key . ' (' . count(Debug::$tables[$key]) . ')</li>';
         $class = '';
     }
     self::echoHtml('<br><ul>' . implode('', $tabs) . '</ul>');
     self::htmlTables();
     self::echoHtml('</body>', '</html>');
     $html = ob_get_clean();
     $filename = $time . '.html';
     file_put_contents($path . $filename, $html);
     file_put_contents($path . 'last.html', $html);
     Debug::$tables = [];
 }