/includes/libraries/debug/debug.php

https://github.com/Arkadiy-Sedelnikov/joostina-1.4 · PHP · 112 lines · 74 code · 18 blank · 20 comment · 3 complexity · 9531ed3f958feee8759b220666b6a114 MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joostina
  4. * @copyright Авторские права (C) 2008-2010 Joostina team. Все права защищены.
  5. * @license Лицензия http://www.gnu.org/licenses/gpl-2.0.htm GNU/GPL, или help/license.php
  6. * Joostina! - свободное программное обеспечение распространяемое по условиям лицензии GNU/GPL
  7. * Для получения информации о используемых расширениях и замечаний об авторском праве, смотрите файл help/copyright.php.
  8. */
  9. // запрет прямого доступа
  10. defined('_JLINDEX') or die();
  11. class jdebug{
  12. /* стек сообщений лога*/
  13. var $_log = array();
  14. /* буфер сообщений лога*/
  15. var $text = null;
  16. /* счетчики */
  17. var $_inc = array();
  18. public static function getInstance(){
  19. static $instance;
  20. if(!is_object($instance)){
  21. $instance = new jdebug();
  22. }
  23. return $instance;
  24. }
  25. /* добавление сообщения в лог*/
  26. function add($text, $top = 0){
  27. $top ? array_unshift($this->_log, $text) : $this->_log[] = $text;
  28. }
  29. /* добавление сообщения в лог*/
  30. function inc($key){
  31. if(!isset($this->_inc[$key])){
  32. $this->_inc[$key] = 0;
  33. }
  34. $this->_inc[$key]++;
  35. }
  36. /* вывод сообщений из лога*/
  37. function get(){
  38. echo '<span style="display:none"><![CDATA[<noindex>]]></span><pre>';
  39. /* счетчики */
  40. foreach($this->_inc as $key => $value){
  41. $this->text .= '<small class="debug_counter">COUNTER:</small> <b>' . htmlentities($key) . '</b>: ' . $value . '<br />';
  42. }
  43. /* лог */
  44. $this->text .= '<ul class="debug_log">';
  45. foreach($this->_log as $key => $value){
  46. $this->text .= '<li><small>LOG:</small> ' . $value . '</li>';
  47. }
  48. $this->text .= '</ul>';
  49. $this->text .= $this->db_debug();
  50. /* подключенные файлы */
  51. $files = get_included_files();
  52. $f = array();
  53. $f[] = '<div onclick="$(\'#_sql_debug_file\').toggle();" style="cursor: pointer;border-bottom:1px solid #CCCCCC;border-top:1px solid #CCCCCC;">' . _INCLUDED_FILES . ': ' . count($files) . '</div>';
  54. $f[] = '<div id="_sql_debug_file" style="display:none">';
  55. foreach($files as $key => $value){
  56. $f[] = '<small>' . $key . ':</small> ' . $value . '<br />';
  57. }
  58. $f[] = '</div>';
  59. $this->text .= implode('', $f);
  60. unset($f);
  61. echo '<div id="jdebug">' . $this->text . '</div>';
  62. echo '</pre><span style="display:none"><![CDATA[</noindex>]]></span>';
  63. }
  64. function db_debug(){
  65. $database = database::getInstance();
  66. $database->setQuery('show profiles;');
  67. $profs = $database->loadObjectList();
  68. $r = array();
  69. $r[] = '<div onclick="$(\'#_sql_debug_log\').toggle();" style="cursor: pointer;border-bottom:1px solid #CCCCCC;border-top:1px solid #CCCCCC;">SQL: ' . count($profs) . '</div>';
  70. $r[] = '<table id="_sql_debug_log" style="display:none"><tr><th colspan="3"></th></tr>';
  71. if(isset($profs[0])){
  72. foreach($profs as $prof){
  73. $r[] = '<tr valign="top"><td>#' . $prof->Query_ID . ' </td><td> ' . $prof->Duration . ' </td><td> ' . $prof->Query . ' </td></tr>';
  74. }
  75. }
  76. $r[] = '</table>';
  77. return implode('', $r);
  78. }
  79. }
  80. /* упрощенная процедура добавления сообщения в лог */
  81. function jd_log($text){
  82. jdebug::getInstance()->add($text);
  83. }
  84. /* упрощенная процедура добавления сообщения в начало лога */
  85. function jd_log_top($text){
  86. jdebug::getInstance()->add($text, 1);
  87. }
  88. /* счетчики вызывов */
  89. function jd_inc($name = 'counter'){
  90. jdebug::getInstance()->inc($name);
  91. }
  92. function jd_get(){
  93. jdebug::getInstance()->get();
  94. }