- fixed file dependency for config files

- some code optimizations
This commit is contained in:
Uwe.Tews
2009-10-21 15:19:00 +00:00
parent 4a68612a5a
commit 5fe16d23f0
8 changed files with 1081 additions and 1081 deletions

View File

@@ -2,6 +2,8 @@
- added {$foo++}{$foo--} syntax - added {$foo++}{$foo--} syntax
- buxfix changed PHP "if (..):" to "if (..){" because of possible bad code when concenating PHP tags - buxfix changed PHP "if (..):" to "if (..){" because of possible bad code when concenating PHP tags
- autoload Smarty internal classes - autoload Smarty internal classes
- fixed file dependency for config files
- some code optimizations
10/20/2009 10/20/2009
- check at compile time for variable filter to improve rendering speed if no filter is used - check at compile time for variable filter to improve rendering speed if no filter is used

View File

@@ -200,8 +200,6 @@ class Smarty extends Smarty_Internal_TemplateBase {
public $autoload_filters = array(); public $autoload_filters = array();
// status of filter on variable output // status of filter on variable output
public $variable_filter = true; public $variable_filter = true;
// cache resorce objects
public $cache_resource_objects = array();
// global internal smarty vars // global internal smarty vars
public $_smarty_vars = array(); public $_smarty_vars = array();
// start time for execution time calculation // start time for execution time calculation

View File

@@ -42,9 +42,9 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase {
$scope = '$_smarty_tpl->parent'; $scope = '$_smarty_tpl->parent';
} }
} }
// create config object // create config object
$_output = "<?php \$_smarty_tpl->smarty->loadPlugin('Smarty_Internal_Config');"; $_output = "<?php \$_config = new Smarty_Internal_Config($conf_file, \$_smarty_tpl->smarty, \$_smarty_tpl);";
$_output .= "\$_config = new Smarty_Internal_Config($conf_file, \$_smarty_tpl->smarty);";
$_output .= "\$_config->loadConfigVars($section, $scope); ?>"; $_output .= "\$_config->loadConfigVars($section, $scope); ?>";
return $_output; return $_output;
} }

View File

