DebugTab.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Debug entries to a static class
  4. * Do not use App::uses() to include this file as it also needs a function included
  5. * (see below). Use App::import('Lib', 'Tools.Bootstrap/DebugTab');
  6. */
  7. class DebugTab {
  8. public static $content = array();
  9. public static $groups = array();
  10. /**
  11. * @return boolean Success
  12. */
  13. public static function debug($var = false, $display = false, $key = null) {
  14. if (is_string($display)) {
  15. $key = $display;
  16. $display = true;
  17. }
  18. if (Configure::read('debug') > 0) {
  19. $calledFrom = debug_backtrace();
  20. if (is_string($key)) {
  21. if (!isset(DebugTab::$groups[$key])) {
  22. DebugTab::$groups[$key] = array();
  23. }
  24. DebugTab::$groups[$key][] = array(
  25. 'debug' => print_r($var, true),
  26. 'file' => substr(str_replace(ROOT, '', $calledFrom[0]['file']), 1),
  27. 'line' => $calledFrom[0]['line'],
  28. 'display' => $display
  29. );
  30. } else {
  31. DebugTab::$content[] = array(
  32. 'debug' => print_r($var, true),
  33. 'file' => substr(str_replace(ROOT, '', $calledFrom[0]['file']), 1),
  34. 'line' => $calledFrom[0]['line'],
  35. 'display' => $display
  36. );
  37. }
  38. }
  39. return true;
  40. }
  41. /**
  42. * Display debugged information
  43. *
  44. * @return string HTML
  45. */
  46. public static function get() {
  47. return '<pre class="debug-tab">' .
  48. print_r(DebugTab::$groups, true) .
  49. print_r(DebugTab::$content, true) .
  50. '</pre>';
  51. }
  52. }
  53. /**
  54. * Public, quick access function for class
  55. *
  56. * @return boolean Success
  57. */
  58. function debugTab($var = false, $display = false, $key = null) {
  59. return DebugTab::debug($var, $display, $key);
  60. }