aa095a3358dfda82b2b4061be59a73459582c9e8.svn-base 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php namespace Maze\Debug;
  2. //use ChromePhp as Tool;
  3. use Maze\Config\Load as Config;
  4. use Maze\Http\Input;
  5. class Process
  6. {
  7. static private $data;
  8. /**
  9. * init
  10. *
  11. * @return string
  12. */
  13. static public function init()
  14. {
  15. if(Input::get(Config::$global['debug']['shell']) == 'request')
  16. {
  17. return 1;
  18. }
  19. if(Config::$global['debug']['request'])
  20. {
  21. return 2;
  22. }
  23. return false;
  24. }
  25. /**
  26. * log
  27. *
  28. * @return string
  29. */
  30. static public function log($msg)
  31. {
  32. if(self::init())
  33. {
  34. if(isset($msg['value']) && isset($msg['sql']) && is_array($msg['value']))
  35. {
  36. foreach($msg['value'] as $k => $v)
  37. {
  38. $msg['sql'] = str_replace($k, $v, $msg['sql']);
  39. }
  40. unset($msg['value']);
  41. }
  42. if(is_array($msg)) $msg = var_export($msg, true);
  43. self::add('log', $msg . "\r\n" . self::time() . "\r\n" . self::memory() . "\r\n" );
  44. }
  45. }
  46. /**
  47. * runtime
  48. *
  49. * @return string
  50. */
  51. static public function runtime()
  52. {
  53. self::log('Total');
  54. self::log('Total' . "\r\n" . self::loadfile());
  55. }
  56. /**
  57. * time
  58. *
  59. * @return string
  60. */
  61. static private function time()
  62. {
  63. list($a, $b) = explode(' ', MAZE_START);
  64. $s = ((float)$a + (float)$b);
  65. list($a, $b) = explode(' ', microtime());
  66. $e = ((float)$a + (float)$b);
  67. return '[time:' . ($e - $s) . 'S]';
  68. }
  69. /**
  70. * memory
  71. *
  72. * @return string
  73. */
  74. static private function memory()
  75. {
  76. return '[memory:' . (memory_get_usage()/1024) . 'KB]';
  77. }
  78. /**
  79. * loadfile
  80. *
  81. * @return string
  82. */
  83. static private function loadfile()
  84. {
  85. return '[file:' . var_export(get_included_files(), true) . ']';
  86. }
  87. /**
  88. * add
  89. *
  90. * @return string
  91. */
  92. static private function add($method, $msg)
  93. {
  94. //Tool::$method($msg);
  95. self::$data[$method][] = $msg;
  96. }
  97. /**
  98. * wait
  99. *
  100. * @return array
  101. */
  102. static public function wait()
  103. {
  104. echo self::html('');die;
  105. }
  106. /**
  107. * data
  108. *
  109. * @return string
  110. */
  111. static public function data()
  112. {
  113. if(self::init() == 1)
  114. {
  115. echo self::html('');
  116. }
  117. }
  118. /**
  119. * html
  120. *
  121. * @return string
  122. */
  123. static public function html($show = 'display:none;')
  124. {
  125. self::runtime();
  126. $fix = 'fixed';
  127. if(!$show)
  128. {
  129. $fix = '';
  130. }
  131. $html = '<div style="position:'.$fix.';z-index:10000;bottom:0;background:white;overflow:auto;width:100%;height:auto;">';
  132. if(self::$data)
  133. {
  134. foreach(self::$data as $k => $v)
  135. {
  136. $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>';
  137. $html .= '<div style="'.$show.'">';
  138. $html .= '<table border="1">';
  139. foreach($v as $i => $j)
  140. {
  141. $html .= '<tr>';
  142. $html .= '<td>' . $j . '</td>';
  143. $html .= '</tr>';
  144. }
  145. $html .= '</table>';
  146. $html .= '</div>';
  147. }
  148. }
  149. $html .= '</div>';
  150. return $html;
  151. }
  152. }