- optimization of resource class loading

This commit is contained in:
Uwe Tews
2015-05-07 22:57:59 +02:00
parent 37449b2fcb
commit c5468b421e
6 changed files with 61 additions and 17 deletions

View File

@@ -1,6 +1,7 @@
 ===== 3.1.22-dev ===== (xx.xx.2015)
07.05.2015
- improvement of the debugging console. Read NEW_FEATURES.txt
- optimization of resource class loading
06.05.2015
- bugfix in 3.1.22-dev cache resource must not be loaded for subtemplates

View File

@@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* smarty version
*/
const SMARTY_VERSION = '3.1.22-dev/29';
const SMARTY_VERSION = '3.1.22-dev/30';
/**
* define variable scopes

View File

@@ -226,7 +226,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
$isCacheTpl = $this->caching == Smarty::CACHING_LIFETIME_CURRENT || $this->caching == Smarty::CACHING_LIFETIME_SAVED;
if ($isCacheTpl) {
if (!isset($this->cached)) {
$this->cached = Smarty_Template_Cached::load($this);
$this->loadCached();
}
$this->cached->isCached($this, true);
}
@@ -241,7 +241,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
if (!$this->source->uncompiled) {
// render compiled code
if (!isset($this->compiled)) {
$this->compiled = Smarty_Template_Compiled::load($this);
$this->loadCompiled();
}
$content = $this->compiled->render($this);
} else {
@@ -790,6 +790,45 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
}
}
/**
* Load compiled object
*
*/
public function loadCompiled()
{
if (!isset($this->compiled)) {
if (!class_exists('Smarty_Template_Compiled', false)) {
require SMARTY_SYSPLUGINS_DIR . 'smarty_template_compiled.php';
}
$this->compiled = Smarty_Template_Compiled::load($this);
}
}
/**
* Load cached object
*
*/
public function loadCached()
{
if (!isset($this->cached)) {
if (!class_exists('Smarty_Template_Cached', false)) {
require SMARTY_SYSPLUGINS_DIR . 'smarty_template_cached.php';
}
$this->cached = Smarty_Template_Cached::load($this);
}
}
/**
* Load compiler object
*
* @throws \SmartyException
*/
public function loadCompiler()
{
$this->smarty->loadPlugin($this->source->compiler_class);
$this->compiler = new $this->source->compiler_class($this->source->template_lexer_class, $this->source->template_parser_class, $this->smarty);
}
/**
* Handle unknown class methods
*
@@ -824,18 +863,14 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
case 'cached':
case 'compiler':
$this->$property_name = $value;
return;
// FIXME: routing of template -> smarty attributes
default:
// Smarty property ?
if (property_exists($this->smarty, $property_name)) {
$this->smarty->$property_name = $value;
return;
}
}
throw new SmartyException("invalid template property '$property_name'.");
}
@@ -855,26 +890,22 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
return $this->source;
case 'compiled':
$this->compiled = Smarty_Template_Compiled::load($this);
$this->loadCompiled();
return $this->compiled;
case 'cached':
$this->cached = Smarty_Template_Cached::load($this);
$this->loadCached();
return $this->cached;
case 'compiler':
$this->smarty->loadPlugin($this->source->compiler_class);
$this->compiler = new $this->source->compiler_class($this->source->template_lexer_class, $this->source->template_parser_class, $this->smarty);
$this->loadCompiler();
return $this->compiler;
// FIXME: routing of template -> smarty attributes
default:
default:
// Smarty property ?
if (property_exists($this->smarty, $property_name)) {
return $this->smarty->$property_name;
}
}
throw new SmartyException("template property '$property_name' does not exist.");
}

View File

@@ -67,6 +67,9 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
}
}
// return cache status of template
if (!isset($template->cached)) {
$template->loadCached();
}
return $template->cached->isCached($template);
}

View File

@@ -109,7 +109,13 @@ class Smarty_Template_Cached
{
$this->compile_id = $_template->compile_id;
$this->cache_id = $_template->cache_id;
if (!isset($_template->source)) {
$_template->loadSource();
}
$this->source = $_template->source;
if (!class_exists('Smarty_CacheResource', false)) {
require SMARTY_SYSPLUGINS_DIR . 'smarty_cacheresource.php';
}
$this->handler = Smarty_CacheResource::load($_template->smarty);
}

View File

@@ -62,6 +62,9 @@ class Smarty_Template_Compiled
*/
static function load($_template)
{
if (!isset($_template->source)) {
$_template->loadSource();
}
// check runtime cache
if (!$_template->source->recompiled && $_template->smarty->resource_caching) {
$_cache_key = $_template->source->unique_resource . '#';