smarty_internal_debug.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Debug
  4. *
  5. * Class to collect data for the Smarty Debugging Consol
  6. *
  7. * @package Smarty
  8. * @subpackage Debug
  9. * @author Uwe Tews
  10. */
  11. /**
  12. * Smarty Internal Plugin Debug Class
  13. */
  14. class Smarty_Internal_Debug extends Smarty_Internal_Data {
  15. // template data
  16. static $template_data = array();
  17. /**
  18. * Start logging of compile time
  19. */
  20. public static function start_compile($template)
  21. {
  22. $key = self::get_key($template);
  23. self::$template_data[$key]['start_time'] = microtime(true);
  24. }
  25. /**
  26. * End logging of compile time
  27. */
  28. public static function end_compile($template)
  29. {
  30. $key = self::get_key($template);
  31. self::$template_data[$key]['compile_time'] += microtime(true) - self::$template_data[$key]['start_time'];
  32. }
  33. /**
  34. * Start logging of render time
  35. */
  36. public static function start_render($template)
  37. {
  38. $key = self::get_key($template);
  39. self::$template_data[$key]['start_time'] = microtime(true);
  40. }
  41. /**
  42. * End logging of compile time
  43. */
  44. public static function end_render($template)
  45. {
  46. $key = self::get_key($template);
  47. self::$template_data[$key]['render_time'] += microtime(true) - self::$template_data[$key]['start_time'];
  48. }
  49. /**
  50. * Start logging of cache time
  51. */
  52. public static function start_cache($template)
  53. {
  54. $key = self::get_key($template);
  55. self::$template_data[$key]['start_time'] = microtime(true);
  56. }
  57. /**
  58. * End logging of cache time
  59. */
  60. public static function end_cache($template)
  61. {
  62. $key = self::get_key($template);
  63. self::$template_data[$key]['cache_time'] += microtime(true) - self::$template_data[$key]['start_time'];
  64. }
  65. /**
  66. * Opens a window for the Smarty Debugging Consol and display the data
  67. */
  68. public static function display_debug($smarty)
  69. {
  70. // prepare information of assigned variables
  71. $_assigned_vars = $smarty->tpl_vars;
  72. ksort($_assigned_vars);
  73. $_config_vars = $smarty->config_vars;
  74. ksort($_config_vars);
  75. $_template = new Smarty_Template ($smarty->debug_tpl, $smarty);
  76. $_template->caching = false;
  77. $_template->force_compile = false;
  78. $_template->security = false;
  79. $_template->cache_id = null;
  80. $_template->compile_id = null;
  81. $_template->assign('template_data', self::$template_data);
  82. $_template->assign('assigned_vars', $_assigned_vars);
  83. $_template->assign('config_vars', $_config_vars);
  84. $_template->assign('execution_time', microtime(true) - $smarty->start_time);
  85. echo $smarty->fetch($_template);
  86. }
  87. /**
  88. * get_key
  89. */
  90. static function get_key($template)
  91. {
  92. // calculate Uid if not already done
  93. if ($template->templateUid == '') {
  94. $template->getTemplateFilepath();
  95. }
  96. $key = $template->templateUid;
  97. if (isset(self::$template_data[$key])) {
  98. return $key;
  99. } else {
  100. self::$template_data[$key]['name'] = $template->getTemplateFilepath();
  101. self::$template_data[$key]['compile_time'] = 0;
  102. self::$template_data[$key]['render_time'] = 0;
  103. self::$template_data[$key]['cache_time'] = 0;
  104. return $key;
  105. }
  106. }
  107. }
  108. ?>