diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-01-16 21:35:50 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-01-16 21:35:50 -0500 |
commit | 41e900fc7a5cf53f340abdaf1e687adea7e0d0d3 (patch) | |
tree | 951d4982bdf86ba727dc9bc2ab3eade529e397e7 /app | |
parent | ee19c626485037adb57ae85b0cba598d37bd0010 (diff) |
Show template rendering time in debug log
Diffstat (limited to 'app')
-rw-r--r-- | app/Core/Template.php | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/app/Core/Template.php b/app/Core/Template.php index ce2884a7..8ded6f7c 100644 --- a/app/Core/Template.php +++ b/app/Core/Template.php @@ -19,6 +19,50 @@ class Template extends Helper private $overrides = array(); /** + * Rendering start time + * + * @access private + * @var float + */ + private $startTime = 0; + + /** + * Total rendering time + * + * @access private + * @var float + */ + private $renderingTime = 0; + + /** + * Method executed before the rendering + * + * @access protected + * @param string $template + */ + protected function beforeRender($template) + { + if (DEBUG) { + $this->startTime = microtime(true); + } + } + + /** + * Method executed after the rendering + * + * @access protected + * @param string $template + */ + protected function afterRender($template) + { + if (DEBUG) { + $duration = microtime(true) - $this->startTime; + $this->renderingTime += $duration; + $this->container['logger']->debug('Rendering '.$template.' in '.$duration.'s, total='.$this->renderingTime); + } + } + + /** * Render a template * * Example: @@ -32,11 +76,16 @@ class Template extends Helper */ public function render($__template_name, array $__template_args = array()) { - extract($__template_args); + $this->beforeRender($__template_name); + extract($__template_args); ob_start(); include $this->getTemplateFile($__template_name); - return ob_get_clean(); + $html = ob_get_clean(); + + $this->afterRender($__template_name); + + return $html; } /** |