123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- <?php namespace Maze\Debug;
- //use ChromePhp as Tool;
- use Maze\Config\Load as Config;
- use Maze\Http\Input;
- class Process
- {
- static private $data;
- /**
- * init
- *
- * @return string
- */
- static public function init()
- {
- if(Input::get(Config::$global['debug']['shell']) == 'request')
- {
- return 1;
- }
- if(Config::$global['debug']['request'])
- {
- return 2;
- }
- return false;
- }
-
- /**
- * log
- *
- * @return string
- */
- static public function log($msg)
- {
- if(self::init())
- {
- if(isset($msg['value']) && isset($msg['sql']) && is_array($msg['value']))
- {
- foreach($msg['value'] as $k => $v)
- {
- $msg['sql'] = str_replace($k, $v, $msg['sql']);
- }
- unset($msg['value']);
- }
- if(is_array($msg)) $msg = var_export($msg, true);
- self::add('log', $msg . "\r\n" . self::time() . "\r\n" . self::memory() . "\r\n" );
- }
- }
- /**
- * runtime
- *
- * @return string
- */
- static public function runtime()
- {
- self::log('Total');
- self::log('Total' . "\r\n" . self::loadfile());
- }
- /**
- * time
- *
- * @return string
- */
- static private function time()
- {
- list($a, $b) = explode(' ', MAZE_START);
- $s = ((float)$a + (float)$b);
- list($a, $b) = explode(' ', microtime());
- $e = ((float)$a + (float)$b);
- return '[time:' . ($e - $s) . 'S]';
- }
- /**
- * memory
- *
- * @return string
- */
- static private function memory()
- {
- return '[memory:' . (memory_get_usage()/1024) . 'KB]';
- }
- /**
- * loadfile
- *
- * @return string
- */
- static private function loadfile()
- {
- return '[file:' . var_export(get_included_files(), true) . ']';
- }
- /**
- * add
- *
- * @return string
- */
- static private function add($method, $msg)
- {
- //Tool::$method($msg);
- self::$data[$method][] = $msg;
- }
- /**
- * wait
- *
- * @return array
- */
- static public function wait()
- {
- echo self::html('');die;
- }
- /**
- * data
- *
- * @return string
- */
- static public function data()
- {
- if(self::init() == 1)
- {
- echo self::html('');
- }
- }
-
- /**
- * html
- *
- * @return string
- */
- static public function html($show = 'display:none;')
- {
- self::runtime();
- $fix = 'fixed';
- if(!$show)
- {
- $fix = '';
- }
- $html = '<div style="position:'.$fix.';z-index:10000;bottom:0;background:white;overflow:auto;width:100%;height:auto;">';
-
- if(self::$data)
- {
- foreach(self::$data as $k => $v)
- {
- $html .= '<a style="font-size:14px;font-weight:bold;margin-left:5px;" href="javascript:;" onclick="var a = $(this).next();if(a.get(0).style.display == \'none\'){a.show();$(this).parent().height(500)}else if(a.get(0).style.display != \'none\'){a.hide();$(this).parent().height(\'auto\')}">' . $k . '</a>';
-
- $html .= '<div style="'.$show.'">';
- $html .= '<table border="1">';
-
- foreach($v as $i => $j)
- {
- $html .= '<tr>';
-
- $html .= '<td>' . $j . '</td>';
-
- $html .= '</tr>';
- }
-
- $html .= '</table>';
-
- $html .= '</div>';
- }
- }
- $html .= '</div>';
-
- return $html;
- }
- }
|