mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
- 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...
This commit is contained in:
@@ -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)
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user