converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs.

This commit is contained in:
Simon Wisselink
2023-01-13 00:04:08 +01:00
parent 541f0821f0
commit e0f2c36d4d
49 changed files with 723 additions and 922 deletions

View File

@@ -4,7 +4,6 @@ Smarty Class Variables {#api.variables}
These are all of the available Smarty class variables. You can access
them directly, or use the corresponding setter/getter methods.
- [$allow_php_templates](./api-variables/variable-allow-php-templates.md)
- [$auto_literal](./api-variables/variable-auto-literal.md)
- [$cache_dir](./api-variables/variable-cache-dir.md)
- [$cache_id](./api-variables/variable-cache-id.md)

View File

@@ -1,18 +0,0 @@
\$allow\_php\_templates {#variable.allow.php.templates}
=======================
By default the PHP template file resource is disabled. Setting
`$allow_php_templates` to TRUE will enable PHP template files.
::: {.informalexample}
<?php
$smarty->allow_php_templates = true;
?>
:::
> **Note**
>
> The PHP template file resource is an undocumented deprecated feature.

View File

@@ -85,9 +85,9 @@ abstract class Base
*/
public function getCachedContent(Template $_template)
{
if ($_template->cached->handler->process($_template)) {
if ($_template->getCached()->handler->process($_template)) {
ob_start();
$unifunc = $_template->cached->unifunc;
$unifunc = $_template->getCached()->unifunc;
$unifunc($_template);
return ob_get_clean();
}

View File

@@ -143,13 +143,13 @@ abstract class Custom extends Base
$update = false
) {
if (!$cached) {
$cached = $_smarty_tpl->cached;
$cached = $_smarty_tpl->getCached();
}
$content = $cached->content ? $cached->content : null;
$timestamp = $cached->timestamp ? $cached->timestamp : null;
if ($content === null || !$timestamp) {
$this->fetch(
$_smarty_tpl->cached->filepath,
$_smarty_tpl->getCached()->filepath,
$_smarty_tpl->source->name,
$_smarty_tpl->cache_id,
$_smarty_tpl->compile_id,
@@ -176,7 +176,7 @@ abstract class Custom extends Base
public function storeCachedContent(Template $_template, $content)
{
return $this->save(
$_template->cached->filepath,
$_template->getCached()->filepath,
$_template->source->name,
$_template->cache_id,
$_template->compile_id,
@@ -194,11 +194,11 @@ abstract class Custom extends Base
*/
public function retrieveCachedContent(Template $_template)
{
$content = $_template->cached->content ?: null;
$content = $_template->getCached()->content ?: null;
if ($content === null) {
$timestamp = null;
$this->fetch(
$_template->cached->filepath,
$_template->getCached()->filepath,
$_template->source->name,
$_template->cache_id,
$_template->compile_id,

View File

@@ -108,12 +108,12 @@ class File extends Base
Cached $cached = null,
$update = false
) {
$_smarty_tpl->cached->valid = false;
$_smarty_tpl->getCached()->valid = false;
if ($update && defined('HHVM_VERSION')) {
eval('?>' . file_get_contents($_smarty_tpl->cached->filepath));
eval('?>' . file_get_contents($_smarty_tpl->getCached()->filepath));
return true;
} else {
return @include $_smarty_tpl->cached->filepath;
return @include $_smarty_tpl->getCached()->filepath;
}
}
@@ -128,15 +128,15 @@ class File extends Base
*/
public function storeCachedContent(Template $_template, $content)
{
if ($_template->smarty->writeFile($_template->cached->filepath, $content) === true) {
if ($_template->smarty->writeFile($_template->getCached()->filepath, $content) === true) {
if (function_exists('opcache_invalidate')
&& (!function_exists('ini_get') || strlen(ini_get('opcache.restrict_api'))) < 1
) {
opcache_invalidate($_template->cached->filepath, true);
opcache_invalidate($_template->getCached()->filepath, true);
} elseif (function_exists('apc_compile_file')) {
apc_compile_file($_template->cached->filepath);
apc_compile_file($_template->getCached()->filepath);
}
$cached = $_template->cached;
$cached = $_template->getCached();
$cached->timestamp = $cached->exists = is_file($cached->filepath);
if ($cached->exists) {
$cached->timestamp = filemtime($cached->filepath);
@@ -155,8 +155,8 @@ class File extends Base
*/
public function retrieveCachedContent(Template $_template)
{
if (is_file($_template->cached->filepath)) {
return file_get_contents($_template->cached->filepath);
if (is_file($_template->getCached()->filepath)) {
return file_get_contents($_template->getCached()->filepath);
}
return false;
}
@@ -213,7 +213,7 @@ class File extends Base
// remove from template cache
$tpl->source; // have the template registered before unset()
if ($tpl->source->exists) {
$_resourcename_parts = basename(str_replace('^', '/', $tpl->cached->filepath));
$_resourcename_parts = basename(str_replace('^', '/', $tpl->getCached()->filepath));
} else {
return 0;
}

View File

@@ -107,13 +107,13 @@ abstract class KeyValueStore extends Base
$update = false
) {
if (!$cached) {
$cached = $_smarty_tpl->cached;
$cached = $_smarty_tpl->getCached();
}
$content = $cached->content ?: null;
$timestamp = $cached->timestamp ?: null;
if ($content === null || !$timestamp) {
if (!$this->fetch(
$_smarty_tpl->cached->filepath,
$_smarty_tpl->getCached()->filepath,
$_smarty_tpl->source->name,
$_smarty_tpl->cache_id,
$_smarty_tpl->compile_id,
@@ -143,7 +143,7 @@ abstract class KeyValueStore extends Base
public function storeCachedContent(Template $_template, $content)
{
$this->addMetaTimestamp($content);
return $this->write(array($_template->cached->filepath => $content), $_template->cache_lifetime);
return $this->write(array($_template->getCached()->filepath => $content), $_template->cache_lifetime);
}
/**
@@ -155,11 +155,11 @@ abstract class KeyValueStore extends Base
*/
public function retrieveCachedContent(Template $_template)
{
$content = $_template->cached->content ? $_template->cached->content : null;
$content = $_template->getCached()->content ?: null;
$timestamp = null;
if ($content === null) {
if (!$this->fetch(
$_template->cached->filepath,
$_template->getCached()->filepath,
$_template->source->name,
$_template->cache_id,
$_template->compile_id,

View File

@@ -83,13 +83,13 @@ class Block extends Inheritance {
'block',
[
$_attr, $compiler->nocache, $compiler->parser->current_buffer,
$compiler->template->compiled->has_nocache_code,
$compiler->template->getCompiled()->getNocacheCode(),
$compiler->template->caching,
]
);
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
$compiler->parser->current_buffer = new Template();
$compiler->template->compiled->has_nocache_code = false;
$compiler->template->getCompiled()->setNocacheCode(false);
$compiler->suppressNocacheProcessing = true;
}
}

View File

@@ -45,8 +45,8 @@ class BlockClose extends Inheritance {
$output .= "public \${$property} = " . var_export($value, true) . ";\n";
}
$output .= "public function callBlock(\\Smarty\\Template \$_smarty_tpl) {\n";
if ($compiler->template->compiled->has_nocache_code) {
$output .= "\$_smarty_tpl->cached->hashes['{$compiler->template->compiled->nocache_hash}'] = true;\n";
if ($compiler->template->getCompiled()->getNocacheCode()) {
$output .= "\$_smarty_tpl->getCached()->hashes['{$compiler->template->getCompiled()->nocache_hash}'] = true;\n";
}
if (isset($_assign)) {
$output .= "ob_start();\n";
@@ -78,7 +78,7 @@ class BlockClose extends Inheritance {
$compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
$compiler->parser->current_buffer = new Template();
// restore old status
$compiler->template->compiled->has_nocache_code = $_has_nocache_code;
$compiler->template->getCompiled()->setNocacheCode($_has_nocache_code);
$compiler->tag_nocache = $compiler->nocache;
$compiler->nocache = $_nocache;
$compiler->parser->current_buffer = $_buffer;

View File

@@ -41,7 +41,7 @@ class FunctionClose extends Base {
$_attr = $saved_data[0];
$_name = trim($_attr['name'], '\'"');
$compiler->parent_compiler->tpl_function[$_name]['compiled_filepath'] =
$compiler->parent_compiler->template->compiled->filepath;
$compiler->parent_compiler->template->getCompiled()->filepath;
$compiler->parent_compiler->tpl_function[$_name]['uid'] = $compiler->template->source->uid;
$_parameter = $_attr;
unset($_parameter['name']);
@@ -56,22 +56,22 @@ class FunctionClose extends Base {
$_functionCode = $compiler->parser->current_buffer;
// setup buffer for template function code
$compiler->parser->current_buffer = new \Smarty\ParseTree\Template();
$_funcName = "smarty_template_function_{$_name}_{$compiler->template->compiled->nocache_hash}";
$_funcName = "smarty_template_function_{$_name}_{$compiler->template->getCompiled()->nocache_hash}";
$_funcNameCaching = $_funcName . 'Smarty\Compile\Tag\Nocache';
if ($compiler->template->compiled->has_nocache_code) {
if ($compiler->template->getCompiled()->getNocacheCode()) {
$compiler->parent_compiler->tpl_function[$_name]['call_name_caching'] = $_funcNameCaching;
$output = "<?php\n";
$output .= $compiler->cStyleComment(" {$_funcNameCaching} ") . "\n";
$output .= "if (!function_exists('{$_funcNameCaching}')) {\n";
$output .= "function {$_funcNameCaching} (\\Smarty\\Template \$_smarty_tpl,\$params) {\n";
$output .= "ob_start();\n";
$output .= "\$_smarty_tpl->compiled->has_nocache_code = true;\n";
$output .= "\$_smarty_tpl->getCompiled()->setNocacheCode(true);\n";
$output .= $_paramsCode;
$output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->assign(\$key, \$value);\n}\n";
$output .= "\$params = var_export(\$params, true);\n";
$output .= "echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php ";
$output .= "echo \"/*%%SmartyNocache:{$compiler->template->getCompiled()->nocache_hash}%%*/<?php ";
$output .= "\\\$_smarty_tpl->smarty->getRuntime('TplFunction')->saveTemplateVariables(\\\$_smarty_tpl, '{$_name}');\nforeach (\$params as \\\$key => \\\$value) {\n\\\$_smarty_tpl->assign(\\\$key, \\\$value);\n}\n?>";
$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\";?>";
$output .= "/*/%%SmartyNocache:{$compiler->template->getCompiled()->nocache_hash}%%*/\";?>";
$compiler->parser->current_buffer->append_subtree(
$compiler->parser,
new \Smarty\ParseTree\Tag(
@@ -80,10 +80,10 @@ class FunctionClose extends Base {
)
);
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
$output = "<?php echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php ";
$output = "<?php echo \"/*%%SmartyNocache:{$compiler->template->getCompiled()->nocache_hash}%%*/<?php ";
$output .= "\\\$_smarty_tpl->smarty->getRuntime('TplFunction')->restoreTemplateVariables(\\\$_smarty_tpl, '{$_name}');?>\n";
$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\";\n?>";
$output .= "<?php echo str_replace('{$compiler->template->compiled->nocache_hash}', \$_smarty_tpl->compiled->nocache_hash ?? '', ob_get_clean());\n";
$output .= "/*/%%SmartyNocache:{$compiler->template->getCompiled()->nocache_hash}%%*/\";\n?>";
$output .= "<?php echo str_replace('{$compiler->template->getCompiled()->nocache_hash}', \$_smarty_tpl->getCompiled()->nocache_hash ?? '', ob_get_clean());\n";
$output .= "}\n}\n";
$output .= $compiler->cStyleComment("/ {$_funcName}_nocache ") . "\n\n";
$output .= "?>\n";
@@ -97,7 +97,7 @@ class FunctionClose extends Base {
$_functionCode = new \Smarty\ParseTree\Tag(
$compiler->parser,
preg_replace_callback(
"/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/",
"/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->getCompiled()->nocache_hash}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->getCompiled()->nocache_hash}%%\*\/';(\?>\n)?)/",
[$this, 'removeNocache'],
$_functionCode->to_smarty_php($compiler->parser)
)
@@ -133,7 +133,7 @@ class FunctionClose extends Base {
// restore old buffer
$compiler->parser->current_buffer = $saved_data[1];
// restore old status
$compiler->template->compiled->has_nocache_code = $saved_data[2];
$compiler->template->getCompiled()->setNocacheCode($saved_data[2]);
$compiler->template->caching = $saved_data[3];
return true;
}
@@ -148,7 +148,7 @@ class FunctionClose extends Base {
public function removeNocache($match) {
$code =
preg_replace(
"/((<\?php )?echo '\/\*%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/)|(\/\*\/%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/",
"/((<\?php )?echo '\/\*%%SmartyNocache:{$this->compiler->template->getCompiled()->nocache_hash}%%\*\/)|(\/\*\/%%SmartyNocache:{$this->compiler->template->getCompiled()->nocache_hash}%%\*\/';(\?>\n)?)/",
'',
$match[0]
);

View File

@@ -60,13 +60,13 @@ class FunctionTag extends Base {
$compiler->parent_compiler->tpl_function[$_name] = [];
$save = [
$_attr, $compiler->parser->current_buffer, $compiler->template->compiled->has_nocache_code,
$_attr, $compiler->parser->current_buffer, $compiler->template->getCompiled()->getNocacheCode(),
$compiler->template->caching,
];
$this->openTag($compiler, 'function', $save);
// Init temporary context
$compiler->parser->current_buffer = new \Smarty\ParseTree\Template();
$compiler->template->compiled->has_nocache_code = false;
$compiler->template->getCompiled()->setNocacheCode(false);
return true;
}
}

View File

@@ -24,11 +24,6 @@ use Smarty\Template\Compiled;
*/
class IncludeTag extends Base {
/**
* caching mode to create nocache code but no cache file
*/
private const CACHING_NOCACHE_CODE = 9999;
/**
* Attribute definition: Overwrites base class.
*
@@ -90,7 +85,7 @@ class IncludeTag extends Base {
if (!$variable_template) {
if ($type !== 'string') {
$fullResourceName = "{$type}:{$name}";
$compiled = $compiler->parent_compiler->template->compiled;
$compiled = $compiler->parent_compiler->template->getCompiled();
if (isset($compiled->includes[$fullResourceName])) {
$compiled->includes[$fullResourceName]++;
$cache_tpl = true;
@@ -122,7 +117,7 @@ class IncludeTag extends Base {
$call_nocache = $compiler->tag_nocache || $compiler->nocache;
// caching was on and {include} is not in nocache mode
if ($compiler->template->caching && !$compiler->nocache && !$compiler->tag_nocache) {
$_caching = self::CACHING_NOCACHE_CODE;
$_caching = \Smarty\Template::CACHING_NOCACHE_CODE;
}
// flag if included template code should be merged into caller
$merge_compiled_includes = ($compiler->smarty->merge_compiled_includes || $_attr['inline'] === true) &&
@@ -187,26 +182,28 @@ class IncludeTag extends Base {
}
$has_compiled_template = false;
if ($merge_compiled_includes) {
$c_id = isset($_attr['compile_id']) ? $_attr['compile_id'] : $compiler->template->compile_id;
$c_id = $_attr['compile_id'] ?? $compiler->template->compile_id;
// we must observe different compile_id and caching
$t_hash = sha1($c_id . ($_caching ? '--caching' : '--nocaching'));
$compiler->smarty->allow_ambiguous_resources = true;
/* @var \Smarty\Template $tpl */
$tpl = new \Smarty\Template(
$compiler->smarty->setAllowAmbiguousResources(true);
$tpl = $compiler->smarty->createTemplate(
trim($fullResourceName, '"\''),
$compiler->smarty,
$compiler->template,
$compiler->template->cache_id,
$c_id,
$compiler->template,
$_caching
);
$uid = $tpl->source->type . $tpl->source->uid;
if (!isset($compiler->parent_compiler->mergedSubTemplatesData[$uid][$t_hash])) {
$has_compiled_template = $this->compileInlineTemplate($compiler, $tpl, $t_hash);
} else {
$has_compiled_template = true;
}
unset($tpl);
$compiler->smarty->setAllowAmbiguousResources(false);
}
// delete {include} standard attributes
unset($_attr['file'], $_attr['assign'], $_attr['cache_id'], $_attr['compile_id'], $_attr['cache_lifetime'], $_attr['nocache'], $_attr['caching'], $_attr['scope'], $_attr['inline']);
@@ -227,7 +224,7 @@ class IncludeTag extends Base {
if ($update_compile_id) {
$_output .= $compiler->makeNocacheCode("\$_compile_id_save[] = \$_smarty_tpl->compile_id;\n\$_smarty_tpl->compile_id = {$_compile_id};\n");
}
if (!empty($_attr) && $_caching === 9999 && $compiler->template->caching) {
if (!empty($_attr) && $_caching === \Smarty\Template::CACHING_NOCACHE_CODE && $compiler->template->caching) {
$_vars_nc = "foreach ($_vars as \$ik => \$iv) {\n";
$_vars_nc .= "\$_smarty_tpl->assign(\$ik, \$iv);\n";
$_vars_nc .= "}\n";
@@ -287,16 +284,14 @@ class IncludeTag extends Base {
$uid = $tpl->source->type . $tpl->source->uid;
if ($tpl->source->exists) {
$compiler->parent_compiler->mergedSubTemplatesData[$uid][$t_hash]['uid'] = $tpl->source->uid;
$tpl->compiled = new Compiled();
$tpl->compiled->nocache_hash = $compiler->parent_compiler->template->compiled->nocache_hash;
$tpl->loadCompiler();
$tpl->getCompiled(true)->nocache_hash = $compiler->parent_compiler->template->getCompiled()->nocache_hash;
// save unique function name
$compiler->parent_compiler->mergedSubTemplatesData[$uid][$t_hash]['func'] =
$tpl->compiled->unifunc = 'content_' . str_replace(['.', ','], '_', uniqid('', true));
$tpl->getCompiled()->unifunc = 'content_' . str_replace(['.', ','], '_', uniqid('', true));
// make sure whole chain gets compiled
$tpl->mustCompile = true;
$compiler->parent_compiler->mergedSubTemplatesData[$uid][$t_hash]['nocache_hash'] =
$tpl->compiled->nocache_hash;
$tpl->getCompiled()->nocache_hash;
if ($tpl->source->type === 'file') {
$sourceInfo = $tpl->source->filepath;
} else {
@@ -307,26 +302,28 @@ class IncludeTag extends Base {
// get compiled code
$compiled_code = "<?php\n\n";
$compiled_code .= $compiler->cStyleComment(" Start inline template \"{$sourceInfo}\" =============================") . "\n";
$compiled_code .= "function {$tpl->compiled->unifunc} (\\Smarty\\Template \$_smarty_tpl) {\n";
$compiled_code .= "?>\n" . $tpl->compiler->compileTemplateSource($tpl, null, $compiler->parent_compiler);
$compiled_code .= "function {$tpl->getCompiled()->unifunc} (\\Smarty\\Template \$_smarty_tpl) {\n";
$compiled_code .= "?>\n" . $tpl->getCompiler()->compileTemplateSource($tpl, null, $compiler->parent_compiler);
$compiled_code .= "<?php\n";
$compiled_code .= "}\n?>\n";
$compiled_code .= $tpl->smarty->runPostFilters($tpl->compiler->blockOrFunctionCode, $tpl);
$compiled_code .= $tpl->smarty->runPostFilters($tpl->getCompiler()->blockOrFunctionCode, $tpl);
$compiled_code .= "<?php\n\n";
$compiled_code .= $compiler->cStyleComment(" End inline template \"{$sourceInfo}\" =============================") . "\n";
$compiled_code .= '?>';
unset($tpl->compiler);
if ($tpl->compiled->has_nocache_code) {
// unset($tpl->compiler); // @TODO removed this.
if ($tpl->getCompiled()->getNocacheCode()) {
// replace nocache_hash
$compiled_code =
str_replace(
"{$tpl->compiled->nocache_hash}",
$compiler->template->compiled->nocache_hash,
"{$tpl->getCompiled()->nocache_hash}",
$compiler->template->getCompiled()->nocache_hash,
$compiled_code
);
$compiler->template->compiled->has_nocache_code = true;
$compiler->template->getCompiled()->setNocacheCode(true);
}
$compiler->parent_compiler->mergedSubTemplatesCode[$tpl->compiled->unifunc] = $compiled_code;
$compiler->parent_compiler->mergedSubTemplatesCode[$tpl->getCompiled()->unifunc] = $compiled_code;
return true;
} else {
return false;

View File

@@ -55,7 +55,7 @@ class MakeNocache extends Base {
$_attr = $this->getAttributes($compiler, $args);
if ($compiler->template->caching) {
$output = "<?php \$_smarty_tpl->smarty->getRuntime('MakeNocache')->save(\$_smarty_tpl, {$_attr[ 'var' ]});\n?>\n";
$compiler->template->compiled->has_nocache_code = true;
$compiler->template->getCompiled()->setNocacheCode(true);
$compiler->suppressNocacheProcessing = true;
return $output;
} else {

View File

@@ -47,12 +47,12 @@ class CodeFrame
$properties[ 'version' ] = \Smarty\Smarty::SMARTY_VERSION;
$properties[ 'unifunc' ] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
if (!$cache) {
$properties[ 'has_nocache_code' ] = $this->_template->compiled->has_nocache_code;
$properties[ 'file_dependency' ] = $this->_template->compiled->file_dependency;
$properties[ 'includes' ] = $this->_template->compiled->includes;
$properties[ 'has_nocache_code' ] = $this->_template->getCompiled()->getNocacheCode();
$properties[ 'file_dependency' ] = $this->_template->getCompiled()->file_dependency;
$properties[ 'includes' ] = $this->_template->getCompiled()->includes;
} else {
$properties[ 'has_nocache_code' ] = $this->_template->cached->has_nocache_code;
$properties[ 'file_dependency' ] = $this->_template->cached->file_dependency;
$properties[ 'has_nocache_code' ] = $this->_template->getCached()->getNocacheCode();
$properties[ 'file_dependency' ] = $this->_template->getCached()->file_dependency;
$properties[ 'cache_lifetime' ] = $this->_template->cache_lifetime;
}
$output = sprintf(

View File

@@ -82,7 +82,7 @@ class Configfile extends BaseCompiler {
*/
public function compileTemplate(Template $template) {
$this->template = $template;
$this->template->compiled->file_dependency[$this->template->source->uid] =
$this->template->getCompiled()->file_dependency[$this->template->source->uid] =
[
$this->template->source->filepath,
$this->template->source->getTimeStamp(),

View File

@@ -394,22 +394,22 @@ class Template extends BaseCompiler {
}
$this->parent_compiler = $parent_compiler ? $parent_compiler : $this;
$nocache = isset($nocache) ? $nocache : false;
if (empty($template->compiled->nocache_hash)) {
$template->compiled->nocache_hash = $this->nocache_hash;
if (empty($template->getCompiled()->nocache_hash)) {
$template->getCompiled()->nocache_hash = $this->nocache_hash;
} else {
$this->nocache_hash = $template->compiled->nocache_hash;
$this->nocache_hash = $template->getCompiled()->nocache_hash;
}
$this->caching = $template->caching;
// flag for nocache sections
$this->nocache = $nocache;
$this->tag_nocache = false;
// reset has nocache code flag
$this->template->compiled->has_nocache_code = false;
$this->template->getCompiled()->setNocacheCode(false);
$this->has_variable_string = false;
$this->prefix_code = [];
// add file dependency
if ($this->smarty->merge_compiled_includes || $this->template->source->handler->checkTimestamps()) {
$this->parent_compiler->template->compiled->file_dependency[$this->template->source->uid] =
$this->parent_compiler->template->getCompiled()->file_dependency[$this->template->source->uid] =
[
$this->template->source->filepath,
$this->template->source->getTimeStamp(),
@@ -723,7 +723,7 @@ class Template extends BaseCompiler {
if ((!($this->template->source->handler->recompiled) || $this->forceNocache) && $this->caching
&& !$this->suppressNocacheProcessing && ($this->nocache || $this->tag_nocache)
) {
$this->template->compiled->has_nocache_code = true;
$this->template->getCompiled()->setNocacheCode(true);
$_output = addcslashes($content, '\'\\');
$_output = str_replace('^#^', '\'', $_output);
$_output =
@@ -1238,7 +1238,7 @@ class Template extends BaseCompiler {
$this
);
if ($isTemplateSource && $this->template->caching) {
$this->parser->insertPhpCode("<?php\n\$_smarty_tpl->compiled->nocache_hash = '{$this->nocache_hash}';\n?>\n");
$this->parser->insertPhpCode("<?php\n\$_smarty_tpl->getCompiled()->nocache_hash = '{$this->nocache_hash}';\n?>\n");
}
if (function_exists('mb_internal_encoding')
&& function_exists('ini_get')

View File

@@ -2,13 +2,11 @@
namespace Smarty;
use Smarty\Template\Config;
/**
* Smarty Internal Plugin Data
* This file contains the basic properties and methods for holding config and template variables
*/
abstract class Data
class Data
{
/**
@@ -49,6 +47,31 @@ abstract class Data
*/
public $config_vars = array();
/**
* create Smarty data object
*
* @param Smarty|array $_parent parent template
* @param Smarty|Template $smarty global smarty instance
* @param string $name optional data block name
*
* @throws Exception
*/
public function __construct($_parent = null, $smarty = null, $name = null) {
$this->smarty = $smarty;
if (is_object($_parent)) {
// when object set up back pointer
$this->parent = $_parent;
} elseif (is_array($_parent)) {
// set up variable values
foreach ($_parent as $_key => $_val) {
$this->assign($_key, $_val);
}
} elseif ($_parent !== null) {
throw new Exception('Wrong type for template variables');
}
}
/**
* assigns a Smarty variable
*
@@ -66,6 +89,7 @@ abstract class Data
foreach ($tpl_var as $_key => $_val) {
$this->assign($_key, $_val, $nocache, $scope);
}
return;
}
switch ($scope) {
@@ -363,6 +387,14 @@ abstract class Data
return $returnValue;
}
public function hasConfigVariable($varName): bool {
try {
return $this->getConfigVariable($varName) !== null;
} catch (Exception $e) {
return false;
}
}
/**
* Returns a single or all config variables
*
@@ -399,12 +431,11 @@ abstract class Data
public function configLoad($config_file, $sections = null)
{
$smarty = $this->_getSmartyObj();
$template = new Template($config_file, $smarty, $this, null, null, null, null, true);
$template = new Template($config_file, $smarty, $this, null, null, null, true);
$template->caching = Smarty::CACHING_OFF;
$template->assign('sections', (array) $sections ?? []);
// trigger a call to $this->assignConfigVars
$template->compiled = \Smarty\Template\Compiled::load($template);
$template->compiled->render($template);
$template->getCompiled(true)->render($template);
return $this;
}

View File

@@ -1,53 +0,0 @@
<?php
/**
* Smarty Plugin Data
* This file contains the data object
*
* @author Uwe Tews
*/
namespace Smarty;
/**
* class for the Smarty data object
* The Smarty data object will hold Smarty variables in the current scope
*
*/
class DataObject extends Data {
/**
* Smarty object
*
* @var Smarty
*/
public $smarty = null;
/**
* create Smarty data object
*
* @param Smarty|array $_parent parent template
* @param Smarty|Template $smarty global smarty instance
* @param string $name optional data block name
*
* @throws Exception
*/
public function __construct($_parent = null, $smarty = null, $name = null) {
$this->smarty = $smarty;
if (is_object($_parent)) {
// when object set up back pointer
$this->parent = $_parent;
} elseif (is_array($_parent)) {
// set up variable values
foreach ($_parent as $_key => $_val) {
$this->assign($_key, $_val);
}
} elseif ($_parent !== null) {
throw new Exception('Wrong type for template variables');
}
}
}

View File

@@ -84,8 +84,8 @@ class Debug extends Data
public function start_compile(\Smarty\Template $template)
{
static $_is_stringy = array('string' => true, 'eval' => true);
if (!empty($template->compiler->trace_uid)) {
$key = $template->compiler->trace_uid;
if (!empty($template->getCompiler()->trace_uid)) {
$key = $template->getCompiler()->trace_uid;
if (!isset($this->template_data[ $this->index ][ $key ])) {
$this->saveTemplateData($_is_stringy, $template, $key);
}
@@ -105,8 +105,8 @@ class Debug extends Data
*/
public function end_compile(\Smarty\Template $template)
{
if (!empty($template->compiler->trace_uid)) {
$key = $template->compiler->trace_uid;
if (!empty($template->getCompiler()->trace_uid)) {
$key = $template->getCompiler()->trace_uid;
} else {
if (isset($this->ignore_uid[ $template->source->uid ])) {
return;
@@ -223,7 +223,7 @@ class Debug extends Data
$_config_vars = $ptr->config_vars;
ksort($_config_vars);
$debugging = $smarty->debugging;
$_template = new \Smarty\Template($debObj->debug_tpl, $debObj);
$_template = $debObj->createTemplate($debObj->debug_tpl);
if ($obj instanceof \Smarty\Template) {
$_template->assign('template_name', $obj->source->type . ':' . $obj->source->name);
} elseif ($obj instanceof Smarty || $full) {
@@ -248,7 +248,7 @@ class Debug extends Data
/**
* Recursively gets variables from all template/data scopes
*
* @param \Smarty\Template|\Smarty\DataObject $obj object to debug
* @param \Smarty\Data $obj object to debug
*
* @return \StdClass
*/

View File

@@ -4,24 +4,11 @@ namespace Smarty\Resource;
use Smarty\Smarty;
/**
* Smarty Resource Plugin
*
* @author Rodney Rehm
*/
/**
* Smarty Resource Plugin
* Base implementation for resource plugins
*
*
* @method renderUncompiled(\Smarty\Template\Source $source, \Smarty\Template $_template)
* @method populateCompiledFilepath(\Smarty\Template\Compiled $compiled, \Smarty\Template $_template)
* @method process(\Smarty\Template $_smarty_tpl)
* @author Rodney Rehm
*/
abstract class BasePlugin
{
@@ -46,11 +33,13 @@ abstract class BasePlugin
public $recompiled = false;
/**
* Flag if resource does implement populateCompiledFilepath() method
* Flag if resource does allow compilation
*
* @var bool
* @return bool
*/
public $hasCompiledHandler = false;
public function supportsCompiledTemplates(): bool {
return true;
}
/**
* Load Resource Handler
@@ -119,30 +108,6 @@ abstract class BasePlugin
return array($name, $type);
}
/**
* modify template_resource according to resource handlers specifications
*
* @param \Smarty\Template|null $template Smarty instance
* @param string $template_resource template_resource to extract resource handler and
* name of
*
* @return string unique resource name
* @throws \Smarty\Exception
*/
public static function getUniqueTemplateName($smarty, $template, $template_resource)
{
[$name, $type] = self::parseResourceName($template_resource, $smarty->default_resource_type);
// TODO: optimize for Smarty's internal resource types
$resource = BasePlugin::load($smarty, $type);
// go relative to a given template?
$_file_is_dotted = $name[ 0 ] === '.' && ($name[ 1 ] === '.' || $name[ 1 ] === '/');
if ($template && $_file_is_dotted && ($template->source->type === 'file' || $template->parent->source->type === 'extends')
) {
$name = $smarty->_realpath(dirname($template->parent->source->filepath) . DIRECTORY_SEPARATOR . $name);
}
return $resource->buildUniqueResourceName($smarty, $name);
}
/**
* initialize Source Object for given resource
* wrapper for backward compatibility to versions < 3.1.22
@@ -191,30 +156,6 @@ abstract class BasePlugin
// intentionally left blank
}
/**
* modify resource_name according to resource handlers specifications
*
* @param Smarty $smarty Smarty instance
* @param string $resource_name resource_name to make unique
* @param boolean $isConfig flag for config resource
*
* @return string unique resource name
*/
public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false)
{
if ($isConfig) {
if (!isset($smarty->_joined_config_dir)) {
$smarty->getTemplateDir(null, true);
}
return get_class($this) . '#' . $smarty->_joined_config_dir . '#' . $resource_name;
} else {
if (!isset($smarty->_joined_template_dir)) {
$smarty->getTemplateDir();
}
return get_class($this) . '#' . $smarty->_joined_template_dir . '#' . $resource_name;
}
}
/*
* Check if resource must check time stamps when when loading complied or cached templates.
* Resources like 'extends' which use source components my disable timestamp checks on own resource.

View File

@@ -30,11 +30,13 @@ abstract class RecompiledPlugin extends BasePlugin {
public $recompiled = true;
/**
* Resource does implement populateCompiledFilepath() method
* Flag if resource does allow compilation
*
* @var bool
* @return bool
*/
public $hasCompiledHandler = true;
public function supportsCompiledTemplates(): bool {
return false;
}
/**
* compile template from source
@@ -44,45 +46,27 @@ abstract class RecompiledPlugin extends BasePlugin {
* @throws Exception
*/
public function process(Template $_smarty_tpl) {
$compiled = &$_smarty_tpl->compiled;
$compiled = $_smarty_tpl->getCompiled();
$compiled->file_dependency = [];
$compiled->includes = [];
$compiled->nocache_hash = null;
$compiled->unifunc = null;
$level = ob_get_level();
ob_start();
$_smarty_tpl->loadCompiler();
// call compiler
try {
eval('?>' . $_smarty_tpl->compiler->compileTemplate($_smarty_tpl));
eval('?>' . $_smarty_tpl->getCompiler()->compileTemplate($_smarty_tpl));
} catch (\Exception $e) {
unset($_smarty_tpl->compiler);
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
}
// release compiler object to free memory
unset($_smarty_tpl->compiler);
ob_get_clean();
$compiled->timestamp = time();
$compiled->exists = true;
}
/**
* populate Compiled Object with compiled filepath
*
* @param Compiled $compiled compiled object
* @param Template $_template template object
*
* @return void
*/
public function populateCompiledFilepath(Compiled $compiled, Template $_template) {
$compiled->filepath = false;
$compiled->timestamp = false;
$compiled->exists = false;
}
/*
* Disable timestamp checks for recompiled resource.
*

View File

@@ -66,16 +66,4 @@ class StreamPlugin extends RecompiledPlugin {
}
}
/**
* modify resource_name according to resource handlers specifications
*
* @param Smarty $smarty Smarty instance
* @param string $resource_name resource_name to make unique
* @param boolean $isConfig flag for config resource
*
* @return string unique resource name
*/
public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false) {
return get_class($this) . '#' . $resource_name;
}
}

View File

@@ -71,20 +71,6 @@ class StringEval extends RecompiledPlugin
return $string;
}
/**
* modify resource_name according to resource handlers specifications
*
* @param Smarty $smarty Smarty instance
* @param string $resource_name resource_name to make unique
* @param boolean $isConfig flag for config resource
*
* @return string unique resource name
*/
public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false)
{
return get_class($this) . '#' . $this->decode($resource_name);
}
/**
* Determine basename for compiled filename
*

View File

@@ -68,19 +68,6 @@ class StringPlugin extends BasePlugin {
return $string;
}
/**
* modify resource_name according to resource handlers specifications
*
* @param Smarty $smarty Smarty instance
* @param string $resource_name resource_name to make unique
* @param boolean $isConfig flag for config resource
*
* @return string unique resource name
*/
public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false) {
return get_class($this) . '#' . $this->decode($resource_name);
}
/**
* Determine basename for compiled filename
* Always returns an empty string.

View File

@@ -116,7 +116,7 @@ class InheritanceRuntime {
$template,
$tpl->cache_id,
$tpl->compile_id,
$tpl->caching ? 9999 : 0,
$tpl->caching ? \Smarty\Template::CACHING_NOCACHE_CODE : 0,
$tpl->cache_lifetime,
[],
$uid,

View File

@@ -28,9 +28,9 @@ class MakeNocacheRuntime {
if (preg_match('/(\w+)::__set_state/', $export, $match)) {
throw new \Smarty\Exception("{make_nocache \${$var}} in template '{$tpl->source->name}': variable does contain object '{$match[1]}' not implementing method '__set_state'");
}
echo "/*%%SmartyNocache:{$tpl->compiled->nocache_hash}%%*/<?php " .
echo "/*%%SmartyNocache:{$tpl->getCompiled()->nocache_hash}%%*/<?php " .
addcslashes("\$_smarty_tpl->smarty->getRuntime('MakeNocache')->store(\$_smarty_tpl, '{$var}', ", '\\') .
$export . ");?>\n/*/%%SmartyNocache:{$tpl->compiled->nocache_hash}%%*/";
$export . ");?>\n/*/%%SmartyNocache:{$tpl->getCompiled()->nocache_hash}%%*/";
}
}

View File

@@ -1,6 +1,7 @@
<?php
namespace Smarty\Runtime;
use Smarty\Exception;
use Smarty\Template;
use Smarty\TemplateBase;
@@ -98,8 +99,9 @@ class TplFunctionRuntime {
* @param string $_function PHP function name
*
* @return bool
* @throws Exception
*/
public function addTplFuncToCache(Template $tpl, $_name, $_function) {
private function addTplFuncToCache(Template $tpl, $_name, $_function) {
$funcParam = $tpl->tplFunctions[$_name];
if (is_file($funcParam['compiled_filepath'])) {
// read compiled file
@@ -112,32 +114,30 @@ class TplFunctionRuntime {
// make PHP function known
eval($match[0]);
if (function_exists($_function)) {
// search cache file template
$tplPtr = $tpl;
while (!isset($tplPtr->cached) && isset($tplPtr->parent)) {
$tplPtr = $tplPtr->parent;
}
// Some magic code existed here, testing if the cached property had been set
// and then bubbling up until it found a parent template that had the cached property.
// This is no longer possible, so somehow this might break.
// add template function code to cache file
if (isset($tplPtr->cached)) {
$content = $tplPtr->cached->readCache($tplPtr);
if ($content) {
// check if we must update file dependency
if (!preg_match("/'{$funcParam['uid']}'(.*?)'nocache_hash'/", $content, $match2)) {
$content = preg_replace("/('file_dependency'(.*?)\()/", "\\1{$match1[0]}", $content);
}
$tplPtr->cached->writeCache(
$tplPtr,
preg_replace('/\s*\?>\s*$/', "\n", $content) .
"\n" . preg_replace(
[
'/^\s*<\?php\s+/',
'/\s*\?>\s*$/',
],
"\n",
$match[0]
)
);
$content = $tpl->getCached()->readCache($tpl);
if ($content) {
// check if we must update file dependency
if (!preg_match("/'{$funcParam['uid']}'(.*?)'nocache_hash'/", $content, $match2)) {
$content = preg_replace("/('file_dependency'(.*?)\()/", "\\1{$match1[0]}", $content);
}
$tpl->getCached()->writeCache(
$tpl,
preg_replace('/\s*\?>\s*$/', "\n", $content) .
"\n" . preg_replace(
[
'/^\s*<\?php\s+/',
'/\s*\?>\s*$/',
],
"\n",
$match[0]
)
);
}
return true;
}

View File

@@ -11,6 +11,7 @@ use Smarty\Extension\CoreExtension;
use Smarty\Extension\DefaultExtension;
use Smarty\Extension\ExtensionInterface;
use Smarty\Filter\Output\TrimWhitespace;
use Smarty\Resource\BasePlugin;
use Smarty\Smarty\Runtime\CaptureRuntime;
use Smarty\Smarty\Runtime\ForeachRuntime;
use Smarty\Smarty\Runtime\InheritanceRuntime;
@@ -202,7 +203,7 @@ class Smarty extends \Smarty\TemplateBase
*
* @var boolean
*/
public $allow_ambiguous_resources = false;
private $allow_ambiguous_resources = false;
/**
* merge compiled includes
@@ -255,13 +256,6 @@ class Smarty extends \Smarty\TemplateBase
*/
public $security_policy = null;
/**
* controls if the php template file resource is allowed
*
* @var bool
*/
public $allow_php_templates = false;
/**
* debug mode
* Setting this to true enables the debug-console.
@@ -538,6 +532,12 @@ class Smarty extends \Smarty\TemplateBase
*/
private $BCPluginsAdapter;
/**
* Cache of templates created
* @var array
*/
private $templates;
/**
* Initialize new Smarty object
*/
@@ -965,39 +965,58 @@ class Smarty extends \Smarty\TemplateBase
return $this;
}
/**
* creates a template object
*
* @param string $template the resource handle of the template file
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param object $parent next higher level of Smarty variables
*
* @return \Smarty\Template template object
* @throws \Smarty\Exception
*/
public function createTemplate($template, $cache_id = null, $compile_id = null, $parent = null)
/**
* creates a template object
*
* @param Template|null $template_name
*
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param null $parent next higher level of Smarty variables
* $cache_lifetime
* @param null $caching
* @param null $cache_lifetime
* @param string|null $baseFilePath
*
* @return Template template object
* @throws Exception
*/
public function createTemplate($template_name, $cache_id = null, $compile_id = null, $parent = null, $caching = null,
$cache_lifetime = null, string $baseFilePath = null)
{
if ((is_object($cache_id) || is_array($cache_id))) {
$data = null;
// Shuffle params for backward compatibility: if 2nd param is an object, it's the parent
if (is_object($cache_id)) {
$parent = $cache_id;
$cache_id = null;
}
if (is_array($parent)) {
$data = $parent;
$parent = null;
} else {
$data = null;
// Shuffle params for backward compatibility: if 2nd param is an array, it's data
if (is_array($cache_id)) {
$data = $cache_id;
$cache_id = null;
}
if (!$this->_templateDirNormalized) {
$this->_normalizeTemplateConfig(false);
}
$_templateId = $this->_getTemplateId($template, $cache_id, $compile_id);
$_templateId = $this->generateUniqueTemplateId($template_name, $cache_id, $compile_id, $caching, $baseFilePath);
$tpl = new \Smarty\Template($template, $this, null, $cache_id, $compile_id, null, null);
$tpl->templateId = $_templateId;
// if (true || !isset($this->templates[$_templateId])) {
// $this->templates[$_templateId] = new Template($template_name, $this, null, $cache_id, $compile_id, $caching);
// $this->templates[$_templateId]->templateId = $_templateId;
// }
// $tpl = $this->templates[$_templateId];
$tpl = new Template($template_name, $this, $parent ?: $this, $cache_id, $compile_id, $caching);
$tpl->templateId = $_templateId;
if ($cache_lifetime) {
$tpl->setCacheLifetime($cache_lifetime);
}
$tpl->parent = $parent ?: $this;
// fill data if present
if (!empty($data) && is_array($data)) {
// set up variable values
@@ -1014,38 +1033,57 @@ class Smarty extends \Smarty\TemplateBase
return $tpl;
}
/**
* Get unique template id
*
* @param string $template_name
* @param null|mixed $cache_id
* @param null|mixed $compile_id
* @param null $caching
* @param \Smarty\Template $template
*
* @return string
* @throws \Smarty\Exception
*/
public function _getTemplateId(
/**
* Get unique template id
*
* @param string $template_name
* @param null|mixed $cache_id
* @param null|mixed $compile_id
* @param null $caching
* @param string|null $baseFilePath
*
* @return string
*/
public function generateUniqueTemplateId(
$template_name,
$cache_id = null,
$compile_id = null,
$caching = null,
\Smarty\Template $template = null
) {
$template_name = (strpos($template_name, ':') === false) ? "{$this->default_resource_type}:{$template_name}" :
$template_name;
$cache_id = $cache_id === null ? $this->cache_id : $cache_id;
$compile_id = $compile_id === null ? $this->compile_id : $compile_id;
$caching = (int)($caching === null ? $this->caching : $caching);
if ((isset($template) && strpos($template_name, ':.') !== false) || $this->allow_ambiguous_resources) {
$_templateId =
\Smarty\Resource\BasePlugin::getUniqueTemplateName($this, $template ?? null, $template_name) .
"#{$cache_id}#{$compile_id}#{$caching}";
} else {
$_templateId = $this->_joined_template_dir . "#{$template_name}#{$cache_id}#{$compile_id}#{$caching}";
string $baseFilePath = null
): string {
// defaults for optional params
$cache_id = $cache_id ?? $this->cache_id;
$compile_id = $compile_id ?? $this->compile_id;
$caching = (int) $caching ?? $this->caching;
if (strpos($template_name, ':') === false) {
$template_name = "{$this->default_resource_type}:{$template_name}";
}
$id_parts = [];
[$name, $type] = BasePlugin::parseResourceName($template_name, $this->default_resource_type);
$nameIsDotted = !empty($name) && $name[0] === '.' && ($name[1] === '.' || $name[1] === '/');
$id_parts[] = $type;
$id_parts[] = $this->_getSmartyObj()->_joined_template_dir;
// handle relative template names
if ($baseFilePath && $nameIsDotted) {
// go relative to a given template?
$id_parts[] = $this->_realpath($baseFilePath);
}
if (isset($_templateId[ 150 ])) {
$id_parts[] = $name;
$id_parts[] = (string) $cache_id;
$id_parts[] = (string) $compile_id;
$id_parts[] = (string) $caching;
$_templateId = implode('#', $id_parts);
// hash very long IDs to prevent problems with filename length
// do not hash shorter IDs so they remain recognizable
if (strlen($_templateId) > 150) {
$_templateId = sha1($_templateId);
}
return $_templateId;
@@ -1387,7 +1425,7 @@ class Smarty extends \Smarty\TemplateBase
$tpl = $this->createTemplate($resource_name);
$this->caching = $_save_stat;
if (!$tpl->source->handler->recompiled && $tpl->source->exists) {
$_resource_part_1 = basename(str_replace('^', DIRECTORY_SEPARATOR, $tpl->compiled->filepath));
$_resource_part_1 = basename(str_replace('^', DIRECTORY_SEPARATOR, $tpl->getCompiled()->filepath));
$_resource_part_1_length = strlen($_resource_part_1);
} else {
return 0;
@@ -1593,15 +1631,15 @@ class Smarty extends \Smarty\TemplateBase
* check client side cache
*
* @param \Smarty\Template\Cached $cached
* @param \Smarty\Template $_template
* @param Template $_template
* @param string $content
*
* @throws \Exception
* @throws \Smarty\Exception
*/
public function cacheModifiedCheck(Template\Cached $cached, \Smarty\Template $_template, $content)
public function cacheModifiedCheck(Template\Cached $cached, Template $_template, $content)
{
$_isCached = $_template->isCached() && !$_template->compiled->has_nocache_code;
$_isCached = $_template->isCached() && !$_template->getCompiled()->getNocacheCode();
$_last_modified_date =
@substr($_SERVER[ 'HTTP_IF_MODIFIED_SINCE' ], 0, strpos($_SERVER[ 'HTTP_IF_MODIFIED_SINCE' ], 'GMT') + 3);
if ($_isCached && $cached->timestamp <= strtotime($_last_modified_date)) {
@@ -2141,7 +2179,7 @@ class Smarty extends \Smarty\TemplateBase
* @param array|string $modifiers modifier or list of modifiers
* to add
*
* @return \Smarty|\Smarty\Template
* @return \Smarty|Template
* @api Smarty::addDefaultModifiers()
*
*/
@@ -2231,7 +2269,7 @@ class Smarty extends \Smarty\TemplateBase
/**
* test if cache is valid
*
* @param null|string|\Smarty\Template $template the resource handle of the template file or template
* @param null|string|Template $template the resource handle of the template file or template
* object
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template

View File

@@ -18,14 +18,30 @@ use Smarty\Template\Config;
/**
* Main class with template data structures and methods
*
* @property Compiled $compiled
* @property Cached $cached
* @property \Smarty\Compiler\Template $compiler
*/
#[\AllowDynamicProperties]
class Template extends TemplateBase {
/**
* caching mode to create nocache code but no cache file
*/
public const CACHING_NOCACHE_CODE = 9999;
/**
* @var Compiled
*/
private $compiled = null;
/**
* @var Cached
*/
private $cached = null;
/**
* @var \Smarty\Compiler\Template
*/
private $compiler = null;
/**
* Source instance
*
@@ -48,7 +64,7 @@ class Template extends TemplateBase {
public $mustCompile = null;
/**
* Template Id
* Template ID
*
* @var null|string
*/
@@ -100,7 +116,6 @@ class Template extends TemplateBase {
* @param mixed $_cache_id cache id or null
* @param mixed $_compile_id compile id or null
* @param bool|int|null $_caching use caching?
* @param int|null $_cache_lifetime cache life-time in seconds
* @param bool $_isConfig
*
* @throws \Smarty\Exception
@@ -112,7 +127,6 @@ class Template extends TemplateBase {
$_cache_id = null,
$_compile_id = null,
$_caching = null,
$_cache_lifetime = null,
$_isConfig = false
) {
$this->smarty = $smarty;
@@ -120,14 +134,14 @@ class Template extends TemplateBase {
$this->cache_id = $_cache_id === null ? $this->smarty->cache_id : $_cache_id;
$this->compile_id = $_compile_id === null ? $this->smarty->compile_id : $_compile_id;
$this->caching = (int)($_caching === null ? $this->smarty->caching : $_caching);
$this->cache_lifetime = $_cache_lifetime === null ? $this->smarty->cache_lifetime : $_cache_lifetime;
$this->cache_lifetime = $this->smarty->cache_lifetime;
$this->compile_check = (int)$smarty->compile_check;
$this->parent = $_parent;
// Template resource
$this->template_resource = $template_resource;
$this->source = $_isConfig ? Config::load($this) : Source::load($this);
if ($smarty->security_policy && method_exists($smarty->security_policy, 'registerCallBacks')) {
if ($smarty->security_policy) {
$smarty->security_policy->registerCallBacks($this);
}
}
@@ -159,28 +173,27 @@ class Template extends TemplateBase {
}
// read from cache or render
if ($this->caching === \Smarty\Smarty::CACHING_LIFETIME_CURRENT || $this->caching === \Smarty\Smarty::CACHING_LIFETIME_SAVED) {
if (!isset($this->cached) || $this->cached->cache_id !== $this->cache_id
|| $this->cached->compile_id !== $this->compile_id
) {
$this->loadCached(true);
if ($this->getCached()->cache_id !== $this->cache_id || $this->getCached()->compile_id !== $this->compile_id) {
$this->getCached(true);
}
$this->cached->render($this, $no_output_filter);
$this->getCached()->render($this, $no_output_filter);
} else {
if (!isset($this->compiled) || $this->compiled->compile_id !== $this->compile_id) {
$this->loadCompiled(true);
$compiled = $this->getCompiled();
if ($compiled->compile_id !== $this->compile_id) {
$compiled = $this->getCompiled(true);
}
$this->compiled->render($this);
$compiled->render($this);
}
// display or fetch
if ($display) {
if ($this->caching && $this->smarty->cache_modified_check) {
$this->smarty->cacheModifiedCheck(
$this->cached,
$this->getCached(),
$this,
isset($content) ? $content : ob_get_clean()
);
} else {
if ((!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled)
if ((!$this->caching || $this->getCached()->getNocacheCode() || $this->source->handler->recompiled)
&& !$no_output_filter && isset($this->smarty->registered_filters['output'])
) {
echo $this->smarty->runOutputFilters(ob_get_clean(), $this);
@@ -203,7 +216,7 @@ class Template extends TemplateBase {
}
if (
!$no_output_filter
&& (!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled)
&& (!$this->caching || $this->getCached()->getNocacheCode() || $this->source->handler->recompiled)
) {
return $this->smarty->runOutputFilters(ob_get_clean(), $this);
@@ -216,12 +229,12 @@ class Template extends TemplateBase {
/**
* Runtime function to render sub-template
*
* @param string $template template name
* @param string $template_name template name
* @param mixed $cache_id cache id
* @param mixed $compile_id compile id
* @param integer $caching cache mode
* @param integer $cache_lifetime life time of cache data
* @param array $data passed parameter template variables
* @param array $extra_vars passed parameter template variables
* @param string $uid file dependency uid
* @param string $content_func function name
*
@@ -229,63 +242,57 @@ class Template extends TemplateBase {
* @throws \Smarty\Exception
*/
public function _subTemplateRender(
$template,
$template_name,
$cache_id,
$compile_id,
$caching,
$cache_lifetime,
$data,
array $extra_vars,
$uid = null,
$content_func = null
) {
$tpl = clone $this;
$tpl->parent = $this;
$smarty = &$this->smarty;
$_templateId = $smarty->_getTemplateId($template, $cache_id, $compile_id, $caching, $tpl);
// recursive call ?
if ((isset($tpl->templateId) ? $tpl->templateId : $tpl->_getTemplateId()) !== $_templateId) {
$tpl->templateId = $_templateId;
$tpl->template_resource = $template;
$tpl->cache_id = $cache_id;
$tpl->compile_id = $compile_id;
if (isset($uid)) {
$baseFilePath = $this->source && $this->source->filepath ? dirname($this->source->filepath) : null;
$tpl = $this->_getSmartyObj()->createTemplate($template_name, $cache_id, $compile_id, $this, $caching, $cache_lifetime, $baseFilePath);
// copy variables
$tpl->tpl_vars = $this->tpl_vars;
$tpl->config_vars = $this->config_vars;
// recursive call ?
if ($tpl->getTemplateId() == $this->getTemplateId()) {
if (isset($uid) && $this->getCompiled()->file_dependency) {
// for inline templates we can get all resource information from file dependency
[$filepath, $timestamp, $type] = $tpl->compiled->file_dependency[$uid];
$tpl->source = new Source($smarty, $filepath, $type, $filepath);
[$filepath, $timestamp, $type] = $this->getCompiled()->file_dependency[$uid];
$tpl->source = new Source($this->_getSmartyObj(), $filepath, $type, $filepath);
$tpl->source->filepath = $filepath;
$tpl->source->timestamp = $timestamp;
$tpl->source->exists = true;
$tpl->source->uid = $uid;
} else {
$tpl->source = Source::load($tpl);
unset($tpl->compiled);
$tpl->getCompiled(true); // @TODO this unset($tpl->compiled), there might be a bug here
}
if ($caching !== 9999) {
unset($tpl->cached);
if ($caching !== \Smarty\Template::CACHING_NOCACHE_CODE) {
$tpl->getCached(true); // @TODO this unset($tpl->cached), there might be a bug here
}
} else {
// on recursive calls force caching
$forceTplCache = true;
}
$tpl->caching = $caching;
$tpl->cache_lifetime = $cache_lifetime;
if (!empty($data)) {
if (!empty($extra_vars)) {
// set up variable values
foreach ($data as $_key => $_val) {
foreach ($extra_vars as $_key => $_val) {
$tpl->assign($_key, $_val);
}
}
if ($tpl->caching === 9999) {
if (!isset($tpl->compiled)) {
$tpl->loadCompiled(true);
}
if ($tpl->compiled->has_nocache_code) {
$this->cached->hashes[$tpl->compiled->nocache_hash] = true;
if ($tpl->caching === \Smarty\Template::CACHING_NOCACHE_CODE) {
if ($tpl->getCompiled()->getNocacheCode()) {
$this->getCached()->hashes[$tpl->getCompiled()->nocache_hash] = true;
}
}
if (isset($uid)) {
$smarty = $this->_getSmartyObj();
if ($smarty->debugging) {
$smarty->getDebug()->start_template($tpl);
$smarty->getDebug()->start_render($tpl);
@@ -296,11 +303,14 @@ class Template extends TemplateBase {
$smarty->getDebug()->end_render($tpl);
}
} else {
if (isset($tpl->compiled)) {
$tpl->compiled->render($tpl);
} else {
$tpl->render();
}
$tpl->getCompiled()->render($tpl);
// @TODO: this used to be like this. Might cause a bug.
// if (isset($tpl->compiled)) {
// $tpl->getCompiled()->render($tpl);
// } else {
// $tpl->render();
// }
}
}
@@ -372,21 +382,21 @@ class Template extends TemplateBase {
if ($cache) {
// CACHING_LIFETIME_SAVED cache expiry has to be validated here since otherwise we'd define the unifunc
if ($tpl->caching === \Smarty\Smarty::CACHING_LIFETIME_SAVED && $properties['cache_lifetime'] >= 0
&& (time() > ($tpl->cached->timestamp + $properties['cache_lifetime']))
&& (time() > ($tpl->getCached()->timestamp + $properties['cache_lifetime']))
) {
$is_valid = false;
}
$tpl->cached->cache_lifetime = $properties['cache_lifetime'];
$tpl->cached->valid = $is_valid;
$generatedFile = $tpl->cached;
$tpl->getCached()->cache_lifetime = $properties['cache_lifetime'];
$tpl->getCached()->valid = $is_valid;
$generatedFile = $tpl->getCached();
} else {
$tpl->mustCompile = !$is_valid;
$generatedFile = $tpl->compiled;
$generatedFile = $tpl->getCompiled();
$generatedFile->includes = $properties['includes'] ?? [];
}
if ($is_valid) {
$generatedFile->unifunc = $properties['unifunc'];
$generatedFile->has_nocache_code = $properties['has_nocache_code'];
$generatedFile->setNocacheCode($properties['has_nocache_code']);
$generatedFile->file_dependency = $properties['file_dependency'];
}
return $is_valid && !function_exists($properties['unifunc']);
@@ -399,7 +409,7 @@ class Template extends TemplateBase {
* @throws \Exception
*/
public function compileTemplateSource() {
return $this->compiled->compileTemplateSource($this);
return $this->getCompiled()->compileTemplateSource($this);
}
/**
@@ -415,22 +425,18 @@ class Template extends TemplateBase {
// don't write cache file
return false;
}
if (!isset($this->cached)) {
$this->loadCached();
}
$codeframe = $this->createCodeFrame($content, '', true);
return $this->cached->writeCache($this, $codeframe);
return $this->getCached()->writeCache($this, $codeframe);
}
/**
* Get unique template id
*
* @return string
* @throws \Smarty\Exception
*/
public function _getTemplateId() {
public function getTemplateId() {
return $this->templateId ?? $this->templateId =
$this->smarty->_getTemplateId($this->template_resource, $this->cache_id, $this->compile_id);
$this->smarty->generateUniqueTemplateId($this->template_resource, $this->cache_id, $this->compile_id);
}
/**
@@ -443,32 +449,37 @@ class Template extends TemplateBase {
}
/**
* Load compiled object
* Return Compiled object
*
* @param bool $force force new compiled object
* @param bool $forceNew force new compiled object
*/
public function loadCompiled($force = false) {
if ($force || !isset($this->compiled)) {
public function getCompiled($forceNew = false) {
if ($forceNew || !isset($this->compiled)) {
$this->compiled = Compiled::load($this);
}
return $this->compiled;
}
/**
* Load cached object
* Return Cached object
*
* @param bool $force force new cached object
* @param bool $forceNew force new cached object
*
* @throws Exception
*/
public function loadCached($force = false) {
if ($force || !isset($this->cached)) {
public function getCached($forceNew = false) {
if ($forceNew || !isset($this->cached)) {
$this->cached = new Cached($this);
$this->cached->handler->populate($this->cached, $this);
// caching enabled ?
if (!$this->caching || $this->source->handler->recompiled) {
if (!$this->isCachingEnabled()) {
$this->cached->valid = false;
}
}
return $this->cached;
}
public function isCachingEnabled(): bool {
return $this->caching && !$this->source->handler->recompiled;
}
/**
@@ -490,14 +501,13 @@ class Template extends TemplateBase {
}
/**
* Load compiler object
*
* @throws \Smarty\Exception
* Return Compiler object
*/
public function loadCompiler() {
public function getCompiler() {
if (!isset($this->compiler)) {
$this->compiler = $this->source->createCompiler();
}
return $this->compiler;
}
/**
@@ -506,102 +516,24 @@ class Template extends TemplateBase {
* @param string $content optional template content
* @param string $functions compiled template function and block code
* @param bool $cache flag for cache file
* @param \Smarty\Compiler\Template $compiler
* @param Compiler\Template|null $compiler
*
* @return string
* @throws Exception
*/
public function createCodeFrame($content = '', $functions = '', $cache = false, \Smarty\Compiler\Template $compiler = null) {
return $this->getCodeFrameCompiler()->create($content, $functions, $cache, $compiler);
}
/**
* Handle unknown class methods
*
* @param string $name unknown method-name
* @param array $args argument array
*
* @return mixed
*/
public function __call($name, $args) {
// method of Smarty object?
if (method_exists($this->smarty, $name)) {
return call_user_func_array([$this->smarty, $name], $args);
}
// parent
return parent::__call($name, $args);
}
/**
* get Smarty property in template context
*
* @param string $property_name property name
*
* @return mixed|Cached
* @throws Exception
*
* @deprecated
* @TODO remove
*/
public function __get($property_name) {
switch ($property_name) {
case 'compiled':
$this->loadCompiled();
return $this->compiled;
case 'cached':
$this->loadCached();
return $this->cached;
case 'compiler':
$this->loadCompiler();
return $this->compiler;
default:
// Smarty property ?
if (property_exists($this->smarty, $property_name)) {
return $this->smarty->$property_name;
}
}
throw new Exception("template property '$property_name' does not exist.");
}
/**
* set Smarty property in template context
*
* @param string $property_name property name
* @param mixed $value value
*
* @throws Exception
*
*
* @deprecated
* @TODO remove
*/
public function __set($property_name, $value) {
switch ($property_name) {
case 'compiled':
case 'cached':
case 'compiler':
$this->$property_name = $value;
return;
default:
// Smarty property ?
if (property_exists($this->smarty, $property_name)) {
$this->smarty->$property_name = $value;
return;
}
}
throw new Exception("invalid template property '$property_name'.");
}
/**
* Template data object destructor
*/
public function __destruct() {
if ($this->smarty->cache_locking && isset($this->cached) && $this->cached->is_locked) {
$this->cached->handler->releaseLock($this->smarty, $this->cached);
if ($this->smarty->cache_locking && $this->getCached()->is_locked) {
$this->getCached()->handler->releaseLock($this->smarty, $this->getCached());
}
}
/**
* Returns if the current template must be compiled by the Smarty compiler
* It does compare the timestamps of template source and the compiled templates and checks the force compile
@@ -622,8 +554,8 @@ class Template extends TemplateBase {
if ($this->mustCompile === null) {
$this->mustCompile = $this->smarty->force_compile
|| $this->source->handler->recompiled
|| !$this->compiled->exists
|| ($this->compile_check && $this->compiled->getTimeStamp() < $this->source->getTimeStamp());
|| !$this->getCompiled()->exists
|| ($this->compile_check && $this->getCompiled()->getTimeStamp() < $this->source->getTimeStamp());
}
return $this->mustCompile;
}
@@ -704,7 +636,7 @@ class Template extends TemplateBase {
{
$confObj = parent::configLoad($config_file, $sections);
$this->compiled->file_dependency[ $confObj->source->uid ] =
$this->getCompiled()->file_dependency[ $confObj->source->uid ] =
array($confObj->source->filepath, $confObj->source->getTimeStamp(), $confObj->source->type);
return $confObj;
@@ -766,19 +698,22 @@ class Template extends TemplateBase {
if ($function === 2) {
if ($this->caching) {
// return cache status of template
if (!isset($this->cached)) {
$this->loadCached();
}
$result = $this->cached->isCached($this);
$result = $this->getCached()->isCached($this);
} else {
return false;
}
} else {
// After rendering a template, the tpl/config variables are reset, so the template can be re-used.
$savedTplVars = $this->tpl_vars;
$savedConfigVars = $this->config_vars;
// Start output-buffering. @TODO keep all ob_* calls together
ob_start();
$result = $this->render(false, $function);
// Restore the template to its previous state
$this->_cleanUp();
$this->tpl_vars = $savedTplVars;
$this->config_vars = $savedConfigVars;

View File

@@ -178,8 +178,8 @@ class Cached extends GeneratedPhpFile {
return $this->valid;
}
if ($this->valid && $_template->caching === \Smarty\Smarty::CACHING_LIFETIME_SAVED
&& $_template->cached->cache_lifetime >= 0
&& (time() > ($_template->cached->timestamp + $_template->cached->cache_lifetime))
&& $_template->getCached()->cache_lifetime >= 0
&& (time() > ($_template->getCached()->timestamp + $_template->getCached()->cache_lifetime))
) {
$this->valid = false;
}
@@ -266,10 +266,8 @@ class Cached extends GeneratedPhpFile {
*/
private function updateCache(Template $_template, $no_output_filter) {
ob_start();
if (!isset($_template->compiled)) {
$_template->loadCompiled();
}
$_template->compiled->render($_template);
$_template->getCompiled()->render($_template);
if ($_template->smarty->debugging) {
$_template->smarty->getDebug()->start_cache($_template);
}
@@ -277,10 +275,10 @@ class Cached extends GeneratedPhpFile {
$compile_check = (int)$_template->compile_check;
$_template->compile_check = \Smarty\Smarty::COMPILECHECK_OFF;
if ($_template->_isSubTpl()) {
$_template->compiled->unifunc = $_template->parent->compiled->unifunc;
$_template->getCompiled()->unifunc = $_template->parent->getCompiled()->unifunc;
}
if (!$_template->cached->processed) {
$_template->cached->process($_template, true);
if (!$_template->getCached()->processed) {
$_template->getCached()->process($_template, true);
}
$_template->compile_check = $compile_check;
$this->renderTemplateCode($_template);
@@ -301,10 +299,10 @@ class Cached extends GeneratedPhpFile {
$php_pattern = '/(<%|%>|<\?php|<\?|\?>|<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>)/';
$content = ob_get_clean();
$hash_array = $this->hashes;
$hash_array[$_template->compiled->nocache_hash] = true;
$hash_array[$_template->getCompiled()->nocache_hash] = true;
$hash_array = array_keys($hash_array);
$nocache_hash = '(' . implode('|', $hash_array) . ')';
$_template->cached->has_nocache_code = false;
$_template->getCached()->setNocacheCode(false);
// get text between non-cached items
$cache_split =
preg_split(
@@ -341,13 +339,13 @@ class Cached extends GeneratedPhpFile {
$content .= $curr_split;
}
if (isset($cache_parts[0][$curr_idx])) {
$_template->cached->has_nocache_code = true;
$_template->getCached()->setNocacheCode(true);
$content .= $cache_parts[2][$curr_idx];
}
}
if (
!$no_output_filter
&& !$_template->cached->has_nocache_code
&& !$_template->getCached()->getNocacheCode()
) {
$content = $_template->smarty->runOutputFilters($content, $_template);
}

View File

@@ -35,9 +35,7 @@ class Compiled extends GeneratedPhpFile {
*/
public static function load($_template) {
$compiled = new Compiled();
if ($_template->source->handler->hasCompiledHandler) {
$_template->source->handler->populateCompiledFilepath($compiled, $_template);
} else {
if ($_template->source->handler->supportsCompiledTemplates()) {
$compiled->populateCompiledFilepath($_template);
}
return $compiled;
@@ -48,7 +46,7 @@ class Compiled extends GeneratedPhpFile {
*
* @param Template $_template template object
**/
public function populateCompiledFilepath(Template $_template) {
private function populateCompiledFilepath(Template $_template) {
$source = &$_template->source;
$smarty = &$_template->smarty;
$this->filepath = $smarty->getCompileDir();
@@ -105,15 +103,14 @@ class Compiled extends GeneratedPhpFile {
if (!$this->processed) {
$this->process($_template);
}
if (isset($_template->cached)) {
$_template->cached->file_dependency =
array_merge($_template->cached->file_dependency, $this->file_dependency);
}
$_template->getCached()->file_dependency =
array_merge($_template->getCached()->file_dependency, $this->file_dependency);
$_template->getRenderedTemplateCode($this->unifunc);
if ($_template->caching && $this->has_nocache_code) {
$_template->cached->hashes[$this->nocache_hash] = true;
if ($_template->caching && $this->getNocacheCode()) {
$_template->getCached()->hashes[$this->nocache_hash] = true;
}
if ($_template->smarty->debugging) {
$_template->smarty->getDebug()->end_render($_template);
@@ -176,18 +173,14 @@ class Compiled extends GeneratedPhpFile {
// compile locking
try {
// call compiler
$_template->loadCompiler();
$this->write($_template, $_template->compiler->compileTemplate($_template));
$this->write($_template, $_template->getCompiler()->compileTemplate($_template));
} catch (\Exception $e) {
// restore old timestamp in case of error
if ($saved_timestamp && is_file($this->filepath)) {
touch($this->filepath, $saved_timestamp);
}
unset($_template->compiler);
throw $e;
}
// release compiler object to free memory
unset($_template->compiler);
}
/**

View File

@@ -55,7 +55,7 @@ abstract class GeneratedPhpFile {
*
* @var bool
*/
public $has_nocache_code = false;
private $has_nocache_code = false;
/**
* resource file dependency
@@ -76,4 +76,18 @@ abstract class GeneratedPhpFile {
return $this->timestamp;
}
/**
* @return bool
*/
public function getNocacheCode(): bool {
return $this->has_nocache_code;
}
/**
* @param bool $has_nocache_code
*/
public function setNocacheCode(bool $has_nocache_code): void {
$this->has_nocache_code = $has_nocache_code;
}
}

View File

@@ -183,7 +183,7 @@ abstract class TemplateBase extends Data {
* variables
* @param null $name optional data block name
*
* @return DataObject data object
* @return Data data object
* @throws Exception
* @api Smarty::createData()
* @link https://www.smarty.net/docs/en/api.create.data.tpl
@@ -192,7 +192,7 @@ abstract class TemplateBase extends Data {
public function createData(Data $parent = null, $name = null) {
/* @var Smarty $smarty */
$smarty = $this->_getSmartyObj();
$dataObj = new DataObject($parent, $smarty, $name);
$dataObj = new Data($parent, $smarty, $name);
if ($smarty->debugging) {
$smarty->getDebug()->register_data($dataObj);
}

View File

@@ -42,7 +42,7 @@ class CacheResourceFileTest extends CacheResourceTestCommon
$this->smarty->setUseSubDirs(true);
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertEquals($this->buildCachedPath($tpl, true, null, null, 'helloworld.tpl', $type = 'file', $this->smarty->getTemplateDir(0), 'file')
, $tpl->cached->filepath);
, $tpl->getCached()->filepath);
}
/**
@@ -55,7 +55,7 @@ class CacheResourceFileTest extends CacheResourceTestCommon
$this->smarty->setUseSubDirs(true);
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar');
$this->assertEquals($this->buildCachedPath($tpl, true, 'foo|bar', null, 'helloworld.tpl', $type = 'file', $this->smarty->getTemplateDir(0), 'file')
, $tpl->cached->filepath);
, $tpl->getCached()->filepath);
}
/**
@@ -68,7 +68,7 @@ class CacheResourceFileTest extends CacheResourceTestCommon
$this->smarty->setUseSubDirs(true);
$tpl = $this->smarty->createTemplate('helloworld.tpl', null, 'blar');
$this->assertEquals($this->buildCachedPath($tpl, true, null, 'blar', 'helloworld.tpl', $type = 'file', $this->smarty->getTemplateDir(0), 'file')
, $tpl->cached->filepath);
, $tpl->getCached()->filepath);
}
/**
@@ -81,7 +81,7 @@ class CacheResourceFileTest extends CacheResourceTestCommon
$this->smarty->setUseSubDirs(true);
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$this->assertEquals($this->buildCachedPath($tpl, true, 'foo|bar', 'blar', 'helloworld.tpl', $type = 'file', $this->smarty->getTemplateDir(0), 'file')
, $tpl->cached->filepath);
, $tpl->getCached()->filepath);
}
/**
@@ -95,7 +95,7 @@ class CacheResourceFileTest extends CacheResourceTestCommon
$this->smarty->setUseSubDirs(true);
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl->getCached()->filepath));
$this->assertEquals(1, $this->smarty->clearAllCache());
}
@@ -114,13 +114,13 @@ class CacheResourceFileTest extends CacheResourceTestCommon
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl3);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertTrue(file_exists($tpl->getCached()->filepath));
$this->assertTrue(file_exists($tpl2->getCached()->filepath));
$this->assertTrue(file_exists($tpl3->getCached()->filepath));
$this->assertEquals(2, $this->smarty->clearCache(null, 'foo|bar'));
$this->assertFalse(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertFalse(file_exists($tpl3->cached->filepath));
$this->assertFalse(file_exists($tpl->getCached()->filepath));
$this->assertTrue(file_exists($tpl2->getCached()->filepath));
$this->assertFalse(file_exists($tpl3->getCached()->filepath));
}
public function testClearCacheCacheIdCompileId2()
@@ -135,13 +135,13 @@ class CacheResourceFileTest extends CacheResourceTestCommon
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl3);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertTrue(file_exists($tpl->getCached()->filepath));
$this->assertTrue(file_exists($tpl2->getCached()->filepath));
$this->assertTrue(file_exists($tpl3->getCached()->filepath));
$this->assertEquals(2, $this->smarty->clearCache('helloworld.tpl'));
$this->assertFalse(file_exists($tpl->cached->filepath));
$this->assertFalse(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertFalse(file_exists($tpl->getCached()->filepath));
$this->assertFalse(file_exists($tpl2->getCached()->filepath));
$this->assertTrue(file_exists($tpl3->getCached()->filepath));
}
public function testClearCacheCacheIdCompileId2Sub()
@@ -156,13 +156,13 @@ class CacheResourceFileTest extends CacheResourceTestCommon
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl3);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertTrue(file_exists($tpl->getCached()->filepath));
$this->assertTrue(file_exists($tpl2->getCached()->filepath));
$this->assertTrue(file_exists($tpl3->getCached()->filepath));
$this->assertEquals(2, $this->smarty->clearCache('helloworld.tpl'));
$this->assertFalse(file_exists($tpl->cached->filepath));
$this->assertFalse(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertFalse(file_exists($tpl->getCached()->filepath));
$this->assertFalse(file_exists($tpl2->getCached()->filepath));
$this->assertTrue(file_exists($tpl3->getCached()->filepath));
}
public function testClearCacheCacheIdCompileId3()
@@ -177,13 +177,13 @@ class CacheResourceFileTest extends CacheResourceTestCommon
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl3);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertTrue(file_exists($tpl->getCached()->filepath));
$this->assertTrue(file_exists($tpl2->getCached()->filepath));
$this->assertTrue(file_exists($tpl3->getCached()->filepath));
$this->assertEquals(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2'));
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertFalse(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertTrue(file_exists($tpl->getCached()->filepath));
$this->assertFalse(file_exists($tpl2->getCached()->filepath));
$this->assertTrue(file_exists($tpl3->getCached()->filepath));
}
public function testClearCacheCacheIdCompileId3Sub()
@@ -198,13 +198,13 @@ class CacheResourceFileTest extends CacheResourceTestCommon
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl3);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertTrue(file_exists($tpl->getCached()->filepath));
$this->assertTrue(file_exists($tpl2->getCached()->filepath));
$this->assertTrue(file_exists($tpl3->getCached()->filepath));
$this->assertEquals(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2'));
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertFalse(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertTrue(file_exists($tpl->getCached()->filepath));
$this->assertFalse(file_exists($tpl2->getCached()->filepath));
$this->assertTrue(file_exists($tpl3->getCached()->filepath));
}
public function testClearCacheCacheIdCompileId4()
@@ -219,13 +219,13 @@ class CacheResourceFileTest extends CacheResourceTestCommon
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl3);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertTrue(file_exists($tpl->getCached()->filepath));
$this->assertTrue(file_exists($tpl2->getCached()->filepath));
$this->assertTrue(file_exists($tpl3->getCached()->filepath));
$this->assertEquals(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2'));
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertFalse(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertTrue(file_exists($tpl->getCached()->filepath));
$this->assertFalse(file_exists($tpl2->getCached()->filepath));
$this->assertTrue(file_exists($tpl3->getCached()->filepath));
}
public function testClearCacheCacheIdCompileId4Sub()
@@ -240,13 +240,13 @@ class CacheResourceFileTest extends CacheResourceTestCommon
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl3);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertTrue(file_exists($tpl->getCached()->filepath));
$this->assertTrue(file_exists($tpl2->getCached()->filepath));
$this->assertTrue(file_exists($tpl3->getCached()->filepath));
$this->assertEquals(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2'));
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertFalse(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertTrue(file_exists($tpl->getCached()->filepath));
$this->assertFalse(file_exists($tpl2->getCached()->filepath));
$this->assertTrue(file_exists($tpl3->getCached()->filepath));
}
public function testClearCacheCacheIdCompileId5()
@@ -261,13 +261,13 @@ class CacheResourceFileTest extends CacheResourceTestCommon
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl3);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertTrue(file_exists($tpl->getCached()->filepath));
$this->assertTrue(file_exists($tpl2->getCached()->filepath));
$this->assertTrue(file_exists($tpl3->getCached()->filepath));
$this->assertEquals(2, $this->smarty->clearCache(null, null, 'blar'));
$this->assertFalse(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertFalse(file_exists($tpl3->cached->filepath));
$this->assertFalse(file_exists($tpl->getCached()->filepath));
$this->assertTrue(file_exists($tpl2->getCached()->filepath));
$this->assertFalse(file_exists($tpl3->getCached()->filepath));
}
public function testClearCacheCacheIdCompileId5Sub()
@@ -282,13 +282,13 @@ class CacheResourceFileTest extends CacheResourceTestCommon
$this->writeCachedContent($tpl2);
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$this->writeCachedContent($tpl3);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertTrue(file_exists($tpl->getCached()->filepath));
$this->assertTrue(file_exists($tpl2->getCached()->filepath));
$this->assertTrue(file_exists($tpl3->getCached()->filepath));
$this->assertEquals(2, $this->smarty->clearCache(null, null, 'blar'));
$this->assertFalse(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertFalse(file_exists($tpl3->cached->filepath));
$this->assertFalse(file_exists($tpl->getCached()->filepath));
$this->assertTrue(file_exists($tpl2->getCached()->filepath));
$this->assertFalse(file_exists($tpl3->getCached()->filepath));
}
public function testClearCacheCacheFile()
@@ -305,15 +305,15 @@ class CacheResourceFileTest extends CacheResourceTestCommon
$this->writeCachedContent($tpl3);
$tpl4 = $this->smarty->createTemplate('helloworld2.tpl');
$this->writeCachedContent($tpl4);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertTrue(file_exists($tpl4->cached->filepath));
$this->assertTrue(file_exists($tpl->getCached()->filepath));
$this->assertTrue(file_exists($tpl2->getCached()->filepath));
$this->assertTrue(file_exists($tpl3->getCached()->filepath));
$this->assertTrue(file_exists($tpl4->getCached()->filepath));
$this->assertEquals(3, $this->smarty->clearCache('helloworld.tpl'));
$this->assertFalse(file_exists($tpl->cached->filepath));
$this->assertFalse(file_exists($tpl2->cached->filepath));
$this->assertFalse(file_exists($tpl3->cached->filepath));
$this->assertTrue(file_exists($tpl4->cached->filepath));
$this->assertFalse(file_exists($tpl->getCached()->filepath));
$this->assertFalse(file_exists($tpl2->getCached()->filepath));
$this->assertFalse(file_exists($tpl3->getCached()->filepath));
$this->assertTrue(file_exists($tpl4->getCached()->filepath));
}
public function testClearCacheCacheFileSub()
@@ -330,15 +330,15 @@ class CacheResourceFileTest extends CacheResourceTestCommon
$this->writeCachedContent($tpl3);
$tpl4 = $this->smarty->createTemplate('helloworld2.tpl');
$this->writeCachedContent($tpl4);
$this->assertTrue(file_exists($tpl->cached->filepath));
$this->assertTrue(file_exists($tpl2->cached->filepath));
$this->assertTrue(file_exists($tpl3->cached->filepath));
$this->assertTrue(file_exists($tpl4->cached->filepath));
$this->assertTrue(file_exists($tpl->getCached()->filepath));
$this->assertTrue(file_exists($tpl2->getCached()->filepath));
$this->assertTrue(file_exists($tpl3->getCached()->filepath));
$this->assertTrue(file_exists($tpl4->getCached()->filepath));
$this->assertEquals(3, $this->smarty->clearCache('helloworld.tpl'));
$this->assertFalse(file_exists($tpl->cached->filepath));
$this->assertFalse(file_exists($tpl2->cached->filepath));
$this->assertFalse(file_exists($tpl3->cached->filepath));
$this->assertTrue(file_exists($tpl4->cached->filepath));
$this->assertFalse(file_exists($tpl->getCached()->filepath));
$this->assertFalse(file_exists($tpl2->getCached()->filepath));
$this->assertFalse(file_exists($tpl3->getCached()->filepath));
$this->assertTrue(file_exists($tpl4->getCached()->filepath));
}
/**

View File

@@ -47,9 +47,8 @@ class CacheResourceCustomMemcacheTest extends CacheResourceTestCommon
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$tpl->loadCached();
$sha1 = $tpl->source->uid . '#helloworld_tpl##';
$this->assertEquals($sha1, $tpl->cached->filepath);
$this->assertEquals($sha1, $tpl->getCached()->filepath);
}
/**
@@ -60,9 +59,8 @@ class CacheResourceCustomMemcacheTest extends CacheResourceTestCommon
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar');
$tpl->loadCached();
$sha1 = $tpl->source->uid . '#helloworld_tpl#foo|bar#';
$this->assertEquals($sha1, $tpl->cached->filepath);
$this->assertEquals($sha1, $tpl->getCached()->filepath);
}
/**
@@ -73,9 +71,8 @@ class CacheResourceCustomMemcacheTest extends CacheResourceTestCommon
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('helloworld.tpl', null, 'blar');
$tpl->loadCached();
$sha1 = $tpl->source->uid . '#helloworld_tpl##blar';
$this->assertEquals($sha1, $tpl->cached->filepath);
$this->assertEquals($sha1, $tpl->getCached()->filepath);
}
/**
@@ -86,8 +83,7 @@ class CacheResourceCustomMemcacheTest extends CacheResourceTestCommon
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$tpl->loadCached();
$sha1 = $tpl->source->uid . '#helloworld_tpl#foo|bar#blar';
$this->assertEquals($sha1, $tpl->cached->filepath);
$this->assertEquals($sha1, $tpl->getCached()->filepath);
}
}

View File

@@ -45,7 +45,7 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$this->smarty->cache_lifetime = 1000;
$this->smarty->setUseSubDirs(true);
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertEquals($this->buildCachedPath($tpl), $tpl->cached->filepath);
$this->assertEquals($this->buildCachedPath($tpl), $tpl->getCached()->filepath);
}
/**
@@ -56,7 +56,7 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar');
$this->assertEquals($this->buildCachedPath($tpl, true, 'foo|bar'), $tpl->cached->filepath);
$this->assertEquals($this->buildCachedPath($tpl, true, 'foo|bar'), $tpl->getCached()->filepath);
}
/**
@@ -67,7 +67,7 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('helloworld.tpl', null, 'blar');
$this->assertEquals($this->buildCachedPath($tpl, true, null, 'blar'), $tpl->cached->filepath);
$this->assertEquals($this->buildCachedPath($tpl, true, null, 'blar'), $tpl->getCached()->filepath);
}
/**
@@ -78,7 +78,7 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$this->assertEquals($this->buildCachedPath($tpl, true, 'foo|bar', 'blar'), $tpl->cached->filepath);
$this->assertEquals($this->buildCachedPath($tpl, true, 'foo|bar', 'blar'), $tpl->getCached()->filepath);
}
/**
@@ -91,7 +91,7 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$tpl->writeCachedContent('hello world');
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl));
// Custom CacheResources may return -1 if they can't tell the number of deleted elements
//$this->assertEquals(-1, $this->smarty->clearAllCache());
}
@@ -112,15 +112,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$tpl3->writeCachedContent('hello world 3');
// test cached content
$this->assertEquals('hello world 1', $tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world 2', $tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world 3', $tpl->cached->handler->getCachedContent($tpl3));
$this->assertEquals('hello world 1', $tpl->getCached()->handler->getCachedContent($tpl));
$this->assertEquals('hello world 2', $tpl->getCached()->handler->getCachedContent($tpl2));
$this->assertEquals('hello world 3', $tpl->getCached()->handler->getCachedContent($tpl3));
// test number of deleted caches
$this->doClearCacheAssertion(2, $this->smarty->clearCache(null, 'foo|bar'));
// test that caches are deleted properly
$this->assertNull($tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world 2', $tpl->cached->handler->getCachedContent($tpl2));
$this->assertNull($tpl->cached->handler->getCachedContent($tpl3));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl));
$this->assertEquals('hello world 2', $tpl->getCached()->handler->getCachedContent($tpl2));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl3));
}
public function testClearCacheCacheIdCompileId2()
@@ -136,15 +136,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$tpl3->writeCachedContent('hello world');
// test cached content
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3));
// test number of deleted caches
$this->doClearCacheAssertion(2, $this->smarty->clearCache('helloworld.tpl'));
// test that caches are deleted properly
$this->assertNull($tpl->cached->handler->getCachedContent($tpl));
$this->assertNull($tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3));
}
public function testClearCacheCacheIdCompileId2Sub()
@@ -160,15 +160,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$tpl3->writeCachedContent('hello world');
// test cached content
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3));
// test number of deleted caches
$this->doClearCacheAssertion(2, $this->smarty->clearCache('helloworld.tpl'));
// test that caches are deleted properly
$this->assertNull($tpl->cached->handler->getCachedContent($tpl));
$this->assertNull($tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3));
}
public function testClearCacheCacheIdCompileId3()
@@ -184,15 +184,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$tpl3->writeCachedContent('hello world');
// test cached content
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3));
// test number of deleted caches
$this->doClearCacheAssertion(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2'));
// test that caches are deleted properly
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertNull($tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3));
}
public function testClearCacheCacheIdCompileId3Sub()
@@ -208,15 +208,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$tpl3->writeCachedContent('hello world');
// test cached content
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3));
// test number of deleted caches
$this->doClearCacheAssertion(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2'));
// test that caches are deleted properly
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertNull($tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3));
}
public function testClearCacheCacheIdCompileId4()
@@ -232,15 +232,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$tpl3->writeCachedContent('hello world');
// test cached content
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3));
// test number of deleted caches
$this->doClearCacheAssertion(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2'));
// test that caches are deleted properly
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertNull($tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3));
}
public function testClearCacheCacheIdCompileId4Sub()
@@ -256,15 +256,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$tpl3->writeCachedContent('hello world');
// test cached content
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3));
// test number of deleted caches
$this->doClearCacheAssertion(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2'));
// test that caches are deleted properly
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertNull($tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3));
}
public function testClearCacheCacheIdCompileId5()
@@ -280,15 +280,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$tpl3->writeCachedContent('hello world');
// test cached content
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3));
// test number of deleted caches
$this->doClearCacheAssertion(2, $this->smarty->clearCache(null, null, 'blar'));
// test that caches are deleted properly
$this->assertNull($tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2));
$this->assertNull($tpl->cached->handler->getCachedContent($tpl3));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl3));
}
public function testClearCacheCacheIdCompileId5Sub()
@@ -304,15 +304,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$tpl3->writeCachedContent('hello world');
// test cached content
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3));
// test number of deleted caches
$this->doClearCacheAssertion(2, $this->smarty->clearCache(null, null, 'blar'));
// test that caches are deleted properly
$this->assertNull($tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2));
$this->assertNull($tpl->cached->handler->getCachedContent($tpl3));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl3));
}
public function testClearCacheCacheFile()
@@ -330,17 +330,17 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$tpl4 = $this->smarty->createTemplate('helloworld2.tpl');
$tpl4->writeCachedContent('hello world');
// test cached content
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl4));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl4));
// test number of deleted caches
$this->doClearCacheAssertion(3, $this->smarty->clearCache('helloworld.tpl'));
// test that caches are deleted properly
$this->assertNull($tpl->cached->handler->getCachedContent($tpl));
$this->assertNull($tpl->cached->handler->getCachedContent($tpl2));
$this->assertNull($tpl->cached->handler->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl4));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl2));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl4));
}
/**
@@ -359,19 +359,19 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$tpl3 = $this->smarty->createTemplate('helloworld.tpl', 'buh|blar');
$tpl3->writeCachedContent('hello world');
// test cached content
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3));
sleep(10);
$tpl4 = $this->smarty->createTemplate('helloworld2.tpl');
$tpl4->writeCachedContent('hello world');
// test number of deleted caches
$this->doClearCacheAssertion(3,$this->smarty->clearAllCache(5));
// test that caches are deleted properly
$this->assertNull($tpl->cached->handler->getCachedContent($tpl));
$this->assertNull($tpl->cached->handler->getCachedContent($tpl2));
$this->assertNull($tpl->cached->handler->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl4));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl2));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl4));
}
public function testClearCacheCacheFileSub()
@@ -389,17 +389,17 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$tpl4 = $this->smarty->createTemplate('helloworld2.tpl');
$tpl4->writeCachedContent('hello world');
// test cached content
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl4));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl4));
// test number of deleted caches
$this->doClearCacheAssertion(3, $this->smarty->clearCache('helloworld.tpl'));
// test that caches are deleted properly
$this->assertNull($tpl->cached->handler->getCachedContent($tpl));
$this->assertNull($tpl->cached->handler->getCachedContent($tpl2));
$this->assertNull($tpl->cached->handler->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl4));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl2));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl4));
}
/**
* Test caching
@@ -430,9 +430,9 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$this->assertEquals($t,$tpl->source->getTimeStamp(), $testName . ' - source touch');
}
if ($lockTime) {
$tpl->cached->handler->acquireLock($this->smarty, $tpl->cached);
$tpl->cached->handler->lockTime = $lockTime;
$tpl->cached->is_locked = false;
$tpl->getCached()->handler->acquireLock($this->smarty, $tpl->getCached());
$tpl->getCached()->handler->lockTime = $lockTime;
$tpl->getCached()->is_locked = false;
}
$start = time();
if (isset($isCached)) {
@@ -440,9 +440,9 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
if ($lockTimeout) {
$time = time() - $start;
$this->assertTrue($time >= $tmin && $time <= $tmax, $testName . ' - isCached() - lock time');
$this->assertEquals(!$isCached, $tpl->cached->handler->hasLock($this->smarty, $tpl->cached), $testName . ' - isCached() - lock status');
$this->assertEquals(!$isCached, $tpl->getCached()->handler->hasLock($this->smarty, $tpl->getCached()), $testName . ' - isCached() - lock status');
} else {
$this->assertFalse($tpl->cached->handler->hasLock($this->smarty, $tpl->cached), $testName . ' - isCached() - unexpected lock');
$this->assertFalse($tpl->getCached()->handler->hasLock($this->smarty, $tpl->getCached()), $testName . ' - isCached() - unexpected lock');
}
}
$this->assertEquals("cache resource test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $this->smarty->fetch($tpl), $testName . ' - fetch() failure');
@@ -450,7 +450,7 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$time = time() - $start;
$this->assertTrue($time >= $tmin && $time <= $tmax, $testName . ' - fetch() - lock time');
}
$this->assertFalse($tpl->cached->handler->hasLock($this->smarty, $tpl->cached, $testName . ' - lock not removed'));
$this->assertFalse($tpl->getCached()->handler->hasLock($this->smarty, $tpl->getCached(), $testName . ' - lock not removed'));
}
public function data(){

View File

@@ -27,19 +27,6 @@ class Smarty_Resource_AmbiguousPlugin extends FilePlugin
$this->segment = $segment;
}
/**
* modify resource_name according to resource handlers specifications
*
* @param Smarty $smarty Smarty instance
* @param string $resource_name resource_name to make unique
*
* @return string unique resource name
*/
public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false)
{
return get_class($this) . '#' . $this->segment . '#' . $resource_name;
}
/**
* populate Source Object with meta data from Resource
*

View File

@@ -54,8 +54,9 @@ if (MysqlResourceEnable == true) {
$this->assertFalse($tpl->mustCompile());
}
/**
/**
* test must compile
* @group slow
*/
public function testMustCompile2()
{
@@ -97,7 +98,7 @@ if (MysqlResourceEnable == true) {
{
//$this->smarty->addPluginsDir("./PHPunitplugins/");
$tpl = $this->smarty->createTemplate('mysqltest:test.tpl');
$this->assertEquals($this->buildCompiledPath($tpl, false, false, null, 'test.tpl', 'mysqltest', $this->smarty->getTemplateDir(0)), $tpl->compiled->filepath);
$this->assertEquals($this->buildCompiledPath($tpl, false, false, null, 'test.tpl', 'mysqltest', $this->smarty->getTemplateDir(0)), $tpl->getCompiled()->filepath);
}
public function testResourcePluginMysqlCompiledFilepathCache()
@@ -107,7 +108,7 @@ if (MysqlResourceEnable == true) {
$this->smarty->setForceCompile(true);
$this->smarty->fetch('mysqltest:test.tpl');
$tpl = $this->smarty->createTemplate('mysqltest:test.tpl');
$this->assertEquals($this->buildCompiledPath($tpl, false, true, null, 'test.tpl', 'mysqltest', $this->smarty->getTemplateDir(0)), $tpl->compiled->filepath);
$this->assertEquals($this->buildCompiledPath($tpl, false, true, null, 'test.tpl', 'mysqltest', $this->smarty->getTemplateDir(0)), $tpl->getCompiled()->filepath);
$this->smarty->caching = false;
}

View File

@@ -108,7 +108,7 @@ class EvalResourceTest extends PHPUnit_Smarty
public function testGetCompiledFilepath()
{
$tpl = $this->smarty->createTemplate('eval:hello world');
$this->assertFalse($tpl->compiled->filepath);
$this->assertNull($tpl->getCompiled()->filepath);
}
/**
@@ -117,7 +117,7 @@ class EvalResourceTest extends PHPUnit_Smarty
public function testGetCompiledTimestamp()
{
$tpl = $this->smarty->createTemplate('eval:hello world');
$this->assertFalse($tpl->compiled->getTimeStamp());
$this->assertFalse($tpl->getCompiled()->getTimeStamp());
}
/**

View File

@@ -146,6 +146,7 @@ class ExtendsResourceTest extends PHPUnit_Smarty
/**
* test grandchild/child/parent dependency test3
* @group slow
*/
public function testCompileBlockGrandChildMustCompile_021_3()
{

View File

@@ -106,7 +106,7 @@ class FileResourceTest extends PHPUnit_Smarty
{
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertEquals($this->buildCompiledPath($tpl, false, false, null, 'helloworld.tpl', 'file', $this->smarty->getTemplateDir(0))
, $tpl->compiled->filepath
, $tpl->getCompiled()->filepath
);
}
@@ -117,8 +117,8 @@ class FileResourceTest extends PHPUnit_Smarty
{
$tpl = $this->smarty->createTemplate('helloworld.tpl');
// create dummy compiled file
file_put_contents($tpl->compiled->filepath, '<?php ?>');
touch($tpl->compiled->filepath, $tpl->source->getTimeStamp());
file_put_contents($tpl->getCompiled()->filepath, '<?php ?>');
touch($tpl->getCompiled()->filepath, $tpl->source->getTimeStamp());
}
/**
@@ -127,9 +127,9 @@ class FileResourceTest extends PHPUnit_Smarty
public function testGetCompiledTimestamp()
{
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertTrue(is_integer($tpl->compiled->getTimeStamp()));
$this->assertEquals(10, strlen($tpl->compiled->getTimeStamp()));
$this->assertEquals($tpl->compiled->getTimeStamp(), $tpl->source->getTimeStamp());
$this->assertTrue(is_integer($tpl->getCompiled()->getTimeStamp()));
$this->assertEquals(10, strlen($tpl->getCompiled()->getTimeStamp()));
$this->assertEquals($tpl->getCompiled()->getTimeStamp(), $tpl->source->getTimeStamp());
}
public function testMustCompileExisting()
@@ -145,18 +145,18 @@ class FileResourceTest extends PHPUnit_Smarty
$this->assertTrue($tpl->mustCompile());
}
/**
* @doesNotPerformAssertions
*/
public function testMustCompileTouchedSourcePrepare()
{
// touch to prepare next test
sleep(2);
$tpl = $this->smarty->createTemplate('helloworld.tpl');
touch($tpl->source->filepath);
}
public function testMustCompileTouchedSource()
/**
* @group slow
*/
public function testMustCompileTouchedSource()
{
// touch to prepare next test
sleep(2);
$tpl = $this->smarty->createTemplate('helloworld.tpl');
touch($tpl->source->filepath);
$this->setUp();
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertTrue($tpl->mustCompile());
// clean up for next tests
@@ -167,7 +167,7 @@ class FileResourceTest extends PHPUnit_Smarty
{
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$tpl->compileTemplateSource();
$this->assertTrue(file_exists($tpl->compiled->filepath));
$this->assertTrue(file_exists($tpl->getCompiled()->filepath));
}
public function testGetCachedFilepath()
@@ -176,7 +176,7 @@ class FileResourceTest extends PHPUnit_Smarty
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertEquals($this->buildCachedPath($tpl, false, null, null, 'helloworld.tpl', 'file', $this->smarty->getTemplateDir(0), 'file')
, $tpl->cached->filepath
, $tpl->getCached()->filepath
);
}
@@ -188,8 +188,8 @@ class FileResourceTest extends PHPUnit_Smarty
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertTrue(is_integer($tpl->cached->timestamp));
$this->assertEquals(10, strlen($tpl->cached->timestamp));
$this->assertTrue(is_integer($tpl->getCached()->timestamp));
$this->assertEquals(10, strlen($tpl->getCached()->timestamp));
}

View File

@@ -101,7 +101,7 @@ class FileResourceIndexedTest extends PHPUnit_Smarty
public function testGetCompiledFilepath()
{
$tpl = $this->smarty->createTemplate('[foo]dirname.tpl');
$this->assertEquals($this->buildCompiledPath($tpl, false, false, null, 'dirname.tpl', 'file', $this->smarty->getTemplateDir('foo')), $tpl->compiled->filepath);
$this->assertEquals($this->buildCompiledPath($tpl, false, false, null, 'dirname.tpl', 'file', $this->smarty->getTemplateDir('foo')), $tpl->getCompiled()->filepath);
}
public function testGetCachedFilepath()
@@ -110,6 +110,6 @@ class FileResourceIndexedTest extends PHPUnit_Smarty
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('[foo]dirname.tpl');
$this->assertEquals($this->buildCachedPath($tpl, false, null, null, 'dirname.tpl', 'file', $this->smarty->getTemplateDir('foo'))
, $tpl->cached->filepath);
, $tpl->getCached()->filepath);
}
}

View File

@@ -62,7 +62,7 @@ class ResourcePluginTest extends PHPUnit_Smarty
$tpl = $this->smarty->createTemplate('db2:test.tpl');
$expected = realpath('./templates_c/' . sha1('db2:test.tpl') . '.db2.test.tpl.php');
$this->assertFalse(!!$expected);
$this->assertFalse($tpl->compiled->filepath);
$this->assertNull($tpl->getCompiled()->filepath);
}
/**

View File

@@ -97,7 +97,7 @@ class StreamResourceTest extends PHPUnit_Smarty
public function testGetCompiledFilepath()
{
$tpl = $this->smarty->createTemplate('global:mytest');
$this->assertFalse($tpl->compiled->filepath);
$this->assertNull($tpl->getCompiled()->filepath);
}
/**
@@ -106,7 +106,7 @@ class StreamResourceTest extends PHPUnit_Smarty
public function testGetCompiledTimestamp()
{
$tpl = $this->smarty->createTemplate('global:mytest');
$this->assertFalse($tpl->compiled->getTimeStamp());
$this->assertFalse($tpl->getCompiled()->getTimeStamp());
}
/**

View File

@@ -110,7 +110,7 @@ class StringResourceTest extends PHPUnit_Smarty
public function testGetCompiledFilepath()
{
$tpl = $this->smarty->createTemplate('string:hello world');
$this->assertEquals($this->buildCompiledPath($tpl, false, false, null, 'hello world', 'string', $this->smarty->getTemplateDir(0)), $tpl->compiled->filepath);
$this->assertEquals($this->buildCompiledPath($tpl, false, false, null, 'hello world', 'string', $this->smarty->getTemplateDir(0)), $tpl->getCompiled()->filepath);
}
/**
@@ -119,7 +119,7 @@ class StringResourceTest extends PHPUnit_Smarty
public function testGetCompiledTimestamp()
{
$tpl = $this->smarty->createTemplate('string:hello world');
$this->assertFalse($tpl->compiled->getTimeStamp());
$this->assertFalse($tpl->getCompiled()->getTimeStamp());
}
/**
@@ -137,7 +137,7 @@ class StringResourceTest extends PHPUnit_Smarty
public function testGetCachedTimestamp()
{
$tpl = $this->smarty->createTemplate('string:hello world');
$this->assertFalse($tpl->cached->timestamp);
$this->assertFalse($tpl->getCached()->timestamp);
}
/**

View File

@@ -68,7 +68,7 @@ class ClearCompiledTest extends PHPUnit_Smarty
foreach ($compile_ids as $compile_id) {
$tpl = $this->getSmartyObj()->createTemplate($template, null, $compile_id);
$tpl->fetch();
$this->_files[$template . '#' . $compile_id] = substr($tpl->compiled->filepath, $directory_length);
$this->_files[$template . '#' . $compile_id] = substr($tpl->getCompiled()->filepath, $directory_length);
}
}

View File

@@ -608,9 +608,6 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
/**
* test grandchild/child/parent dependency test2
*
*
*
* @group slow
*/
public function testCompileBlockGrandChildMustCompile_021_2()
@@ -642,9 +639,6 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
/**
* test grandchild/child/parent dependency test3
*
*
*
* @group slow
*/
public function testCompileBlockGrandChildMustCompile_021_3()
@@ -689,9 +683,6 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty
/**
* test grandchild/child/parent dependency test4
*
*
*
* @group slow
*/
public function testCompileBlockGrandChildMustCompile_021_4()

View File

@@ -97,7 +97,7 @@ class ScopeTest extends PHPUnit_Smarty
$i++,
],
[
'{append var=foo value=\'newvar\' scope=smarty}', true,
'{append var=foo value=\'newvar\' scope=global}', true,
'#testAppendScope_3.tpl:$foo =\'data\'' .
'#scope_include.tpl:$foo =\'data\'' .
'#scope_tag.tpl:$foo =\'data\'' .
@@ -118,10 +118,10 @@ class ScopeTest extends PHPUnit_Smarty
{
$file = "testAssignScope_{$testNumber}.tpl";
$this->makeTemplateFile($file, $code . '{checkvar var=foo}');
$this->smarty->assignGlobal('file', $file);
$this->smarty->assign('foo', 'smarty');
$this->smarty->assignGlobal('foo', 'global');
$this->smarty->assign('foo', 'global');
$data = $this->smarty->createData($useSmarty ? $this->smarty : null);
$data->assign('file', $file);
$data->assign('foo', 'data');
$tpl = $this->smarty->createTemplate('scope_tag.tpl', $data);
@@ -141,39 +141,48 @@ class ScopeTest extends PHPUnit_Smarty
* result
* test name
*/
return array(array('{$foo = \'newvar\'}', true,
':$foo =\'newvar\'#scope_include.tpl:$foo =\'data\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'',
'', $i ++,), array('{assign var=foo value=\'newvar\'}', true,
':$foo =\'newvar\'#scope_include.tpl:$foo =\'data\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'',
'', $i ++,), array('{$foo = \'newvar\' scope=local}', true,
':$foo =\'newvar\'#scope_include.tpl:$foo =\'data\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'',
'', $i ++,),
array('{assign var=foo value=\'newvar\' scope=local}', true,
':$foo =\'newvar\'#scope_include.tpl:$foo =\'data\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'',
'', $i ++,), array('{$foo = \'newvar\' scope=parent}', true,
':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'',
'', $i ++,), array('{assign var=foo value=\'newvar\' scope=parent}', true,
':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'',
'', $i ++,),
array('{$foo = \'newvar\' scope=tpl_root}', true,
':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'newvar\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'',
'', $i ++,), array('{$foo = \'newvar\' scope=global}', true,
':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'newvar\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'#global:$foo =\'newvar\'',
'', $i ++,), array('{$foo = \'newvar\' scope=root}', true,
':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'newvar\'#data:$foo =\'newvar\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'',
'', $i ++,),
array('{$foo = \'newvar\' scope=root}', false,
':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'newvar\'#data:$foo =\'newvar\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'',
'no smarty', $i ++,), array('{$foo = \'newvar\' scope=smarty}', false,
':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'newvar\'#data:$foo =\'data\'#Smarty:$foo =\'newvar\'#global:$foo =\'global\'',
'no smarty', $i ++,),);
return [
['{$foo = \'newvar\'}', true,
':$foo =\'newvar\'#scope_include.tpl:$foo =\'data\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#global:$foo =\'global\'',
'default', $i++,],
['{assign var=foo value=\'newvar\'}', true,
':$foo =\'newvar\'#scope_include.tpl:$foo =\'data\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#global:$foo =\'global\'',
'assign tag', $i++,],
['{$foo = \'newvar\' scope=local}', true,
':$foo =\'newvar\'#scope_include.tpl:$foo =\'data\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#global:$foo =\'global\'',
'local', $i++,],
['{assign var=foo value=\'newvar\' scope=local}', true,
':$foo =\'newvar\'#scope_include.tpl:$foo =\'data\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#global:$foo =\'global\'',
'assign tag local', $i++,],
['{$foo = \'newvar\' scope=parent}', true,
':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#global:$foo =\'global\'',
'parent', $i++,],
['{assign var=foo value=\'newvar\' scope=parent}', true,
':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#global:$foo =\'global\'',
'assign tag parent', $i++,],
['{$foo = \'newvar\' scope=tpl_root}', true,
':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'newvar\'#data:$foo =\'data\'#global:$foo =\'global\'',
'tpl_root', $i++,],
['{$foo = \'newvar\' scope=global}', true,
':$foo =\'data\'#scope_include.tpl:$foo =\'data\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#global:$foo =\'newvar\'',
'global', $i++,],
['{$foo = \'newvar\' scope=root}', true,
':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'newvar\'#data:$foo =\'newvar\'#global:$foo =\'global\'',
'root', $i++,],
['{$foo = \'newvar\' scope=root}', false,
':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'newvar\'#data:$foo =\'newvar\'#global:$foo =\'global\'',
'root, no smarty', $i++,],
['{$foo = \'newvar\' scope=global}', false,
':$foo =\'data\'#scope_include.tpl:$foo =\'data\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#global:$foo =\'newvar\'',
'global, no smarty', $i++,],
];
}
/**
* Test scope nocache
*
*
*
/**
* Test scope nocache
*
*
*
* @dataProvider dataTestScopeNocache
*/
public function testScopeNocache($var, $file, $result)
@@ -196,13 +205,13 @@ class ScopeTest extends PHPUnit_Smarty
* result
*/
return array(array('b1', 'test_scope_assignbar.tpl',
'#test_scope_assignbar.tpl:$foo =\'b1\'#Smarty:$foo =\'smarty\'#global:$foo =\'b1\'',),
'#test_scope_assignbar.tpl:$foo =\'b1\'#global:$foo =\'b1\'',),
array('b2', 'test_scope_assignbar.tpl',
'#test_scope_assignbar.tpl:$foo =\'b2\'#Smarty:$foo =\'smarty\'#global:$foo =\'b2\'',),
'#test_scope_assignbar.tpl:$foo =\'b2\'#global:$foo =\'b2\'',),
array('b1', 'test_scope_assignnocache.tpl',
'#test_scope_assignnocache.tpl:$foo =\'b1\'#Smarty:$foo =\'smarty\'#global:$foo =\'b1\'',),
'#test_scope_assignnocache.tpl:$foo =\'b1\'#global:$foo =\'b1\'',),
array('b2', 'test_scope_assignnocache.tpl',
'#test_scope_assignnocache.tpl:$foo =\'b2\'#Smarty:$foo =\'smarty\'#global:$foo =\'b2\'',),);
'#test_scope_assignnocache.tpl:$foo =\'b2\'#global:$foo =\'b2\'',),);
}
/**
@@ -216,14 +225,10 @@ class ScopeTest extends PHPUnit_Smarty
{
$file = "testIncludeScope_{$testNumber}.tpl";
$this->makeTemplateFile($file, $code);
$this->smarty->assignGlobal('file', $file);
$this->smarty->assign('foo', 'smarty');
$this->smarty->assignGlobal('foo', 'global');
$this->smarty->assign('foo', 'global');
$data = $this->smarty->createData($useSmarty ? $this->smarty : null);
$data->assign('foo', 'data');
if (!$useSmarty) {
$testName .= 'no smarty';
}
$data->assign('file', $file);
$tpl = $this->smarty->createTemplate('test_scope.tpl', $data);
$this->assertEquals($result, $this->smarty->fetch($tpl), "test - {$code} - {$testName}");
}
@@ -234,44 +239,46 @@ class ScopeTest extends PHPUnit_Smarty
public function dataTestIncludeScope()
{
$i = 0;
return array(/*
* Code
* use Smarty object
* result
* test name
*/
array('{include \'test_scope_assign.tpl\'}', true,
'#test_scope_assign.tpl:$foo =\'newvar\'#testIncludeScope_' . $i .
'.tpl:$foo =\'data\'#test_scope.tpl:$foo =\'data\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'',
'', $i ++), array('{include \'test_scope_assign.tpl\' scope=parent}', true,
'#test_scope_assign.tpl:$foo =\'newvar\'#testIncludeScope_' . $i .
'.tpl:$foo =\'newvar\'#test_scope.tpl:$foo =\'data\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'',
'', $i ++),
array('{include \'test_scope_assign.tpl\' scope=tpl_root}', true,
'#test_scope_assign.tpl:$foo =\'newvar\'#testIncludeScope_' . $i .
'.tpl:$foo =\'newvar\'#test_scope.tpl:$foo =\'newvar\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'',
'', $i ++), array('{include \'test_scope_assign.tpl\' scope=root}', true,
'#test_scope_assign.tpl:$foo =\'newvar\'#testIncludeScope_' . $i .
'.tpl:$foo =\'newvar\'#test_scope.tpl:$foo =\'newvar\'#data:$foo =\'newvar\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'',
'', $i ++), array('{include \'test_scope_assign.tpl\' scope=root}', false,
'#test_scope_assign.tpl:$foo =\'newvar\'#testIncludeScope_' .
$i .
'.tpl:$foo =\'newvar\'#test_scope.tpl:$foo =\'newvar\'#data:$foo =\'newvar\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'',
'', $i ++),
array('{include \'test_scope_assign.tpl\' scope=smarty}', true,
'#test_scope_assign.tpl:$foo =\'newvar\'#testIncludeScope_' . $i .
'.tpl:$foo =\'newvar\'#test_scope.tpl:$foo =\'newvar\'#data:$foo =\'data\'#Smarty:$foo =\'newvar\'#global:$foo =\'global\'',
'', $i ++), array('{include \'test_scope_assign.tpl\' scope=global}', true,
'#test_scope_assign.tpl:$foo =\'newvar\'#testIncludeScope_' . $i .
'.tpl:$foo =\'newvar\'#test_scope.tpl:$foo =\'newvar\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'#global:$foo =\'newvar\'',
'', $i ++),
array('{include \'test_scope_pluginassign.tpl\' scope=global}', true,
'#test_scope_pluginassign.tpl:$foo =\'newvar\'#testIncludeScope_' . $i .
'.tpl:$foo =\'newvar\'#test_scope.tpl:$foo =\'newvar\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'#global:$foo =\'newvar\'',
'', $i ++), array('{include \'test_scope_assign_noscope.tpl\' scope=root}', true,
'#test_scope_assign_noscope.tpl:$foo =\'newvar\'#testIncludeScope_' . $i .
'.tpl:$foo =\'data\'#test_scope.tpl:$foo =\'data\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'#global:$foo =\'global\'',
'', $i ++),);
return [
/*
* Code
* use Smarty object
* result
* test name
*/
['{include \'test_scope_assign.tpl\'}', true,
'#test_scope_assign.tpl:$foo =\'newvar\'#testIncludeScope_' . $i .
'.tpl:$foo =\'data\'#test_scope.tpl:$foo =\'data\'#data:$foo =\'data\'#global:$foo =\'global\'',
'basic', $i++],
['{include \'test_scope_assign.tpl\' scope=parent}', true,
'#test_scope_assign.tpl:$foo =\'newvar\'#testIncludeScope_' . $i .
'.tpl:$foo =\'newvar\'#test_scope.tpl:$foo =\'data\'#data:$foo =\'data\'#global:$foo =\'global\'',
'parent scope', $i++],
['{include \'test_scope_assign.tpl\' scope=tpl_root}', true,
'#test_scope_assign.tpl:$foo =\'newvar\'#testIncludeScope_' . $i .
'.tpl:$foo =\'newvar\'#test_scope.tpl:$foo =\'newvar\'#data:$foo =\'data\'#global:$foo =\'global\'',
'tpl_root scope', $i++],
['{include \'test_scope_assign.tpl\' scope=root}', true,
'#test_scope_assign.tpl:$foo =\'newvar\'#testIncludeScope_' . $i .
'.tpl:$foo =\'newvar\'#test_scope.tpl:$foo =\'newvar\'#data:$foo =\'newvar\'#global:$foo =\'global\'',
'root scope', $i++],
['{include \'test_scope_assign.tpl\' scope=root}', false,
'#test_scope_assign.tpl:$foo =\'newvar\'#testIncludeScope_' . $i .
'.tpl:$foo =\'newvar\'#test_scope.tpl:$foo =\'newvar\'#data:$foo =\'newvar\'#global:$foo =\'global\'',
'root scope / no smarty', $i++],
['{include \'test_scope_assign.tpl\' scope=global}', true,
'#test_scope_assign.tpl:$foo =\'newvar\'#testIncludeScope_' . $i .
'.tpl:$foo =\'newvar\'#test_scope.tpl:$foo =\'newvar\'#data:$foo =\'data\'#global:$foo =\'global\'',
'global scope', $i++],
['{include \'test_scope_pluginassign.tpl\' scope=global}', true,
'#test_scope_pluginassign.tpl:$foo =\'newvar\'#testIncludeScope_' . $i .
'.tpl:$foo =\'newvar\'#test_scope.tpl:$foo =\'newvar\'#data:$foo =\'data\'#global:$foo =\'newvar\'',
'pluginassign global', $i++],
['{include \'test_scope_assign_noscope.tpl\' scope=root}', true,
'#test_scope_assign_noscope.tpl:$foo =\'newvar\'#testIncludeScope_' . $i .
'.tpl:$foo =\'data\'#test_scope.tpl:$foo =\'data\'#data:$foo =\'data\'#global:$foo =\'global\'',
'noscope root', $i++],
];
}
/**
@@ -310,21 +317,21 @@ class ScopeTest extends PHPUnit_Smarty
* test name
*/
return array(array('{config_load \'template.conf\'}', true,
':$foo =\'newvar\'#scope_include.tpl:$foo =\'data\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'',
':$foo =\'newvar\'#scope_include.tpl:$foo =\'data\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'',
'', $i ++,), array('{config_load \'template.conf\' scope=local}', true,
':$foo =\'newvar\'#scope_include.tpl:$foo =\'data\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'',
':$foo =\'newvar\'#scope_include.tpl:$foo =\'data\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'',
'', $i ++,), array('{config_load \'template.conf\' scope=parent}', true,
':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'',
':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'data\'#data:$foo =\'data\'',
'', $i ++,),
array('{config_load \'template.conf\' scope=tpl_root}', true,
':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'newvar\'#data:$foo =\'data\'#Smarty:$foo =\'smarty\'',
':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'newvar\'#data:$foo =\'data\'',
'', $i ++,), array('{config_load \'template.conf\' scope=root}', true,
':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'newvar\'#data:$foo =\'newvar\'#Smarty:$foo =\'smarty\'',
':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'newvar\'#data:$foo =\'newvar\'',
'', $i ++,), array('{config_load \'template.conf\' scope=root}', false,
':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'newvar\'#data:$foo =\'newvar\'#Smarty:$foo =\'smarty\'',
':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'newvar\'#data:$foo =\'newvar\'',
'no smarty', $i ++,),
array('{config_load \'template.conf\' scope=smarty}', false,
':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'newvar\'#data:$foo =\'data\'#Smarty:$foo =\'newvar\'',
array('{config_load \'template.conf\' scope=global}', false,
':$foo =\'newvar\'#scope_include.tpl:$foo =\'newvar\'#scope_tag.tpl:$foo =\'newvar\'#data:$foo =\'data\'#global:$foo =\'newvar\'',
'no smarty', $i ++,),);
}

View File

@@ -6,7 +6,6 @@
*/
use Smarty\DataObject;
use Smarty\Template;
/**
@@ -20,7 +19,7 @@ use Smarty\Template;
function smarty_function_checkconfigvar($params, $template)
{
$output = '';
$types = array('template', 'data', 'smarty');
$types = array('template', 'data', 'global');
if (isset($params['types'])) {
$types = (array)$params['types'];
}
@@ -29,20 +28,20 @@ function smarty_function_checkconfigvar($params, $template)
while ($ptr) {
if (in_array('template', $types) && $ptr instanceof Template) {
$output .= "#{$ptr->source->name}:\${$var} =";
$output .= isset($ptr->config_vars[$var]) ? preg_replace('/\s/', '', var_export($ptr->config_vars[$var], true)) : 'null';
$output .= $ptr->hasConfigVariable($var) ? preg_replace('/\s/', '', var_export($ptr->getConfigVariable($var), true)) : 'null';
$ptr = $ptr->parent;
} elseif (in_array('data', $types) && $ptr instanceof DataObject) {
} elseif (in_array('data', $types) && !($ptr instanceof Template || $ptr instanceof Smarty)) {
$output .= "#data:\${$var} =";
$output .= isset($ptr->config_vars[$var]) ? preg_replace('/\s/', '', var_export($ptr->config_vars[$var], true)) : 'null';
$output .= $ptr->hasConfigVariable($var) ? preg_replace('/\s/', '', var_export($ptr->getConfigVariable($var), true)) : 'null';
$ptr = $ptr->parent;
} else {
$ptr = null;
}
}
if (in_array('smarty', $types)) {
$output .= "#Smarty:\${$var} =";
$output .= isset($template->smarty->config_vars[ $var ]) ?
preg_replace('/\s/', '', var_export($template->smarty->config_vars[ $var ], true)) : 'null';
if (in_array('global', $types)) {
$output .= "#global:\${$var} =";
$output .= $template->smarty->hasConfigVariable($var) ?
preg_replace('/\s/', '', var_export($template->smarty->getConfigVariable($var), true)) : 'null';
}
return $output;
}

View File

@@ -6,7 +6,6 @@
*/
use Smarty\DataObject;
use Smarty\Template;
/**
@@ -37,7 +36,7 @@ function smarty_function_checkvar($params, \Smarty\Template $template)
$i ++;
}
$ptr = $ptr->parent;
} elseif (in_array('data', $types) && $ptr instanceof DataObject) {
} elseif (in_array('data', $types) && !($ptr instanceof Template || $ptr instanceof Smarty)) {
$output .= "#data:\${$var} =";
$output .= $ptr->hasVariable($var) ? preg_replace('/\s/', '', var_export($ptr->getValue($var), true)) : '>unassigned<';
$ptr = $ptr->parent;