From 3b006ae5a1792f96c40ffa2035ae4698fcb8097d Mon Sep 17 00:00:00 2001 From: rodneyrehm Date: Thu, 13 Oct 2011 09:50:55 +0000 Subject: [PATCH] - add caching for config files in Smarty_Resource (not really sure why this wasn't implemented yet?!) If we removed this (for some reason) we should've made a note of it in the code... --- change_log.txt | 3 +++ libs/Smarty.class.php | 11 ++++++-- libs/sysplugins/smarty_resource.php | 41 ++++++++++++++++++++++------- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/change_log.txt b/change_log.txt index dc9775ea..0bb14870 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@ ===== trunk ===== +13.10.2011 +- add caching for config files in Smarty_Resource + 11.10.2011 - add runtime checks for not matching {capture}/{/capture} calls (Forum Topic 20120) diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 8060f3b9..ff5f155f 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -197,6 +197,11 @@ class Smarty extends Smarty_Internal_TemplateBase { */ public $joined_template_dir = null; /** + * joined config directory string used in cache keys + * @var string + */ + public $joined_config_dir = null; + /** * default template handler * @var callable */ @@ -841,7 +846,8 @@ class Smarty extends Smarty_Internal_TemplateBase { foreach ((array) $config_dir as $k => $v) { $this->config_dir[$k] = rtrim($v, '/\\') . DS; } - + + $this->joined_config_dir = join(DIRECTORY_SEPARATOR, $this->config_dir); return $this; } @@ -874,7 +880,8 @@ class Smarty extends Smarty_Internal_TemplateBase { // append new directory $this->config_dir[] = rtrim($config_dir, '/\\') . DS; } - + + $this->joined_config_dir = join(DIRECTORY_SEPARATOR, $this->config_dir); return $this; } diff --git a/libs/sysplugins/smarty_resource.php b/libs/sysplugins/smarty_resource.php index b2f89701..047076b3 100644 --- a/libs/sysplugins/smarty_resource.php +++ b/libs/sysplugins/smarty_resource.php @@ -398,16 +398,6 @@ abstract class Smarty_Resource { $template_resource = $_template->template_resource; } - // check runtime cache - $_cache_key_dir = $smarty->joined_template_dir; - $_cache_key = 'template|' . $template_resource; - if (!isset(self::$sources[$_cache_key_dir])) { - self::$sources[$_cache_key_dir] = array(); - } - if (isset(self::$sources[$_cache_key_dir][$_cache_key])) { - return self::$sources[$_cache_key_dir][$_cache_key]; - } - if (($pos = strpos($template_resource, ':')) === false) { // no resource given, use default $resource_type = $smarty->default_resource_type; @@ -424,6 +414,20 @@ abstract class Smarty_Resource { } $resource = Smarty_Resource::load($smarty, $resource_type); + + // TODO: modify $template_resource here + + // check runtime cache + $_cache_key_dir = $smarty->joined_template_dir; + $_cache_key = 'template|' . $template_resource; + if (!isset(self::$sources[$_cache_key_dir])) { + self::$sources[$_cache_key_dir] = array(); + } + if (isset(self::$sources[$_cache_key_dir][$_cache_key])) { + return self::$sources[$_cache_key_dir][$_cache_key]; + } + + // create source $source = new Smarty_Template_Source($resource, $smarty, $template_resource, $resource_type, $resource_name); $resource->populate($source, $_template); @@ -464,8 +468,25 @@ abstract class Smarty_Resource { } $resource = Smarty_Resource::load($smarty, $resource_type); + + // TODO: modify $config_resource here + + // check runtime cache + $_cache_key_dir = $smarty->joined_config_dir; + $_cache_key = 'config|' . $config_resource; + if (!isset(self::$sources[$_cache_key_dir])) { + self::$sources[$_cache_key_dir] = array(); + } + if (isset(self::$sources[$_cache_key_dir][$_cache_key])) { + return self::$sources[$_cache_key_dir][$_cache_key]; + } + + // create source $source = new Smarty_Config_Source($resource, $smarty, $config_resource, $resource_type, $resource_name); $resource->populate($source, null); + + // runtime cache + self::$sources[$_cache_key_dir][$_cache_key] = $source; return $source; }