@@ -12,8 +12,9 @@
class Smarty_Internal_Config { class Smarty_Internal_Config {
static $config_objects = array(); static $config_objects = array();
public function __construct($config_resource, $smarty) public function __construct($config_resource, $smarty, $template = null)
{ {
$this->template = $template;
$this->smarty = $smarty; $this->smarty = $smarty;
$this->config_resource = $config_resource; $this->config_resource = $config_resource;
$this->config_resource_type = null; $this->config_resource_type = null;
@@ -223,6 +224,9 @@ class Smarty_Internal_Config {
*/ */
public function loadConfigVars ($sections = null, $scope) public function loadConfigVars ($sections = null, $scope)
{ {
if (isset($this->template)) {
$this->template->properties['file_dependency']['F' . abs(crc32($this->getConfigFilepath()))] = array($this->getConfigFilepath(), $this->getTimestamp());
}
$config_data = unserialize($this->getCompiledConfig()); $config_data = unserialize($this->getCompiledConfig());
// var_dump($config_data); // var_dump($config_data);
// copy global config vars // copy global config vars

View File

@@ -29,6 +29,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
public $template_resource = null; public $template_resource = null;
public $resource_type = null; public $resource_type = null;
public $resource_name = null; public $resource_name = null;
private $resource_object = null;
private $usesCompiler = null; private $usesCompiler = null;
private $isEvaluated = null; private $isEvaluated = null;
private $isExisting = null; private $isExisting = null;
@@ -52,7 +53,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
private $cached_filepath = null; private $cached_filepath = null;
private $cached_timestamp = null; private $cached_timestamp = null;
private $isCached = null; private $isCached = null;
public $cache_time = 0; public $cache_time = 0;
private $cache_resource_object = null;
// template variables // template variables
public $tpl_vars = array(); public $tpl_vars = array();
public $parent = null; public $parent = null;
@@ -98,13 +100,12 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
// Template resource // Template resource
$this->template_resource = $template_resource; $this->template_resource = $template_resource;
// parse resource name // parse resource name
if (!$this->parseResourceName ($template_resource, $this->resource_type, $this->resource_name, $dummy)) { if (!$this->parseResourceName ($template_resource, $this->resource_type, $this->resource_name, $this->resource_object)) {
throw new Exception ("Unable to parse resource name \"{$template_resource}\""); throw new Exception ("Unable to parse resource name \"{$template_resource}\"");
} }
// load cache resource // load cache resource
if (!$this->isEvaluated() && $this->caching && !isset($this->smarty->cache_resource_objects[$this->caching_type])) { if (!$this->isEvaluated() && $this->caching) {
$this->smarty->loadPlugin($this->cache_resource_class); $this->cache_resource_object = new $this->cache_resource_class($this->smarty);
$this->smarty->cache_resource_objects[$this->caching_type] = new $this->cache_resource_class($this->smarty);
} }
} }
@@ -118,7 +119,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
public function getTemplateFilepath () public function getTemplateFilepath ()
{ {
return $this->template_filepath === null ? return $this->template_filepath === null ?
$this->template_filepath = $this->smarty->resource_objects[$this->resource_type]->getTemplateFilepath($this) : $this->template_filepath = $this->resource_object->getTemplateFilepath($this) :
$this->template_filepath; $this->template_filepath;
} }
@@ -132,7 +133,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
public function getTemplateTimestamp () public function getTemplateTimestamp ()
{ {
return $this->template_timestamp === null ? return $this->template_timestamp === null ?
$this->template_timestamp = $this->smarty->resource_objects[$this->resource_type]->getTemplateTimestamp($this) : $this->template_timestamp = $this->resource_object->getTemplateTimestamp($this) :
$this->template_timestamp; $this->template_timestamp;
} }
@@ -146,7 +147,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
public function getTemplateSource () public function getTemplateSource ()
{ {
if ($this->template_source === null) { if ($this->template_source === null) {
if (!$this->smarty->resource_objects[$this->resource_type]->getTemplateSource($this)) { if (!$this->resource_object->getTemplateSource($this)) {
throw new Exception("Unable to read template {$this->resource_type} '{$this->resource_name}'"); throw new Exception("Unable to read template {$this->resource_type} '{$this->resource_name}'");
} }
} }
@@ -163,7 +164,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
public function isExisting ($error = false) public function isExisting ($error = false)
{ {
if ($this->isExisting === null) { if ($this->isExisting === null) {
$this->isExisting = $this->smarty->resource_objects[$this->resource_type]->isExisting($this); $this->isExisting = $this->resource_object->isExisting($this);
} }
if (!$this->isExisting && $error) { if (!$this->isExisting && $error) {
throw new Exception("Unable to load template {$this->resource_type} '{$this->resource_name}'"); throw new Exception("Unable to load template {$this->resource_type} '{$this->resource_name}'");
@@ -180,7 +181,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
public function usesCompiler () public function usesCompiler ()
{ {
return $this->usesCompiler === null ? return $this->usesCompiler === null ?
$this->usesCompiler = $this->smarty->resource_objects[$this->resource_type]->usesCompiler() : $this->usesCompiler = $this->resource_object->usesCompiler() :
$this->usesCompiler; $this->usesCompiler;
} }
@@ -194,7 +195,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
public function isEvaluated () public function isEvaluated ()
{ {
return $this->isEvaluated === null ? return $this->isEvaluated === null ?
$this->isEvaluated = $this->smarty->resource_objects[$this->resource_type]->isEvaluated() : $this->isEvaluated = $this->resource_object->isEvaluated() :
$this->isEvaluated; $this->isEvaluated;
} }
@@ -223,7 +224,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
public function getCompiledFilepath () public function getCompiledFilepath ()
{ {
return $this->compiled_filepath === null ? return $this->compiled_filepath === null ?
($this->compiled_filepath = !$this->isEvaluated() ? $this->smarty->resource_objects[$this->resource_type]->getCompiledFilepath($this) : false) : ($this->compiled_filepath = !$this->isEvaluated() ? $this->resource_object->getCompiledFilepath($this) : false) :
$this->compiled_filepath; $this->compiled_filepath;
} }
@@ -275,8 +276,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
// compile template // compile template
if (!is_object($this->compiler_object)) { if (!is_object($this->compiler_object)) {
// load compiler // load compiler
$this->smarty->loadPlugin($this->smarty->resource_objects[$this->resource_type]->compiler_class); $this->smarty->loadPlugin($this->resource_object->compiler_class);
$this->compiler_object = new $this->smarty->resource_objects[$this->resource_type]->compiler_class($this->smarty->resource_objects[$this->resource_type]->template_lexer_class, $this->smarty->resource_objects[$this->resource_type]->template_parser_class, $this->smarty); $this->compiler_object = new $this->resource_object->compiler_class($this->resource_object->template_lexer_class, $this->resource_object->template_parser_class, $this->smarty);
// load cacher // load cacher
if ($this->caching) { if ($this->caching) {
$this->smarty->loadPlugin($this->cacher_class); $this->smarty->loadPlugin($this->cacher_class);
@@ -310,7 +311,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
public function getCachedFilepath () public function getCachedFilepath ()
{ {
return $this->cached_filepath === null ? return $this->cached_filepath === null ?
$this->cached_filepath = ($this->isEvaluated() || !$this->caching) ? false : $this->smarty->cache_resource_objects[$this->caching_type]->getCachedFilepath($this) : $this->cached_filepath = ($this->isEvaluated() || !$this->caching) ? false : $this->cache_resource_object->getCachedFilepath($this) :
$this->cached_filepath; $this->cached_filepath;
} }
@@ -324,7 +325,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
public function getCachedTimestamp () public function getCachedTimestamp ()
{ {
return $this->cached_timestamp === null ? return $this->cached_timestamp === null ?
$this->cached_timestamp = ($this->isEvaluated() || !$this->caching) ? false : $this->smarty->cache_resource_objects[$this->caching_type]->getCachedTimestamp($this) : $this->cached_timestamp = ($this->isEvaluated() || !$this->caching) ? false : $this->cache_resource_object->getCachedTimestamp($this) :
$this->cached_timestamp; $this->cached_timestamp;
} }
@@ -336,7 +337,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
public function getCachedContent () public function getCachedContent ()
{ {
return $this->rendered_content === null ? return $this->rendered_content === null ?
$this->rendered_content = ($this->isEvaluated() || !$this->caching) ? false : $this->smarty->cache_resource_objects[$this->caching_type]->getCachedContents($this) : $this->rendered_content = ($this->isEvaluated() || !$this->caching) ? false : $this->cache_resource_object->getCachedContents($this) :
$this->rendered_content; $this->rendered_content;
} }
@@ -347,7 +348,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
{ {
// build file dependency string // build file dependency string
$this->properties['cache_lifetime'] = $this->cache_lifetime; $this->properties['cache_lifetime'] = $this->cache_lifetime;
return ($this->isEvaluated() || !$this->caching) ? false : $this->smarty->cache_resource_objects[$this->caching_type]->writeCachedContent($this, $this->createPropertyHeader() . $this->rendered_content); return ($this->isEvaluated() || !$this->caching) ? false : $this->cache_resource_object->writeCachedContent($this, $this->createPropertyHeader() . $this->rendered_content);
} }
/** /**
@@ -367,7 +368,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
} }
if (($this->caching == SMARTY_CACHING_LIVETIME_SAVED || ($this->caching == SMARTY_CACHING_LIFETIME_CURRENT && (time() <= ($this->getCachedTimestamp() + $this->cache_lifetime) || $this->cache_lifetime < 0)))) { if (($this->caching == SMARTY_CACHING_LIVETIME_SAVED || ($this->caching == SMARTY_CACHING_LIFETIME_CURRENT && (time() <= ($this->getCachedTimestamp() + $this->cache_lifetime) || $this->cache_lifetime < 0)))) {
$_start_time = $this->_get_time(); $_start_time = $this->_get_time();
$this->rendered_content = $this->smarty->cache_resource_objects[$this->caching_type]->getCachedContents($this); $this->rendered_content = $this->cache_resource_object->getCachedContents($this);
$this->cache_time += $this->_get_time() - $_start_time; $this->cache_time += $this->_get_time() - $_start_time;
if ($this->caching == SMARTY_CACHING_LIVETIME_SAVED && $this->properties['cache_lifetime'] >0 && (time() > ($this->getCachedTimestamp() + $this->properties['cache_lifetime']))) { if ($this->caching == SMARTY_CACHING_LIVETIME_SAVED && $this->properties['cache_lifetime'] >0 && (time() > ($this->getCachedTimestamp() + $this->properties['cache_lifetime']))) {
$this->rendered_content = null; $this->rendered_content = null;
@@ -446,10 +447,10 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
} }
} }
} else { } else {
if (is_callable(array($this->smarty->resource_objects[$this->resource_type], 'renderUncompiled'))) { if (is_callable(array($this->resource_object, 'renderUncompiled'))) {
$_start_time = $this->_get_time(); $_start_time = $this->_get_time();
ob_start(); ob_start();
$this->smarty->resource_objects[$this->resource_type]->renderUncompiled($this); $this->resource_object->renderUncompiled($this);
} else { } else {
throw new Exception("Resource '$this->resource_type' must have 'renderUncompiled' methode"); throw new Exception("Resource '$this->resource_type' must have 'renderUncompiled' methode");
} }
@@ -468,7 +469,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
// write rendered template // write rendered template
$this->writeCachedContent($this); $this->writeCachedContent($this);
// cache file may contain nocache code. read it back for processing // cache file may contain nocache code. read it back for processing
$this->rendered_content = $this->smarty->cache_resource_objects[$this->caching_type]->getCachedContents($this); $this->rendered_content = $this->cache_resource_object->getCachedContents($this);
} }
} }

File diff suppressed because it is too large Load Diff

View File

@@ -24,15 +24,13 @@
function clear_cache($smarty, $template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = 'file') function clear_cache($smarty, $template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = 'file')
{ {
// load cache resource // load cache resource
if (!isset($smarty->cache_resource_objects[$type])) { $_cache_resource_class = 'Smarty_Internal_CacheResource_' . $type;
$_cache_resource_class = 'Smarty_Internal_CacheResource_' . $type; if (!$smarty->loadPlugin($_cache_resource_class)) {
if (!$smarty->loadPlugin($_cache_resource_class)) { throw new Exception("Undefined cache resource type {$type}");
throw new Exception("Undefined cache resource type {$type}");
}
$smarty->cache_resource_objects[$type] = new $_cache_resource_class($smarty);
} }
$cache_object = new $_cache_resource_class($smarty);
return $smarty->cache_resource_objects[$type]->clear($template_name, $cache_id, $compile_id, $exp_time); return $cache_object->clear($template_name, $cache_id, $compile_id, $exp_time);
} }
?> ?>

View File

@@ -20,7 +20,6 @@
function config_load($smarty, $config_file, $sections = null) function config_load($smarty, $config_file, $sections = null)
{ {
// load Config class // load Config class
$smarty->loadPlugin('Smarty_Internal_Config');
$config = new Smarty_Internal_Config($config_file, $smarty); $config = new Smarty_Internal_Config($config_file, $smarty);
$config->loadConfigVars($sections, $smarty); $config->loadConfigVars($sections, $smarty);
} }