- remove properties with redundant content

This commit is contained in:
uwetews
2015-08-23 01:46:30 +02:00
parent 87985d1243
commit 6eed7732df
9 changed files with 30 additions and 88 deletions

View File

@@ -9,6 +9,7 @@
- remove not really needed properties - remove not really needed properties
- optimize rendering - optimize rendering
- move caching to Smarty::_cache - move caching to Smarty::_cache
- remove properties with redundant content
06.08.2015 06.08.2015
- avoid possible circular object references caused by parser/lexer objects - avoid possible circular object references caused by parser/lexer objects

View File

@@ -119,7 +119,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
// flag if included template code should be merged into caller // flag if included template code should be merged into caller
$merge_compiled_includes = ($compiler->smarty->merge_compiled_includes || $merge_compiled_includes = ($compiler->smarty->merge_compiled_includes ||
($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes) || ($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes) ||
$_attr['inline'] === true) && !$compiler->template->source->recompiled; $_attr['inline'] === true) && !$compiler->template->source->handler->recompiled;
if ($merge_compiled_includes && $_attr['inline'] !== true) { if ($merge_compiled_includes && $_attr['inline'] !== true) {
// variable template name ? // variable template name ?
@@ -215,7 +215,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
if (!isset($compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid])) { if (!isset($compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid])) {
$compiler->smarty->allow_ambiguous_resources = true; $compiler->smarty->allow_ambiguous_resources = true;
$tpl = new $compiler->smarty->template_class ($tpl_name, $compiler->smarty, $compiler->template, $compiler->template->cache_id, $c_id, $_caching); $tpl = new $compiler->smarty->template_class ($tpl_name, $compiler->smarty, $compiler->template, $compiler->template->cache_id, $c_id, $_caching);
if (!($tpl->source->uncompiled) && $tpl->source->exists) { if (!($tpl->source->handler->uncompiled) && $tpl->source->exists) {
$tpl->compiled = new Smarty_Template_Compiled(); $tpl->compiled = new Smarty_Template_Compiled();
$tpl->compiled->nocache_hash = $compiler->parent_compiler->template->compiled->nocache_hash; $tpl->compiled->nocache_hash = $compiler->parent_compiler->template->compiled->nocache_hash;
$tpl->loadCompiler(); $tpl->loadCompiler();

View File

@@ -31,7 +31,7 @@ class Smarty_Internal_Method_MustCompile
public function mustCompile(Smarty_Internal_Template $_template) public function mustCompile(Smarty_Internal_Template $_template)
{ {
if (!$_template->source->exists) { if (!$_template->source->exists) {
if ($_template->parent instanceof Smarty_Internal_Template) { if ($_template->parent->_objType == 2) {
$parent_resource = " in '$_template->parent->template_resource}'"; $parent_resource = " in '$_template->parent->template_resource}'";
} else { } else {
$parent_resource = ''; $parent_resource = '';
@@ -39,8 +39,8 @@ class Smarty_Internal_Method_MustCompile
throw new SmartyException("Unable to load template {$_template->source->type} '{$_template->source->name}'{$parent_resource}"); throw new SmartyException("Unable to load template {$_template->source->type} '{$_template->source->name}'{$parent_resource}");
} }
if ($_template->mustCompile === null) { if ($_template->mustCompile === null) {
$_template->mustCompile = (!$_template->source->uncompiled && $_template->mustCompile = (!$_template->source->handler->uncompiled &&
($_template->smarty->force_compile || $_template->source->recompiled || !$_template->compiled->exists || ($_template->smarty->force_compile || $_template->source->handler->recompiled || !$_template->compiled->exists ||
($_template->smarty->compile_check && $_template->compiled->getTimeStamp() < $_template->source->getTimeStamp()))); ($_template->smarty->compile_check && $_template->compiled->getTimeStamp() < $_template->source->getTimeStamp())));
} }

View File

@@ -65,7 +65,7 @@ class Smarty_Internal_Method_RegisterDefaultTemplateHandler
$source->content = $_content; $source->content = $_content;
$source->timestamp = $_timestamp; $source->timestamp = $_timestamp;
$source->exists = true; $source->exists = true;
$source->recompiled = true; $source->handler->recompiled = true;
$source->filepath = false; $source->filepath = false;
} }
} }

View File

@@ -228,7 +228,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
} }
} }
$content = null; $content = null;
if ((!$this->caching || $this->cached->has_nocache_code || $this->source->recompiled) && !$no_output_filter && if ((!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled) && !$no_output_filter &&
(isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output'])) (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))
) { ) {
$content = Smarty_Internal_Filter_Handler::runFilter('output', ob_get_clean(), $this); $content = Smarty_Internal_Filter_Handler::runFilter('output', ob_get_clean(), $this);
@@ -390,9 +390,9 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
$_templateId = $this->smarty->_getTemplateId($template, $cache_id, $compile_id); $_templateId = $this->smarty->_getTemplateId($template, $cache_id, $compile_id);
// already in template cache? // already in template cache?
/* @var Smarty_Internal_Template $tpl */ /* @var Smarty_Internal_Template $tpl */
if (isset($this->smarty->template_objects[$_templateId])) { if (isset($this->smarty->_cache['template_objects'][$_templateId])) {
// clone cached template object because of possible recursive call // clone cached template object because of possible recursive call
$tpl = clone $this->smarty->template_objects[$_templateId]; $tpl = clone $this->smarty->_cache['template_objects'][$_templateId];
$tpl->parent = $this; $tpl->parent = $this;
if ((bool) $tpl->caching !== (bool) $caching) { if ((bool) $tpl->caching !== (bool) $caching) {
unset($tpl->compiled); unset($tpl->compiled);
@@ -752,10 +752,10 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
*/ */
public function loadCompiler() public function loadCompiler()
{ {
if (!class_exists($this->source->compiler_class)) { if (!class_exists($this->source->handler->compiler_class)) {
$this->smarty->loadPlugin($this->source->compiler_class); $this->smarty->loadPlugin($this->source->handler->compiler_class);
} }
$this->compiler = new $this->source->compiler_class($this->source->template_lexer_class, $this->source->template_parser_class, $this->smarty); $this->compiler = new $this->source->handler->compiler_class($this->source->handler->template_lexer_class, $this->source->handler->template_parser_class, $this->smarty);
} }
/** /**

View File

@@ -99,7 +99,7 @@ class Smarty_Template_Cached extends Smarty_Template_Resource_Base
$_template->cached->handler->populate($_template->cached, $_template); $_template->cached->handler->populate($_template->cached, $_template);
// caching enabled ? // caching enabled ?
if (!($_template->caching == Smarty::CACHING_LIFETIME_CURRENT || if (!($_template->caching == Smarty::CACHING_LIFETIME_CURRENT ||
$_template->caching == Smarty::CACHING_LIFETIME_SAVED) || $_template->source->recompiled $_template->caching == Smarty::CACHING_LIFETIME_SAVED) || $_template->source->handler->recompiled
) { ) {
$_template->cached->valid = false; $_template->cached->valid = false;
} }
@@ -265,7 +265,7 @@ class Smarty_Template_Cached extends Smarty_Template_Resource_Base
*/ */
public function write(Smarty_Internal_Template $_template, $content) public function write(Smarty_Internal_Template $_template, $content)
{ {
if (!$_template->source->recompiled) { if (!$_template->source->handler->recompiled) {
if ($this->handler->writeCachedContent($_template, $content)) { if ($this->handler->writeCachedContent($_template, $content)) {
$this->content = null; $this->content = null;
$this->timestamp = time(); $this->timestamp = time();
@@ -298,7 +298,7 @@ class Smarty_Template_Cached extends Smarty_Template_Resource_Base
*/ */
public function read(Smarty_Internal_Template $_template) public function read(Smarty_Internal_Template $_template)
{ {
if (!$_template->source->recompiled) { if (!$_template->source->handler->recompiled) {
return $this->handler->readCachedContent($_template); return $this->handler->readCachedContent($_template);
} }
return false; return false;
@@ -359,7 +359,7 @@ class Smarty_Template_Cached extends Smarty_Template_Resource_Base
*/ */
public function writeCachedContent(Smarty_Internal_Template $_template, $content) public function writeCachedContent(Smarty_Internal_Template $_template, $content)
{ {
if ($_template->source->recompiled || !($_template->caching == Smarty::CACHING_LIFETIME_CURRENT || if ($_template->source->handler->recompiled || !($_template->caching == Smarty::CACHING_LIFETIME_CURRENT ||
$_template->caching == Smarty::CACHING_LIFETIME_SAVED) $_template->caching == Smarty::CACHING_LIFETIME_SAVED)
) { ) {
// don't write cache file // don't write cache file

View File

@@ -36,7 +36,7 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
static function load($_template) static function load($_template)
{ {
// check runtime cache // check runtime cache
if (!$_template->source->recompiled && ($_template->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON)) { if (!$_template->source->handler->recompiled && ($_template->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON)) {
$_cache_key = $_template->source->unique_resource . '#'; $_cache_key = $_template->source->unique_resource . '#';
if ($_template->caching) { if ($_template->caching) {
$_cache_key .= 'caching#'; $_cache_key .= 'caching#';
@@ -53,7 +53,7 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
$compiled->populateCompiledFilepath($_template); $compiled->populateCompiledFilepath($_template);
} }
// runtime cache // runtime cache
if (!$_template->source->recompiled && ($_template->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON)) { if (!$_template->source->handler->recompiled && ($_template->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON)) {
$_template->source->compileds[$_cache_key] = $compiled; $_template->source->compileds[$_cache_key] = $compiled;
} }
return $compiled; return $compiled;
@@ -119,14 +119,14 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
public function process(Smarty_Internal_Template $_template) public function process(Smarty_Internal_Template $_template)
{ {
$_smarty_tpl = $_template; $_smarty_tpl = $_template;
if ($_template->source->recompiled || !$_template->compiled->exists || $_template->smarty->force_compile || if ($_template->source->handler->recompiled || !$_template->compiled->exists || $_template->smarty->force_compile ||
($_template->smarty->compile_check && ($_template->smarty->compile_check &&
$_template->source->getTimeStamp() > $_template->compiled->getTimeStamp()) $_template->source->getTimeStamp() > $_template->compiled->getTimeStamp())
) { ) {
$this->compileTemplateSource($_template); $this->compileTemplateSource($_template);
$compileCheck = $_template->smarty->compile_check; $compileCheck = $_template->smarty->compile_check;
$_template->smarty->compile_check = false; $_template->smarty->compile_check = false;
if ($_template->source->recompiled) { if ($_template->source->handler->recompiled) {
$level = ob_get_level(); $level = ob_get_level();
ob_start(); ob_start();
try { try {
@@ -236,7 +236,7 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
$this->nocache_hash = null; $this->nocache_hash = null;
$this->unifunc = null; $this->unifunc = null;
// compile locking // compile locking
if (!$_template->source->recompiled) { if (!$_template->source->handler->recompiled) {
if ($saved_timestamp = $_template->compiled->getTimeStamp()) { if ($saved_timestamp = $_template->compiled->getTimeStamp()) {
touch($_template->compiled->filepath); touch($_template->compiled->filepath);
} }
@@ -248,7 +248,7 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
} }
catch (Exception $e) { catch (Exception $e) {
// restore old timestamp in case of error // restore old timestamp in case of error
if (!$_template->source->recompiled && $saved_timestamp) { if (!$_template->source->handler->recompiled && $saved_timestamp) {
touch($_template->compiled->filepath, $saved_timestamp); touch($_template->compiled->filepath, $saved_timestamp);
} }
throw $e; throw $e;
@@ -274,7 +274,7 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
*/ */
public function write(Smarty_Internal_Template $_template, $code) public function write(Smarty_Internal_Template $_template, $code)
{ {
if (!$_template->source->recompiled) { if (!$_template->source->handler->recompiled) {
$obj = new Smarty_Internal_Write_File(); $obj = new Smarty_Internal_Write_File();
if ($obj->writeFile($this->filepath, $code, $_template->smarty) === true) { if ($obj->writeFile($this->filepath, $code, $_template->smarty) === true) {
$this->timestamp = $this->exists = is_file($this->filepath); $this->timestamp = $this->exists = is_file($this->filepath);
@@ -301,7 +301,7 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
*/ */
public function read(Smarty_Internal_Template $_template) public function read(Smarty_Internal_Template $_template)
{ {
if (!$_template->source->recompiled) { if (!$_template->source->handler->recompiled) {
return file_get_contents($this->filepath); return file_get_contents($this->filepath);
} }
return isset($this->content) ? $this->content : false; return isset($this->content) ? $this->content : false;

View File

@@ -18,27 +18,6 @@
*/ */
class Smarty_Template_Config extends Smarty_Template_Source class Smarty_Template_Config extends Smarty_Template_Source
{ {
/**
* Name of the Class to compile this resource's contents with
*
* @var string
*/
public $compiler_class = 'Smarty_Internal_Config_File_Compiler';
/**
* Name of the Class to tokenize this resource's contents with
*
* @var string
*/
public $template_lexer_class = 'Smarty_Internal_Configfilelexer';
/**
* Name of the Class to parse this resource's contents with
*
* @var string
*/
public $template_parser_class = 'Smarty_Internal_Configfileparser';
/** /**
* array of section names, single section or null * array of section names, single section or null
* *
@@ -71,7 +50,11 @@ class Smarty_Template_Config extends Smarty_Template_Source
*/ */
public function __construct(Smarty_Resource $handler, Smarty $smarty, $resource, $type, $name) public function __construct(Smarty_Resource $handler, Smarty $smarty, $resource, $type, $name)
{ {
$this->handler = $handler; // Note: prone to circular references // must clone handler as we change class names
$this->handler = clone $handler; // Note: prone to circular references
$this->handler->compiler_class = 'Smarty_Internal_Config_File_Compiler';
$this->handler->template_lexer_class = 'Smarty_Internal_Configfilelexer';
$this->handler->template_parser_class = 'Smarty_Internal_Configfileparser';
$this->resource = $resource; $this->resource = $resource;
$this->type = $type; $this->type = $type;
$this->name = $name; $this->name = $name;

View File

@@ -11,27 +11,6 @@
*/ */
class Smarty_Template_Source class Smarty_Template_Source
{ {
/**
* Name of the Class to compile this resource's contents with
*
* @var string
*/
public $compiler_class = null;
/**
* Name of the Class to tokenize this resource's contents with
*
* @var string
*/
public $template_lexer_class = null;
/**
* Name of the Class to parse this resource's contents with
*
* @var string
*/
public $template_parser_class = null;
/** /**
* Unique Template ID * Unique Template ID
* *
@@ -123,20 +102,6 @@ class Smarty_Template_Source
*/ */
public $isConfig = false; public $isConfig = false;
/**
* Source is bypassing compiler
*
* @var boolean
*/
public $uncompiled = false;
/**
* Source must be recompiled on every occasion
*
* @var boolean
*/
public $recompiled = false;
/** /**
* cache for Smarty_Template_Compiled instances * cache for Smarty_Template_Compiled instances
* *
@@ -165,13 +130,6 @@ class Smarty_Template_Source
public function __construct(Smarty_Resource $handler, Smarty $smarty, $resource, $type, $name) public function __construct(Smarty_Resource $handler, Smarty $smarty, $resource, $type, $name)
{ {
$this->handler = $handler; // Note: prone to circular references $this->handler = $handler; // Note: prone to circular references
$this->recompiled = $handler->recompiled;
$this->uncompiled = $handler->uncompiled;
$this->compiler_class = $handler->compiler_class;
$this->template_lexer_class = $handler->template_lexer_class;
$this->template_parser_class = $handler->template_parser_class;
$this->smarty = $smarty; $this->smarty = $smarty;
$this->resource = $resource; $this->resource = $resource;
$this->type = $type; $this->type = $type;