mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-06 19:34:27 +02:00
- changed debugging handling
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
11/11/2009
|
||||
- fixed {foreachelse}, {forelse}, {sectionelse} compiled code at nocache variables
|
||||
- removed checking for reserved variables
|
||||
- changed debugging handling
|
||||
|
||||
11/10/2009
|
||||
- fixed preg_qoute on delimiters
|
||||
|
@@ -332,7 +332,9 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
||||
// display template
|
||||
echo $this->fetch ($template, $cache_id, $compile_id, $parent);
|
||||
// debug output
|
||||
$this->displayDebugInfo();
|
||||
if ($this->debugging) {
|
||||
Smarty_Internal_Debug::display_debug($this);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -488,16 +490,6 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
||||
return set_exception_handler($handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display debug info
|
||||
*/
|
||||
public function displayDebugInfo()
|
||||
{
|
||||
if ($this->debugging) {
|
||||
Smarty_Internal_Debug::display_debug($this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* trigger Smarty error
|
||||
*
|
||||
|
@@ -13,35 +13,67 @@
|
||||
* Smarty Internal Plugin Debug Class
|
||||
*/
|
||||
class Smarty_Internal_Debug extends Smarty_Internal_TemplateBase {
|
||||
// template data
|
||||
static $template_data = array();
|
||||
|
||||
/**
|
||||
* Start logging of compile time
|
||||
*/
|
||||
public static function start_compile($template)
|
||||
{
|
||||
$key = self::get_key($template);
|
||||
self::$template_data[$key]['start_time'] = self::get_time();
|
||||
}
|
||||
|
||||
/**
|
||||
* End logging of compile time
|
||||
*/
|
||||
public static function end_compile($template)
|
||||
{
|
||||
$key = self::get_key($template);
|
||||
self::$template_data[$key]['compile_time'] = self::get_time() - self::$template_data[$key]['start_time'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Start logging of render time
|
||||
*/
|
||||
public static function start_render($template)
|
||||
{
|
||||
$key = self::get_key($template);
|
||||
self::$template_data[$key]['start_time'] = self::get_time();
|
||||
}
|
||||
|
||||
/**
|
||||
* End logging of compile time
|
||||
*/
|
||||
public static function end_render($template)
|
||||
{
|
||||
$key = self::get_key($template);
|
||||
self::$template_data[$key]['render_time'] = self::get_time() - self::$template_data[$key]['start_time'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Start logging of cache time
|
||||
*/
|
||||
public static function start_cache($template)
|
||||
{
|
||||
$key = self::get_key($template);
|
||||
self::$template_data[$key]['start_time'] = self::get_time();
|
||||
}
|
||||
|
||||
/**
|
||||
* End logging of cache time
|
||||
*/
|
||||
public static function end_cache($template)
|
||||
{
|
||||
$key = self::get_key($template);
|
||||
self::$template_data[$key]['cache_time'] = self::get_time() - self::$template_data[$key]['start_time'];
|
||||
}
|
||||
/**
|
||||
* Opens a window for the Smarty Debugging Consol and display the data
|
||||
*/
|
||||
public static function display_debug($smarty)
|
||||
{
|
||||
// get template names
|
||||
$i = 0;
|
||||
$_template_data = array();
|
||||
if (is_array($smarty->template_objects)) {
|
||||
foreach ($smarty->template_objects as $_template_obj) {
|
||||
// exclude the debugging template from displayed data
|
||||
if ($smarty->debug_tpl != $_template_obj->resource_name) {
|
||||
$_template_data[$i]['name'] = $_template_obj->getTemplateFilepath();
|
||||
$_template_data[$i]['compile_time'] = $_template_obj->compile_time;
|
||||
$_template_data[$i]['render_time'] = $_template_obj->render_time;
|
||||
$_template_data[$i]['cache_time'] = $_template_obj->cache_time;
|
||||
$i++;
|
||||
if (false && $i == 1) {
|
||||
foreach ($_template_obj->properties['file_dependency'] as $_file) {
|
||||
$_template_data[$i]['name'] = $_file[0];
|
||||
$_template_data[$i]['compile_time'] = 0;
|
||||
$_template_data[$i]['render_time'] = 0;
|
||||
$_template_data[$i]['cache_time'] = 0;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
// prepare information of assigned variables
|
||||
$_assigned_vars = $smarty->tpl_vars;
|
||||
ksort($_assigned_vars);
|
||||
@@ -51,12 +83,41 @@ class Smarty_Internal_Debug extends Smarty_Internal_TemplateBase {
|
||||
$_template->caching = false;
|
||||
$_template->force_compile = false;
|
||||
$_template->security = false;
|
||||
$_template->assign('template_data', $_template_data);
|
||||
$_template->assign('template_data', self::$template_data);
|
||||
$_template->assign('assigned_vars', $_assigned_vars);
|
||||
$_template->assign('config_vars', $_config_vars);
|
||||
$_template->assign('execution_time', $smarty->_get_time() - $smarty->start_time);
|
||||
echo $smarty->fetch($_template);
|
||||
}
|
||||
|
||||
/**
|
||||
* get_key
|
||||
*/
|
||||
static function get_key($template)
|
||||
{
|
||||
$key = 'F' . abs(crc32($template->getTemplateFilepath()));
|
||||
if (isset(self::$template_data[$key])) {
|
||||
return $key;
|
||||
} else {
|
||||
self::$template_data[$key]['name'] = $template->getTemplateFilepath();
|
||||
self::$template_data[$key]['compile_time'] = 0;
|
||||
self::$template_data[$key]['render_time'] = 0;
|
||||
self::$template_data[$key]['cache_time'] = 0;
|
||||
return $key;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* return current time
|
||||
*
|
||||
* @returns double current time
|
||||
*/
|
||||
static function get_time()
|
||||
{
|
||||
$_mtime = microtime();
|
||||
$_mtime = explode(" ", $_mtime);
|
||||
return (double)($_mtime[1]) + (double)($_mtime[0]);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -41,7 +41,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
private $compiled_filepath = null;
|
||||
public $compiled_template = null;
|
||||
private $compiled_timestamp = null;
|
||||
public $compile_time = 0;
|
||||
public $mustCompile = null;
|
||||
public $suppressHeader = false;
|
||||
public $suppressFileDependency = false;
|
||||
@@ -53,7 +52,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
private $cached_filepath = null;
|
||||
private $cached_timestamp = null;
|
||||
private $isCached = null;
|
||||
public $cache_time = 0;
|
||||
private $cache_resource_object = null;
|
||||
// template variables
|
||||
public $tpl_vars = array();
|
||||
@@ -66,8 +64,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
// storage for block data
|
||||
public $block_data = array();
|
||||
|
||||
public $render_time = 0;
|
||||
|
||||
/**
|
||||
* Create template data object
|
||||
*
|
||||
@@ -211,7 +207,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
$this->isExisting(true);
|
||||
if ($this->mustCompile === null) {
|
||||
$this->mustCompile = ($this->usesCompiler() && ($this->force_compile || $this->isEvaluated() || $this->getCompiledTimestamp () === false ||
|
||||
($this->smarty->compile_check && $this->getCompiledTimestamp () !== $this->getTemplateTimestamp ())));
|
||||
($this->smarty->compile_check && $this->getCompiledTimestamp () !== $this->getTemplateTimestamp ())));
|
||||
}
|
||||
return $this->mustCompile;
|
||||
}
|
||||
@@ -269,10 +265,12 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
*/
|
||||
public function compileTemplateSource ()
|
||||
{
|
||||
$_start_time = $this->_get_time();
|
||||
if (!$this->isEvaluated) {
|
||||
$this->properties['file_dependency']['F' . abs(crc32($this->getTemplateFilepath()))] = array($this->getTemplateFilepath(), $this->getTemplateTimestamp());
|
||||
}
|
||||
if ($this->smarty->debugging) {
|
||||
Smarty_Internal_Debug::start_compile($this);
|
||||
}
|
||||
// compile template
|
||||
if (!is_object($this->compiler_object)) {
|
||||
// load compiler
|
||||
@@ -292,18 +290,20 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
Smarty_Internal_Write_File::writeFile($this->getCompiledFilepath(), $this->compiled_template);
|
||||
// make template and compiled file timestamp match
|
||||
$this->compiled_timestamp = null;
|
||||
touch($this->getCompiledFilepath(), $this->getTemplateTimestamp());
|
||||
touch($this->getCompiledFilepath(), $this->getTemplateTimestamp());
|
||||
// daylight saving time problem on windows
|
||||
if ($this->template_timestamp != $this->getCompiledTimestamp()) {
|
||||
touch($this->getCompiledFilepath(),2*$this->template_timestamp - $this->compiled_timestamp);
|
||||
}
|
||||
touch($this->getCompiledFilepath(), 2 * $this->template_timestamp - $this->compiled_timestamp);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// error compiling template
|
||||
throw new Exception("Error compiling template {$this->getTemplateFilepath ()}");
|
||||
return false;
|
||||
}
|
||||
$this->compile_time += $this->_get_time() - $_start_time;
|
||||
if ($this->smarty->debugging) {
|
||||
Smarty_Internal_Debug::end_compile($this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -372,10 +372,14 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
return $this->isCached;
|
||||
}
|
||||
if ($this->caching === SMARTY_CACHING_LIFETIME_SAVED || ($this->caching && (time() <= ($this->getCachedTimestamp() + $this->cache_lifetime) || $this->cache_lifetime < 0))) {
|
||||
$_start_time = $this->_get_time();
|
||||
if ($this->smarty->debugging) {
|
||||
Smarty_Internal_Debug::start_cache($this);
|
||||
}
|
||||
$this->rendered_content = $this->cache_resource_object->getCachedContents($this);
|
||||
$this->cache_time += $this->_get_time() - $_start_time;
|
||||
if ($this->caching === SMARTY_CACHING_LIFETIME_SAVED && $this->properties['cache_lifetime'] >0 && (time() > ($this->getCachedTimestamp() + $this->properties['cache_lifetime']))) {
|
||||
if ($this->smarty->debugging) {
|
||||
Smarty_Internal_Debug::end_cache($this);
|
||||
}
|
||||
if ($this->caching === SMARTY_CACHING_LIFETIME_SAVED && $this->properties['cache_lifetime'] > 0 && (time() > ($this->getCachedTimestamp() + $this->properties['cache_lifetime']))) {
|
||||
$this->rendered_content = null;
|
||||
return $this->isCached;
|
||||
}
|
||||
@@ -416,8 +420,10 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
if ($this->mustCompile() && $this->compiled_template === null) {
|
||||
$this->compileTemplateSource();
|
||||
}
|
||||
if ($this->smarty->debugging) {
|
||||
Smarty_Internal_Debug::start_render($this);
|
||||
}
|
||||
$_smarty_tpl = $this;
|
||||
$_start_time = $this->_get_time();
|
||||
ob_start();
|
||||
if ($this->isEvaluated()) {
|
||||
eval("?>" . $this->compiled_template);
|
||||
@@ -453,7 +459,9 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
}
|
||||
} else {
|
||||
if (is_callable(array($this->resource_object, 'renderUncompiled'))) {
|
||||
$_start_time = $this->_get_time();
|
||||
if ($this->smarty->debugging) {
|
||||
Smarty_Internal_Debug::start_render($this);
|
||||
}
|
||||
ob_start();
|
||||
$this->resource_object->renderUncompiled($this);
|
||||
} else {
|
||||
@@ -461,7 +469,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
}
|
||||
}
|
||||
$this->rendered_content = ob_get_clean();
|
||||
$this->render_time += $this->_get_time() - $_start_time;
|
||||
if (!$this->isEvaluated) {
|
||||
$this->properties['file_dependency']['F' . abs(crc32($this->getTemplateFilepath()))] = array($this->getTemplateFilepath(), $this->getTemplateTimestamp());
|
||||
}
|
||||
@@ -469,12 +476,21 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
// var_dump('merge ', $this->parent->getTemplateFilepath(), $this->parent->properties['file_dependency'], $this->getTemplateFilepath(), $this->properties['file_dependency']);
|
||||
$this->parent->properties['file_dependency'] = array_merge($this->parent->properties['file_dependency'], $this->properties['file_dependency']);
|
||||
}
|
||||
if ($this->smarty->debugging) {
|
||||
Smarty_Internal_Debug::end_render($this);
|
||||
}
|
||||
// write to cache when nessecary
|
||||
if (!$this->isEvaluated() && $this->caching) {
|
||||
if ($this->smarty->debugging) {
|
||||
Smarty_Internal_Debug::start_cache($this);
|
||||
}
|
||||
// write rendered template
|
||||
$this->writeCachedContent($this);
|
||||
// cache file may contain nocache code. read it back for processing
|
||||
$this->rendered_content = $this->cache_resource_object->getCachedContents($this);
|
||||
if ($this->smarty->debugging) {
|
||||
Smarty_Internal_Debug::end_cache($this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -694,7 +710,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
if ($this->smarty->security) {
|
||||
$this->smarty->security_handler->isTrustedStream($resource_type);
|
||||
}
|
||||
return $this->smarty->resource_objects[$resource_type] = new Smarty_Internal_Resource_Stream($this->smarty);
|
||||
return $this->smarty->resource_objects[$resource_type] = new Smarty_Internal_Resource_Stream($this->smarty);
|
||||
} else {
|
||||
throw new Exception('Unkown resource type \'' . $resource_type . '\'');
|
||||
}
|
||||
|
Reference in New Issue
Block a user