mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
implement templateId generation as method
This commit is contained in:
@@ -71,7 +71,7 @@ if (!defined('SMARTY_RESOURCE_DATE_FORMAT')) {
|
||||
|
||||
/**
|
||||
* Try loading the Smmarty_Internal_Data class
|
||||
*
|
||||
*
|
||||
* If we fail we must load Smarty's autoloader.
|
||||
* Otherwise we may have a global autoloader like Composer
|
||||
*/
|
||||
@@ -89,7 +89,6 @@ require SMARTY_SYSPLUGINS_DIR . 'smarty_internal_template.php';
|
||||
require SMARTY_SYSPLUGINS_DIR . 'smarty_resource.php';
|
||||
require SMARTY_SYSPLUGINS_DIR . 'smarty_internal_resource_file.php';
|
||||
|
||||
|
||||
/**
|
||||
* This is the main Smarty class
|
||||
*
|
||||
@@ -632,6 +631,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
* @var bool
|
||||
*/
|
||||
public $_parserdebug = false;
|
||||
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
@@ -1287,18 +1287,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
} else {
|
||||
$data = null;
|
||||
}
|
||||
// default to cache_id and compile_id of Smarty object
|
||||
$cache_id = $cache_id === null ? $this->cache_id : $cache_id;
|
||||
$compile_id = $compile_id === null ? $this->compile_id : $compile_id;
|
||||
// already in template cache?
|
||||
if ($this->allow_ambiguous_resources) {
|
||||
$_templateId = Smarty_Resource::getUniqueTemplateName($this, $template) . $cache_id . $compile_id;
|
||||
} else {
|
||||
$_templateId = $this->joined_template_dir . '#' . $template . $cache_id . $compile_id;
|
||||
}
|
||||
if (isset($_templateId[150])) {
|
||||
$_templateId = sha1($_templateId);
|
||||
}
|
||||
$_templateId = $this->getTemplateId($template, $cache_id, $compile_id);
|
||||
if ($do_clone) {
|
||||
if (isset($this->template_objects[$_templateId])) {
|
||||
// return cached template object
|
||||
@@ -1309,6 +1298,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
$tpl->config_vars = array();
|
||||
} else {
|
||||
$tpl = new $this->template_class($template, clone $this, $parent, $cache_id, $compile_id);
|
||||
$tpl->templateId = $_templateId;
|
||||
}
|
||||
} else {
|
||||
if (isset($this->template_objects[$_templateId])) {
|
||||
@@ -1319,6 +1309,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
$tpl->config_vars = array();
|
||||
} else {
|
||||
$tpl = new $this->template_class($template, $this, $parent, $cache_id, $compile_id);
|
||||
$tpl->templateId = $_templateId;
|
||||
}
|
||||
}
|
||||
// fill data if present
|
||||
@@ -1529,6 +1520,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
{
|
||||
$this->error_reporting = $error_reporting;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $escape_html
|
||||
*/
|
||||
|
@@ -48,6 +48,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
|
||||
* @var integer
|
||||
*/
|
||||
public $cache_lifetime = 3600;
|
||||
|
||||
/**
|
||||
* fetches a rendered Smarty template
|
||||
*
|
||||
@@ -467,6 +468,30 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
|
||||
return $dataObj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get unique template id
|
||||
*
|
||||
* @param string $template_name
|
||||
* @param null|mixed $cache_id
|
||||
* @param null|mixed $compile_id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTemplateId($template_name, $cache_id = null, $compile_id = null)
|
||||
{
|
||||
$cache_id = isset($cache_id) ? $cache_id : $this->cache_id;
|
||||
$compile_id = isset($compile_id) ? $compile_id : $this->compile_id;
|
||||
if ($this->smarty->allow_ambiguous_resources) {
|
||||
$_templateId = Smarty_Resource::getUniqueTemplateName($this, $template_name) . "#{$cache_id}#{$compile_id}";
|
||||
} else {
|
||||
$_templateId = $this->smarty->joined_template_dir . "#{$template_name}#{$cache_id}#{$compile_id}";
|
||||
}
|
||||
if (isset($_templateId[150])) {
|
||||
$_templateId = sha1($_templateId);
|
||||
}
|
||||
return $_templateId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers plugin to be used in templates
|
||||
*
|
||||
|
Reference in New Issue
Block a user