Replaced a bunch of direct property access with getters/setters.

This commit is contained in:
Simon Wisselink
2023-01-13 16:55:15 +01:00
parent 3be63a3418
commit 5c74dc4a83
68 changed files with 684 additions and 585 deletions

View File

@@ -2,6 +2,7 @@
namespace Smarty\Cacheresource; namespace Smarty\Cacheresource;
use Smarty\Exception;
use Smarty\Smarty; use Smarty\Smarty;
use Smarty\Template; use Smarty\Template;
use Smarty\Template\Cached; use Smarty\Template\Cached;
@@ -76,16 +77,17 @@ abstract class Base
*/ */
abstract public function retrieveCachedContent(Template $_template); abstract public function retrieveCachedContent(Template $_template);
/** /**
* Return cached content * Return cached content
* *
* @param Template $_template template object * @param Template $_template template object
* *
* @return null|string * @return null|string
*/ * @throws Exception
*/
public function getCachedContent(Template $_template) public function getCachedContent(Template $_template)
{ {
if ($_template->getCached()->handler->process($_template)) { if ($this->process($_template)) {
ob_start(); ob_start();
$unifunc = $_template->getCached()->unifunc; $unifunc = $_template->getCached()->unifunc;
$unifunc($_template); $unifunc($_template);

View File

@@ -91,9 +91,9 @@ abstract class Custom extends Base
{ {
$_cache_id = isset($cached->cache_id) ? preg_replace('![^\w\|]+!', '_', $cached->cache_id) : null; $_cache_id = isset($cached->cache_id) ? preg_replace('![^\w\|]+!', '_', $cached->cache_id) : null;
$_compile_id = isset($cached->compile_id) ? preg_replace('![^\w]+!', '_', $cached->compile_id) : null; $_compile_id = isset($cached->compile_id) ? preg_replace('![^\w]+!', '_', $cached->compile_id) : null;
$path = $cached->source->uid . $_cache_id . $_compile_id; $path = $cached->getSource()->uid . $_cache_id . $_compile_id;
$cached->filepath = sha1($path); $cached->filepath = sha1($path);
if ($_template->smarty->cache_locking) { if ($_template->getSmarty()->cache_locking) {
$cached->lock_id = sha1('lock.' . $path); $cached->lock_id = sha1('lock.' . $path);
} }
$this->populateTimestamp($cached); $this->populateTimestamp($cached);
@@ -109,7 +109,7 @@ abstract class Custom extends Base
public function populateTimestamp(\Smarty\Template\Cached $cached) public function populateTimestamp(\Smarty\Template\Cached $cached)
{ {
$mtime = $mtime =
$this->fetchTimestamp($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id); $this->fetchTimestamp($cached->filepath, $cached->getSource()->name, $cached->cache_id, $cached->compile_id);
if ($mtime !== null) { if ($mtime !== null) {
$cached->timestamp = $mtime; $cached->timestamp = $mtime;
$cached->exists = !!$cached->timestamp; $cached->exists = !!$cached->timestamp;
@@ -118,7 +118,7 @@ abstract class Custom extends Base
$timestamp = null; $timestamp = null;
$this->fetch( $this->fetch(
$cached->filepath, $cached->filepath,
$cached->source->name, $cached->getSource()->name,
$cached->cache_id, $cached->cache_id,
$cached->compile_id, $cached->compile_id,
$cached->content, $cached->content,
@@ -150,7 +150,7 @@ abstract class Custom extends Base
if ($content === null || !$timestamp) { if ($content === null || !$timestamp) {
$this->fetch( $this->fetch(
$_smarty_tpl->getCached()->filepath, $_smarty_tpl->getCached()->filepath,
$_smarty_tpl->source->name, $_smarty_tpl->getSource()->name,
$_smarty_tpl->cache_id, $_smarty_tpl->cache_id,
$_smarty_tpl->compile_id, $_smarty_tpl->compile_id,
$content, $content,
@@ -177,7 +177,7 @@ abstract class Custom extends Base
{ {
return $this->save( return $this->save(
$_template->getCached()->filepath, $_template->getCached()->filepath,
$_template->source->name, $_template->getSource()->name,
$_template->cache_id, $_template->cache_id,
$_template->compile_id, $_template->compile_id,
$_template->cache_lifetime, $_template->cache_lifetime,
@@ -199,7 +199,7 @@ abstract class Custom extends Base
$timestamp = null; $timestamp = null;
$this->fetch( $this->fetch(
$_template->getCached()->filepath, $_template->getCached()->filepath,
$_template->source->name, $_template->getSource()->name,
$_template->cache_id, $_template->cache_id,
$_template->compile_id, $_template->compile_id,
$content, $content,
@@ -262,7 +262,7 @@ abstract class Custom extends Base
public function hasLock(\Smarty\Smarty $smarty, \Smarty\Template\Cached $cached) public function hasLock(\Smarty\Smarty $smarty, \Smarty\Template\Cached $cached)
{ {
$id = $cached->lock_id; $id = $cached->lock_id;
$name = $cached->source->name . '.lock'; $name = $cached->getSource()->name . '.lock';
$mtime = $this->fetchTimestamp($id, $name, $cached->cache_id, $cached->compile_id); $mtime = $this->fetchTimestamp($id, $name, $cached->cache_id, $cached->compile_id);
if ($mtime === null) { if ($mtime === null) {
$this->fetch($id, $name, $cached->cache_id, $cached->compile_id, $content, $mtime); $this->fetch($id, $name, $cached->cache_id, $cached->compile_id, $content, $mtime);
@@ -282,7 +282,7 @@ abstract class Custom extends Base
{ {
$cached->is_locked = true; $cached->is_locked = true;
$id = $cached->lock_id; $id = $cached->lock_id;
$name = $cached->source->name . '.lock'; $name = $cached->getSource()->name . '.lock';
$this->save($id, $name, $cached->cache_id, $cached->compile_id, $smarty->locking_timeout, ''); $this->save($id, $name, $cached->cache_id, $cached->compile_id, $smarty->locking_timeout, '');
} }
@@ -297,7 +297,7 @@ abstract class Custom extends Base
public function releaseLock(\Smarty\Smarty $smarty, \Smarty\Template\Cached $cached) public function releaseLock(\Smarty\Smarty $smarty, \Smarty\Template\Cached $cached)
{ {
$cached->is_locked = false; $cached->is_locked = false;
$name = $cached->source->name . '.lock'; $name = $cached->getSource()->name . '.lock';
$this->delete($name, $cached->cache_id, $cached->compile_id, null); $this->delete($name, $cached->cache_id, $cached->compile_id, null);
} }
} }

View File

@@ -33,8 +33,8 @@ class File extends Base
*/ */
public function populate(Cached $cached, Template $_template) public function populate(Cached $cached, Template $_template)
{ {
$source = &$_template->source; $source = $_template->getSource();
$smarty = &$_template->smarty; $smarty = $_template->getSmarty();
$_compile_dir_sep = $smarty->use_sub_dirs ? DIRECTORY_SEPARATOR : '^'; $_compile_dir_sep = $smarty->use_sub_dirs ? DIRECTORY_SEPARATOR : '^';
$_filepath = sha1($source->uid . $smarty->_joined_template_dir); $_filepath = sha1($source->uid . $smarty->_joined_template_dir);
$cached->filepath = $smarty->getCacheDir(); $cached->filepath = $smarty->getCacheDir();
@@ -125,7 +125,7 @@ class File extends Base
*/ */
public function storeCachedContent(Template $_template, $content) public function storeCachedContent(Template $_template, $content)
{ {
if ($_template->smarty->writeFile($_template->getCached()->filepath, $content) === true) { if ($_template->getSmarty()->writeFile($_template->getCached()->filepath, $content) === true) {
if (function_exists('opcache_invalidate') if (function_exists('opcache_invalidate')
&& (!function_exists('ini_get') || strlen(ini_get('opcache.restrict_api'))) < 1 && (!function_exists('ini_get') || strlen(ini_get('opcache.restrict_api'))) < 1
) { ) {
@@ -208,8 +208,7 @@ class File extends Base
$tpl = new \Smarty\Template($resource_name, $smarty); $tpl = new \Smarty\Template($resource_name, $smarty);
$smarty->caching = $_save_stat; $smarty->caching = $_save_stat;
// remove from template cache // remove from template cache
$tpl->source; // have the template registered before unset() if ($tpl->getSource()->exists) {
if ($tpl->source->exists) {
$_resourcename_parts = basename(str_replace('^', '/', $tpl->getCached()->filepath)); $_resourcename_parts = basename(str_replace('^', '/', $tpl->getCached()->filepath));
} else { } else {
return 0; return 0;

View File

@@ -61,7 +61,7 @@ abstract class KeyValueStore extends Base
*/ */
public function populate(Cached $cached, Template $_template) public function populate(Cached $cached, Template $_template)
{ {
$cached->filepath = $_template->source->uid . '#' . $this->sanitize($cached->source->resource) . '#' . $cached->filepath = $_template->getSource()->uid . '#' . $this->sanitize($cached->getSource()->resource) . '#' .
$this->sanitize($cached->cache_id) . '#' . $this->sanitize($cached->compile_id); $this->sanitize($cached->cache_id) . '#' . $this->sanitize($cached->compile_id);
$this->populateTimestamp($cached); $this->populateTimestamp($cached);
} }
@@ -77,12 +77,12 @@ abstract class KeyValueStore extends Base
{ {
if (!$this->fetch( if (!$this->fetch(
$cached->filepath, $cached->filepath,
$cached->source->name, $cached->getSource()->name,
$cached->cache_id, $cached->cache_id,
$cached->compile_id, $cached->compile_id,
$content, $content,
$timestamp, $timestamp,
$cached->source->uid $cached->getSource()->uid
) )
) { ) {
return; return;
@@ -114,12 +114,12 @@ abstract class KeyValueStore extends Base
if ($content === null || !$timestamp) { if ($content === null || !$timestamp) {
if (!$this->fetch( if (!$this->fetch(
$_smarty_tpl->getCached()->filepath, $_smarty_tpl->getCached()->filepath,
$_smarty_tpl->source->name, $_smarty_tpl->getSource()->name,
$_smarty_tpl->cache_id, $_smarty_tpl->cache_id,
$_smarty_tpl->compile_id, $_smarty_tpl->compile_id,
$content, $content,
$timestamp, $timestamp,
$_smarty_tpl->source->uid $_smarty_tpl->getSource()->uid
) )
) { ) {
return false; return false;
@@ -160,12 +160,12 @@ abstract class KeyValueStore extends Base
if ($content === null) { if ($content === null) {
if (!$this->fetch( if (!$this->fetch(
$_template->getCached()->filepath, $_template->getCached()->filepath,
$_template->source->name, $_template->getSource()->name,
$_template->cache_id, $_template->cache_id,
$_template->compile_id, $_template->compile_id,
$content, $content,
$timestamp, $timestamp,
$_template->source->uid $_template->getSource()->uid
) )
) { ) {
return false; return false;

View File

@@ -214,8 +214,8 @@ abstract class Base implements CompilerInterface {
} }
} }
// wrong nesting of tags // wrong nesting of tags
$compiler->trigger_template_error("unclosed '" . $compiler->template->getLeftDelimiter() . "{$_openTag}" . $compiler->trigger_template_error("unclosed '" . $compiler->getTemplate()->getLeftDelimiter() . "{$_openTag}" .
$compiler->template->getRightDelimiter() . "' tag"); $compiler->getTemplate()->getRightDelimiter() . "' tag");
return; return;
} }
// wrong nesting of tags // wrong nesting of tags

View File

@@ -70,7 +70,7 @@ class BlockCompiler extends Base {
* @return string * @return string
*/ */
protected function getIsCallableCode($tag, $function): string { protected function getIsCallableCode($tag, $function): string {
return "\$_smarty_tpl->smarty->getBlockHandler(" . var_export($function, true) . ")"; return "\$_smarty_tpl->getSmarty()->getBlockHandler(" . var_export($function, true) . ")";
} }
/** /**
@@ -82,7 +82,7 @@ class BlockCompiler extends Base {
* @return string * @return string
*/ */
protected function getFullCallbackCode($tag, $function): string { protected function getFullCallbackCode($tag, $function): string {
return "\$_smarty_tpl->smarty->getBlockHandler(" . var_export($function, true) . ")->handle"; return "\$_smarty_tpl->getSmarty()->getBlockHandler(" . var_export($function, true) . ")->handle";
} }
/** /**

View File

@@ -7,7 +7,7 @@ class DefaultHandlerBlockCompiler extends BlockCompiler {
* @inheritDoc * @inheritDoc
*/ */
protected function getIsCallableCode($tag, $function): string { protected function getIsCallableCode($tag, $function): string {
return "\$_smarty_tpl->smarty->getRuntime('DefaultPluginHandler')->hasPlugin(" . return "\$_smarty_tpl->getSmarty()->getRuntime('DefaultPluginHandler')->hasPlugin(" .
var_export($function, true) . ", 'block')"; var_export($function, true) . ", 'block')";
} }
@@ -15,7 +15,7 @@ class DefaultHandlerBlockCompiler extends BlockCompiler {
* @inheritDoc * @inheritDoc
*/ */
protected function getFullCallbackCode($tag, $function): string { protected function getFullCallbackCode($tag, $function): string {
return "\$_smarty_tpl->smarty->getRuntime('DefaultPluginHandler')->getCallback(" . return "\$_smarty_tpl->getSmarty()->getRuntime('DefaultPluginHandler')->getCallback(" .
var_export($function, true) . ", 'block')"; var_export($function, true) . ", 'block')";
} }
} }

View File

@@ -35,7 +35,7 @@ class DefaultHandlerFunctionCallCompiler extends Base {
$_paramsArray = $this->formatParamsArray($_attr); $_paramsArray = $this->formatParamsArray($_attr);
$_params = 'array(' . implode(',', $_paramsArray) . ')'; $_params = 'array(' . implode(',', $_paramsArray) . ')';
$output = "\$_smarty_tpl->smarty->getRuntime('DefaultPluginHandler')->getCallback(" . var_export($function, true) . $output = "\$_smarty_tpl->getSmarty()->getRuntime('DefaultPluginHandler')->getCallback(" . var_export($function, true) .
",'function')($_params, \$_smarty_tpl)"; ",'function')($_params, \$_smarty_tpl)";
if (!empty($parameter['modifierlist'])) { if (!empty($parameter['modifierlist'])) {

View File

@@ -55,7 +55,7 @@ class FunctionCallCompiler extends Base {
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
unset($_attr['nocache']); unset($_attr['nocache']);
if (!$functionHandler = $compiler->smarty->getFunctionHandler($function)) { if (!$functionHandler = $compiler->getSmarty()->getFunctionHandler($function)) {
throw new CompilerException("Cannot compile unknown function $function."); throw new CompilerException("Cannot compile unknown function $function.");
} }
@@ -66,7 +66,7 @@ class FunctionCallCompiler extends Base {
$_params = 'array(' . implode(',', $_paramsArray) . ')'; $_params = 'array(' . implode(',', $_paramsArray) . ')';
$output = "\$_smarty_tpl->smarty->getFunctionHandler(" . var_export($function, true) . ")"; $output = "\$_smarty_tpl->getSmarty()->getFunctionHandler(" . var_export($function, true) . ")";
$output .= "->handle($_params, \$_smarty_tpl)"; $output .= "->handle($_params, \$_smarty_tpl)";
if (!empty($parameter['modifierlist'])) { if (!empty($parameter['modifierlist'])) {

View File

@@ -50,6 +50,6 @@ class EscapeModifierCompiler extends Base {
} catch (Exception $e) { } catch (Exception $e) {
// pass through to regular plugin fallback // pass through to regular plugin fallback
} }
return '$_smarty_tpl->smarty->getModifierCallback(\'escape\')(' . join(', ', $params) . ')'; return '$_smarty_tpl->getSmarty()->getModifierCallback(\'escape\')(' . join(', ', $params) . ')';
} }
} }

View File

@@ -45,8 +45,8 @@ class ModifierCompiler extends Base {
$single_modifier[0] = $output; $single_modifier[0] = $output;
$params = implode(',', $single_modifier); $params = implode(',', $single_modifier);
if (!is_object($compiler->smarty->security_policy) if (!is_object($compiler->getSmarty()->security_policy)
|| $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler) || $compiler->getSmarty()->security_policy->isTrustedModifier($modifier, $compiler)
) { ) {
if ($handler = $compiler->getModifierCompiler($modifier)) { if ($handler = $compiler->getModifierCompiler($modifier)) {
@@ -54,7 +54,7 @@ class ModifierCompiler extends Base {
} elseif ($compiler->getSmarty()->getModifierCallback($modifier)) { } elseif ($compiler->getSmarty()->getModifierCallback($modifier)) {
$output = sprintf( $output = sprintf(
'$_smarty_tpl->smarty->getModifierCallback(%s)(%s)', '$_smarty_tpl->getSmarty()->getModifierCallback(%s)(%s)',
var_export($modifier, true), var_export($modifier, true),
$params $params
); );

View File

@@ -22,7 +22,7 @@ class ObjectMethodBlockCompiler extends BlockCompiler {
* @inheritDoc * @inheritDoc
*/ */
protected function getIsCallableCode($tag, $function): string { protected function getIsCallableCode($tag, $function): string {
$callbackObject = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]"; $callbackObject = "\$_smarty_tpl->getSmarty()->registered_objects['{$tag}'][0]";
return "(isset({$callbackObject}) && is_callable(array({$callbackObject}, '{$function}')))"; return "(isset({$callbackObject}) && is_callable(array({$callbackObject}, '{$function}')))";
} }
@@ -30,7 +30,7 @@ class ObjectMethodBlockCompiler extends BlockCompiler {
* @inheritDoc * @inheritDoc
*/ */
protected function getFullCallbackCode($tag, $function): string { protected function getFullCallbackCode($tag, $function): string {
$callbackObject = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]"; $callbackObject = "\$_smarty_tpl->getSmarty()->registered_objects['{$tag}'][0]";
return "{$callbackObject}->{$function}"; return "{$callbackObject}->{$function}";
} }

View File

@@ -49,19 +49,19 @@ class ObjectMethodCallCompiler extends Base {
unset($_attr['assign']); unset($_attr['assign']);
} }
// method or property ? // method or property ?
if (is_callable([$compiler->smarty->registered_objects[$tag][0], $function])) { if (is_callable([$compiler->getSmarty()->registered_objects[$tag][0], $function])) {
// convert attributes into parameter array string // convert attributes into parameter array string
if ($compiler->smarty->registered_objects[$tag][2]) { if ($compiler->getSmarty()->registered_objects[$tag][2]) {
$_paramsArray = $this->formatParamsArray($_attr); $_paramsArray = $this->formatParamsArray($_attr);
$_params = 'array(' . implode(',', $_paramsArray) . ')'; $_params = 'array(' . implode(',', $_paramsArray) . ')';
$output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$function}({$_params},\$_smarty_tpl)"; $output = "\$_smarty_tpl->getSmarty()->registered_objects['{$tag}'][0]->{$function}({$_params},\$_smarty_tpl)";
} else { } else {
$_params = implode(',', $_attr); $_params = implode(',', $_attr);
$output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$function}({$_params})"; $output = "\$_smarty_tpl->getSmarty()->registered_objects['{$tag}'][0]->{$function}({$_params})";
} }
} else { } else {
// object property // object property
$output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$function}"; $output = "\$_smarty_tpl->getSmarty()->registered_objects['{$tag}'][0]->{$function}";
} }
if (!empty($parameter['modifierlist'])) { if (!empty($parameter['modifierlist'])) {
$output = $compiler->compileModifier($parameter['modifierlist'], $output); $output = $compiler->compileModifier($parameter['modifierlist'], $output);

View File

@@ -65,9 +65,9 @@ class PrintExpressionCompiler extends Base {
// display value // display value
if (!$_attr['nofilter']) { if (!$_attr['nofilter']) {
// default modifier // default modifier
if ($compiler->smarty->getDefaultModifiers()) { if ($compiler->getSmarty()->getDefaultModifiers()) {
$modifierlist = []; $modifierlist = [];
foreach ($compiler->smarty->getDefaultModifiers() as $key => $single_default_modifier) { foreach ($compiler->getSmarty()->getDefaultModifiers() as $key => $single_default_modifier) {
preg_match_all( preg_match_all(
'/(\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|:|[^:]+)/', '/(\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|:|[^:]+)/',
$single_default_modifier, $single_default_modifier,
@@ -83,7 +83,7 @@ class PrintExpressionCompiler extends Base {
$output = $compiler->compileModifier($modifierlist, $output); $output = $compiler->compileModifier($modifierlist, $output);
} }
if ($compiler->template->smarty->escape_html) { if ($compiler->getTemplate()->getSmarty()->escape_html) {
$output = "htmlspecialchars((string) {$output}, ENT_QUOTES, '" . addslashes(\Smarty\Smarty::$_CHARSET) . "')"; $output = "htmlspecialchars((string) {$output}, ENT_QUOTES, '" . addslashes(\Smarty\Smarty::$_CHARSET) . "')";
} }

View File

@@ -46,8 +46,8 @@ class SpecialVariableCompiler extends Base {
if ($variable === false) { if ($variable === false) {
$compiler->trigger_template_error("special \$Smarty variable name index can not be variable", null, true); $compiler->trigger_template_error("special \$Smarty variable name index can not be variable", null, true);
} }
if (!isset($compiler->smarty->security_policy) if (!isset($compiler->getSmarty()->security_policy)
|| $compiler->smarty->security_policy->isTrustedSpecialSmartyVar($variable, $compiler) || $compiler->getSmarty()->security_policy->isTrustedSpecialSmartyVar($variable, $compiler)
) { ) {
switch ($variable) { switch ($variable) {
case 'foreach': case 'foreach':
@@ -59,8 +59,8 @@ class SpecialVariableCompiler extends Base {
case 'now': case 'now':
return 'time()'; return 'time()';
case 'cookies': case 'cookies':
if (isset($compiler->smarty->security_policy) if (isset($compiler->getSmarty()->security_policy)
&& !$compiler->smarty->security_policy->allow_super_globals && !$compiler->getSmarty()->security_policy->allow_super_globals
) { ) {
$compiler->trigger_template_error("(secure mode) super globals not permitted"); $compiler->trigger_template_error("(secure mode) super globals not permitted");
break; break;
@@ -73,8 +73,8 @@ class SpecialVariableCompiler extends Base {
case 'server': case 'server':
case 'session': case 'session':
case 'request': case 'request':
if (isset($compiler->smarty->security_policy) if (isset($compiler->getSmarty()->security_policy)
&& !$compiler->smarty->security_policy->allow_super_globals && !$compiler->getSmarty()->security_policy->allow_super_globals
) { ) {
$compiler->trigger_template_error("(secure mode) super globals not permitted"); $compiler->trigger_template_error("(secure mode) super globals not permitted");
break; break;
@@ -82,20 +82,20 @@ class SpecialVariableCompiler extends Base {
$compiled_ref = '$_' . smarty_strtoupper_ascii($variable); $compiled_ref = '$_' . smarty_strtoupper_ascii($variable);
break; break;
case 'template': case 'template':
return 'basename($_smarty_tpl->source->filepath)'; return 'basename($_smarty_tpl->getSource()->filepath)';
case 'template_object': case 'template_object':
if (isset($compiler->smarty->security_policy)) { if (isset($compiler->getSmarty()->security_policy)) {
$compiler->trigger_template_error("(secure mode) template_object not permitted"); $compiler->trigger_template_error("(secure mode) template_object not permitted");
break; break;
} }
return '$_smarty_tpl'; return '$_smarty_tpl';
case 'current_dir': case 'current_dir':
return 'dirname($_smarty_tpl->source->filepath)'; return 'dirname($_smarty_tpl->getSource()->filepath)';
case 'version': case 'version':
return "\\Smarty\\Smarty::SMARTY_VERSION"; return "\\Smarty\\Smarty::SMARTY_VERSION";
case 'const': case 'const':
if (isset($compiler->smarty->security_policy) if (isset($compiler->getSmarty()->security_policy)
&& !$compiler->smarty->security_policy->allow_constants && !$compiler->getSmarty()->security_policy->allow_constants
) { ) {
$compiler->trigger_template_error("(secure mode) constants not permitted"); $compiler->trigger_template_error("(secure mode) constants not permitted");
break; break;

View File

@@ -17,6 +17,6 @@ class BCPluginWrapper extends Base {
* @inheritDoc * @inheritDoc
*/ */
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) { public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
return call_user_func($this->callback, $args, $compiler->smarty); return call_user_func($this->callback, $args, $compiler->getSmarty());
} }
} }

View File

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

View File

@@ -34,9 +34,9 @@ class BlockClose extends Inheritance {
} }
$_className = $compiler->_cache['blockClass'][$compiler->_cache['blockNesting']]; $_className = $compiler->_cache['blockClass'][$compiler->_cache['blockNesting']];
// get compiled block code // get compiled block code
$_functionCode = $compiler->parser->current_buffer; $_functionCode = $compiler->getParser()->current_buffer;
// setup buffer for template function code // setup buffer for template function code
$compiler->parser->current_buffer = new Template(); $compiler->getParser()->current_buffer = new Template();
$output = "<?php\n"; $output = "<?php\n";
$output .= $compiler->cStyleComment(" {block {$_name}} ") . "\n"; $output .= $compiler->cStyleComment(" {block {$_name}} ") . "\n";
$output .= "class {$_className} extends \\Smarty\\Runtime\\Block\n"; $output .= "class {$_className} extends \\Smarty\\Runtime\\Block\n";
@@ -45,21 +45,21 @@ class BlockClose extends Inheritance {
$output .= "public \${$property} = " . var_export($value, true) . ";\n"; $output .= "public \${$property} = " . var_export($value, true) . ";\n";
} }
$output .= "public function callBlock(\\Smarty\\Template \$_smarty_tpl) {\n"; $output .= "public function callBlock(\\Smarty\\Template \$_smarty_tpl) {\n";
if ($compiler->template->getCompiled()->getNocacheCode()) { if ($compiler->getTemplate()->getCompiled()->getNocacheCode()) {
$output .= "\$_smarty_tpl->getCached()->hashes['{$compiler->template->getCompiled()->nocache_hash}'] = true;\n"; $output .= "\$_smarty_tpl->getCached()->hashes['{$compiler->getTemplate()->getCompiled()->nocache_hash}'] = true;\n";
} }
if (isset($_assign)) { if (isset($_assign)) {
$output .= "ob_start();\n"; $output .= "ob_start();\n";
} }
$output .= "?>\n"; $output .= "?>\n";
$compiler->parser->current_buffer->append_subtree( $compiler->getParser()->current_buffer->append_subtree(
$compiler->parser, $compiler->getParser(),
new \Smarty\ParseTree\Tag( new \Smarty\ParseTree\Tag(
$compiler->parser, $compiler->getParser(),
$output $output
) )
); );
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode); $compiler->getParser()->current_buffer->append_subtree($compiler->getParser(), $_functionCode);
$output = "<?php\n"; $output = "<?php\n";
if (isset($_assign)) { if (isset($_assign)) {
$output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n"; $output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n";
@@ -68,20 +68,20 @@ class BlockClose extends Inheritance {
$output .= "}\n"; $output .= "}\n";
$output .= $compiler->cStyleComment(" {/block {$_name}} ") . "\n\n"; $output .= $compiler->cStyleComment(" {/block {$_name}} ") . "\n\n";
$output .= "?>\n"; $output .= "?>\n";
$compiler->parser->current_buffer->append_subtree( $compiler->getParser()->current_buffer->append_subtree(
$compiler->parser, $compiler->getParser(),
new \Smarty\ParseTree\Tag( new \Smarty\ParseTree\Tag(
$compiler->parser, $compiler->getParser(),
$output $output
) )
); );
$compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser); $compiler->blockOrFunctionCode .= $compiler->getParser()->current_buffer->to_smarty_php($compiler->getParser());
$compiler->parser->current_buffer = new Template(); $compiler->getParser()->current_buffer = new Template();
// restore old status // restore old status
$compiler->template->getCompiled()->setNocacheCode($_has_nocache_code); $compiler->getTemplate()->getCompiled()->setNocacheCode($_has_nocache_code);
$compiler->tag_nocache = $compiler->nocache; $compiler->tag_nocache = $compiler->nocache;
$compiler->nocache = $_nocache; $compiler->nocache = $_nocache;
$compiler->parser->current_buffer = $_buffer; $compiler->getParser()->current_buffer = $_buffer;
$output = "<?php \n"; $output = "<?php \n";
if ($compiler->_cache['blockNesting'] === 1) { if ($compiler->_cache['blockNesting'] === 1) {
$output .= "\$_smarty_tpl->getInheritance()->instanceBlock(\$_smarty_tpl, '$_className', $_name);\n"; $output .= "\$_smarty_tpl->getInheritance()->instanceBlock(\$_smarty_tpl, '$_className', $_name);\n";

View File

@@ -59,7 +59,7 @@ class Call extends Base {
$_name = $_attr['name']; $_name = $_attr['name'];
unset($_attr['name'], $_attr['assign'], $_attr['nocache']); unset($_attr['name'], $_attr['assign'], $_attr['nocache']);
// set flag (compiled code of {function} must be included in cache file // set flag (compiled code of {function} must be included in cache file
if (!$compiler->template->caching || $compiler->nocache || $compiler->tag_nocache) { if (!$compiler->getTemplate()->caching || $compiler->nocache || $compiler->tag_nocache) {
$_nocache = 'true'; $_nocache = 'true';
} else { } else {
$_nocache = 'false'; $_nocache = 'false';
@@ -70,10 +70,10 @@ class Call extends Base {
// was there an assign attribute // was there an assign attribute
if (isset($_assign)) { if (isset($_assign)) {
$_output = $_output =
"<?php ob_start();\n\$_smarty_tpl->smarty->getRuntime('TplFunction')->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});\n\$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n"; "<?php ob_start();\n\$_smarty_tpl->getSmarty()->getRuntime('TplFunction')->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});\n\$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
} else { } else {
$_output = $_output =
"<?php \$_smarty_tpl->smarty->getRuntime('TplFunction')->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});?>\n"; "<?php \$_smarty_tpl->getSmarty()->getRuntime('TplFunction')->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});?>\n";
} }
return $_output; return $_output;
} }

View File

@@ -40,7 +40,7 @@ class Capture extends Base {
\Smarty\Compiler\Template $compiler, \Smarty\Compiler\Template $compiler,
$parameter = null $parameter = null
) { ) {
return '$_smarty_tpl->smarty->getRuntime(\'Capture\')->getBuffer($_smarty_tpl' . return '$_smarty_tpl->getSmarty()->getRuntime(\'Capture\')->getBuffer($_smarty_tpl' .
(isset($parameter[1]) ? ", {$parameter[ 1 ]})" : ')'); (isset($parameter[1]) ? ", {$parameter[ 1 ]})" : ')');
} }
@@ -62,7 +62,7 @@ class Capture extends Base {
$compiler->_cache['capture_stack'][] = [$compiler->nocache]; $compiler->_cache['capture_stack'][] = [$compiler->nocache];
// maybe nocache because of nocache variables // maybe nocache because of nocache variables
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache; $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
$_output = "<?php \$_smarty_tpl->smarty->getRuntime('Capture')->open(\$_smarty_tpl, $buffer, $assign, $append);?>"; $_output = "<?php \$_smarty_tpl->getSmarty()->getRuntime('Capture')->open(\$_smarty_tpl, $buffer, $assign, $append);?>";
return $_output; return $_output;
} }
} }

View File

@@ -37,6 +37,6 @@ class CaptureClose extends Base {
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
} }
[$compiler->nocache] = array_pop($compiler->_cache['capture_stack']); [$compiler->nocache] = array_pop($compiler->_cache['capture_stack']);
return "<?php \$_smarty_tpl->smarty->getRuntime('Capture')->close(\$_smarty_tpl);?>"; return "<?php \$_smarty_tpl->getSmarty()->getRuntime('Capture')->close(\$_smarty_tpl);?>";
} }
} }

View File

@@ -58,7 +58,7 @@ class Child extends Base {
if (!isset($compiler->_cache['blockNesting'])) { if (!isset($compiler->_cache['blockNesting'])) {
$compiler->trigger_template_error( $compiler->trigger_template_error(
"{$tag} used outside {block} tags ", "{$tag} used outside {block} tags ",
$compiler->parser->lex->taglineno $compiler->getParser()->lex->taglineno
); );
} }
$compiler->has_code = true; $compiler->has_code = true;

View File

@@ -61,7 +61,7 @@ class EvalTag extends Base {
} }
// create template object // create template object
$_output = $_output =
"\$_template = new \\Smarty\\Template('eval:'.{$_attr[ 'var' ]}, \$_smarty_tpl->smarty, \$_smarty_tpl);"; "\$_template = new \\Smarty\\Template('eval:'.{$_attr[ 'var' ]}, \$_smarty_tpl->getSmarty(), \$_smarty_tpl);";
//was there an assign attribute? //was there an assign attribute?
if (isset($_assign)) { if (isset($_assign)) {
$_output .= "\$_smarty_tpl->assign($_assign,\$_template->fetch());"; $_output .= "\$_smarty_tpl->assign($_assign,\$_template->fetch());";

View File

@@ -56,10 +56,10 @@ class ExtendsTag extends Inheritance {
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) { if ($_attr['nocache'] === true) {
$compiler->trigger_template_error('nocache option not allowed', $compiler->parser->lex->line - 1); $compiler->trigger_template_error('nocache option not allowed', $compiler->getParser()->lex->line - 1);
} }
if (strpos($_attr['file'], '$_tmp') !== false) { if (strpos($_attr['file'], '$_tmp') !== false) {
$compiler->trigger_template_error('illegal value for file attribute', $compiler->parser->lex->line - 1); $compiler->trigger_template_error('illegal value for file attribute', $compiler->getParser()->lex->line - 1);
} }
// add code to initialize inheritance // add code to initialize inheritance
$this->registerInit($compiler, true); $this->registerInit($compiler, true);
@@ -101,14 +101,14 @@ class ExtendsTag extends Inheritance {
*/ */
private function compileEndChild(\Smarty\Compiler\Template $compiler, $template = null) { private function compileEndChild(\Smarty\Compiler\Template $compiler, $template = null) {
$inlineUids = ''; $inlineUids = '';
if (isset($template) && $compiler->smarty->merge_compiled_includes) { if (isset($template) && $compiler->getSmarty()->merge_compiled_includes) {
$code = $compiler->compileTag('include', [$template, ['scope' => 'parent']]); $code = $compiler->compileTag('include', [$template, ['scope' => 'parent']]);
if (preg_match('/([,][\s]*[\'][a-z0-9]+[\'][,][\s]*[\']content.*[\'])[)]/', $code, $match)) { if (preg_match('/([,][\s]*[\'][a-z0-9]+[\'][,][\s]*[\']content.*[\'])[)]/', $code, $match)) {
$inlineUids = $match[1]; $inlineUids = $match[1];
} }
} }
$compiler->parser->template_postfix[] = new \Smarty\ParseTree\Tag( $compiler->getParser()->template_postfix[] = new \Smarty\ParseTree\Tag(
$compiler->parser, $compiler->getParser(),
'<?php $_smarty_tpl->getInheritance()->endChild($_smarty_tpl' . '<?php $_smarty_tpl->getInheritance()->endChild($_smarty_tpl' .
(isset($template) ? (isset($template) ?
", {$template}{$inlineUids}" : ", {$template}{$inlineUids}" :
@@ -126,8 +126,8 @@ class ExtendsTag extends Inheritance {
* @throws \Smarty\Exception * @throws \Smarty\Exception
*/ */
private function compileInclude(\Smarty\Compiler\Template $compiler, $template) { private function compileInclude(\Smarty\Compiler\Template $compiler, $template) {
$compiler->parser->template_postfix[] = new \Smarty\ParseTree\Tag( $compiler->getParser()->template_postfix[] = new \Smarty\ParseTree\Tag(
$compiler->parser, $compiler->getParser(),
$compiler->compileTag( $compiler->compileTag(
'include', 'include',
[ [
@@ -147,7 +147,7 @@ class ExtendsTag extends Inheritance {
*/ */
public static function extendsSourceArrayCode(\Smarty\Template $template) { public static function extendsSourceArrayCode(\Smarty\Template $template) {
$resources = []; $resources = [];
foreach ($template->source->components as $source) { foreach ($template->getSource()->components as $source) {
$resources[] = $source->resource; $resources[] = $source->resource;
} }
return $template->getLeftDelimiter() . 'extends file=\'extends:' . join('|', $resources) . return $template->getLeftDelimiter() . 'extends file=\'extends:' . join('|', $resources) .

View File

@@ -154,7 +154,7 @@ abstract class ForeachSection extends Base {
* @param \Smarty\Compiler\Template $compiler * @param \Smarty\Compiler\Template $compiler
*/ */
private function matchTemplateSource(\Smarty\Compiler\Template $compiler) { private function matchTemplateSource(\Smarty\Compiler\Template $compiler) {
$this->matchProperty($compiler->parser->lex->data); $this->matchProperty($compiler->getParser()->lex->data);
} }
/** /**
@@ -167,14 +167,14 @@ abstract class ForeachSection extends Base {
private function matchParentTemplateSource(\Smarty\Compiler\Template $compiler) { private function matchParentTemplateSource(\Smarty\Compiler\Template $compiler) {
// search parent compiler template source // search parent compiler template source
$nextCompiler = $compiler; $nextCompiler = $compiler;
while ($nextCompiler !== $nextCompiler->parent_compiler) { while ($nextCompiler !== $nextCompiler->getParentCompiler()) {
$nextCompiler = $nextCompiler->parent_compiler; $nextCompiler = $nextCompiler->getParentCompiler();
if ($compiler !== $nextCompiler) { if ($compiler !== $nextCompiler) {
// get template source // get template source
$_content = $nextCompiler->template->source->getContent(); $_content = $nextCompiler->getTemplate()->getSource()->getContent();
if ($_content !== '') { if ($_content !== '') {
// run pre filter if required // run pre filter if required
$_content = $nextCompiler->smarty->runPreFilters($_content, $nextCompiler->template); $_content = $nextCompiler->getSmarty()->runPreFilters($_content, $nextCompiler->getTemplate());
$this->matchProperty($_content); $this->matchProperty($_content);
} }
} }

View File

@@ -191,7 +191,7 @@ class ForeachTag extends ForeachSection {
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache; $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
// generate output code // generate output code
$output = "<?php\n"; $output = "<?php\n";
$output .= "\$_from = \$_smarty_tpl->smarty->getRuntime('Foreach')->init(\$_smarty_tpl, $from, " . $output .= "\$_from = \$_smarty_tpl->getSmarty()->getRuntime('Foreach')->init(\$_smarty_tpl, $from, " .
var_export($item, true); var_export($item, true);
if ($name || $needTotal || $key) { if ($name || $needTotal || $key) {
$output .= ', ' . var_export($needTotal, true); $output .= ', ' . var_export($needTotal, true);
@@ -273,6 +273,6 @@ class ForeachTag extends ForeachSection {
* @return string compiled code * @return string compiled code
*/ */
public function compileRestore($levels) { public function compileRestore($levels) {
return "\$_smarty_tpl->smarty->getRuntime('Foreach')->restore(\$_smarty_tpl, {$levels});"; return "\$_smarty_tpl->getSmarty()->getRuntime('Foreach')->restore(\$_smarty_tpl, {$levels});";
} }
} }

View File

@@ -40,9 +40,10 @@ class FunctionClose extends Base {
$saved_data = $this->closeTag($compiler, ['function']); $saved_data = $this->closeTag($compiler, ['function']);
$_attr = $saved_data[0]; $_attr = $saved_data[0];
$_name = trim($_attr['name'], '\'"'); $_name = trim($_attr['name'], '\'"');
$compiler->parent_compiler->tpl_function[$_name]['compiled_filepath'] = $parentCompiler = $compiler->getParentCompiler();
$compiler->parent_compiler->template->getCompiled()->filepath; $parentCompiler->tpl_function[$_name]['compiled_filepath'] =
$compiler->parent_compiler->tpl_function[$_name]['uid'] = $compiler->template->source->uid; $parentCompiler->getTemplate()->getCompiled()->filepath;
$parentCompiler->tpl_function[$_name]['uid'] = $compiler->getTemplate()->getSource()->uid;
$_parameter = $_attr; $_parameter = $_attr;
unset($_parameter['name']); unset($_parameter['name']);
// default parameter // default parameter
@@ -53,13 +54,13 @@ class FunctionClose extends Base {
} else { } else {
$_paramsCode = ''; $_paramsCode = '';
} }
$_functionCode = $compiler->parser->current_buffer; $_functionCode = $compiler->getParser()->current_buffer;
// setup buffer for template function code // setup buffer for template function code
$compiler->parser->current_buffer = new \Smarty\ParseTree\Template(); $compiler->getParser()->current_buffer = new \Smarty\ParseTree\Template();
$_funcName = "smarty_template_function_{$_name}_{$compiler->template->getCompiled()->nocache_hash}"; $_funcName = "smarty_template_function_{$_name}_{$compiler->getTemplate()->getCompiled()->nocache_hash}";
$_funcNameCaching = $_funcName . 'Smarty\Compile\Tag\Nocache'; $_funcNameCaching = $_funcName . 'Smarty\Compile\Tag\Nocache';
if ($compiler->template->getCompiled()->getNocacheCode()) { if ($compiler->getTemplate()->getCompiled()->getNocacheCode()) {
$compiler->parent_compiler->tpl_function[$_name]['call_name_caching'] = $_funcNameCaching; $parentCompiler->tpl_function[$_name]['call_name_caching'] = $_funcNameCaching;
$output = "<?php\n"; $output = "<?php\n";
$output .= $compiler->cStyleComment(" {$_funcNameCaching} ") . "\n"; $output .= $compiler->cStyleComment(" {$_funcNameCaching} ") . "\n";
$output .= "if (!function_exists('{$_funcNameCaching}')) {\n"; $output .= "if (!function_exists('{$_funcNameCaching}')) {\n";
@@ -69,41 +70,41 @@ class FunctionClose extends Base {
$output .= $_paramsCode; $output .= $_paramsCode;
$output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->assign(\$key, \$value);\n}\n"; $output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->assign(\$key, \$value);\n}\n";
$output .= "\$params = var_export(\$params, true);\n"; $output .= "\$params = var_export(\$params, true);\n";
$output .= "echo \"/*%%SmartyNocache:{$compiler->template->getCompiled()->nocache_hash}%%*/<?php "; $output .= "echo \"/*%%SmartyNocache:{$compiler->getTemplate()->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 .= "\\\$_smarty_tpl->getSmarty()->getRuntime('TplFunction')->saveTemplateVariables(\\\$_smarty_tpl, '{$_name}');\nforeach (\$params as \\\$key => \\\$value) {\n\\\$_smarty_tpl->assign(\\\$key, \\\$value);\n}\n?>";
$output .= "/*/%%SmartyNocache:{$compiler->template->getCompiled()->nocache_hash}%%*/\";?>"; $output .= "/*/%%SmartyNocache:{$compiler->getTemplate()->getCompiled()->nocache_hash}%%*/\";?>";
$compiler->parser->current_buffer->append_subtree( $compiler->getParser()->current_buffer->append_subtree(
$compiler->parser, $compiler->getParser(),
new \Smarty\ParseTree\Tag( new \Smarty\ParseTree\Tag(
$compiler->parser, $compiler->getParser(),
$output $output
) )
); );
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode); $compiler->getParser()->current_buffer->append_subtree($compiler->getParser(), $_functionCode);
$output = "<?php echo \"/*%%SmartyNocache:{$compiler->template->getCompiled()->nocache_hash}%%*/<?php "; $output = "<?php echo \"/*%%SmartyNocache:{$compiler->getTemplate()->getCompiled()->nocache_hash}%%*/<?php ";
$output .= "\\\$_smarty_tpl->smarty->getRuntime('TplFunction')->restoreTemplateVariables(\\\$_smarty_tpl, '{$_name}');?>\n"; $output .= "\\\$_smarty_tpl->getSmarty()->getRuntime('TplFunction')->restoreTemplateVariables(\\\$_smarty_tpl, '{$_name}');?>\n";
$output .= "/*/%%SmartyNocache:{$compiler->template->getCompiled()->nocache_hash}%%*/\";\n?>"; $output .= "/*/%%SmartyNocache:{$compiler->getTemplate()->getCompiled()->nocache_hash}%%*/\";\n?>";
$output .= "<?php echo str_replace('{$compiler->template->getCompiled()->nocache_hash}', \$_smarty_tpl->getCompiled()->nocache_hash ?? '', ob_get_clean());\n"; $output .= "<?php echo str_replace('{$compiler->getTemplate()->getCompiled()->nocache_hash}', \$_smarty_tpl->getCompiled()->nocache_hash ?? '', ob_get_clean());\n";
$output .= "}\n}\n"; $output .= "}\n}\n";
$output .= $compiler->cStyleComment("/ {$_funcName}_nocache ") . "\n\n"; $output .= $compiler->cStyleComment("/ {$_funcName}_nocache ") . "\n\n";
$output .= "?>\n"; $output .= "?>\n";
$compiler->parser->current_buffer->append_subtree( $compiler->getParser()->current_buffer->append_subtree(
$compiler->parser, $compiler->getParser(),
new \Smarty\ParseTree\Tag( new \Smarty\ParseTree\Tag(
$compiler->parser, $compiler->getParser(),
$output $output
) )
); );
$_functionCode = new \Smarty\ParseTree\Tag( $_functionCode = new \Smarty\ParseTree\Tag(
$compiler->parser, $compiler->getParser(),
preg_replace_callback( preg_replace_callback(
"/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->getCompiled()->nocache_hash}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->getCompiled()->nocache_hash}%%\*\/';(\?>\n)?)/", "/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->getTemplate()->getCompiled()->nocache_hash}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->getTemplate()->getCompiled()->nocache_hash}%%\*\/';(\?>\n)?)/",
[$this, 'removeNocache'], [$this, 'removeNocache'],
$_functionCode->to_smarty_php($compiler->parser) $_functionCode->to_smarty_php($compiler->getParser())
) )
); );
} }
$compiler->parent_compiler->tpl_function[$_name]['call_name'] = $_funcName; $parentCompiler->tpl_function[$_name]['call_name'] = $_funcName;
$output = "<?php\n"; $output = "<?php\n";
$output .= $compiler->cStyleComment(" {$_funcName} ") . "\n"; $output .= $compiler->cStyleComment(" {$_funcName} ") . "\n";
$output .= "if (!function_exists('{$_funcName}')) {\n"; $output .= "if (!function_exists('{$_funcName}')) {\n";
@@ -111,30 +112,30 @@ class FunctionClose extends Base {
$output .= $_paramsCode; $output .= $_paramsCode;
$output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->assign(\$key, \$value);\n}\n"; $output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->assign(\$key, \$value);\n}\n";
$output .= "?>\n"; $output .= "?>\n";
$compiler->parser->current_buffer->append_subtree( $compiler->getParser()->current_buffer->append_subtree(
$compiler->parser, $compiler->getParser(),
new \Smarty\ParseTree\Tag( new \Smarty\ParseTree\Tag(
$compiler->parser, $compiler->getParser(),
$output $output
) )
); );
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode); $compiler->getParser()->current_buffer->append_subtree($compiler->getParser(), $_functionCode);
$output = "<?php\n}}\n"; $output = "<?php\n}}\n";
$output .= $compiler->cStyleComment("/ {$_funcName} ") . "\n\n"; $output .= $compiler->cStyleComment("/ {$_funcName} ") . "\n\n";
$output .= "?>\n"; $output .= "?>\n";
$compiler->parser->current_buffer->append_subtree( $compiler->getParser()->current_buffer->append_subtree(
$compiler->parser, $compiler->getParser(),
new \Smarty\ParseTree\Tag( new \Smarty\ParseTree\Tag(
$compiler->parser, $compiler->getParser(),
$output $output
) )
); );
$compiler->parent_compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser); $parentCompiler->blockOrFunctionCode .= $compiler->getParser()->current_buffer->to_smarty_php($compiler->getParser());
// restore old buffer // restore old buffer
$compiler->parser->current_buffer = $saved_data[1]; $compiler->getParser()->current_buffer = $saved_data[1];
// restore old status // restore old status
$compiler->template->getCompiled()->setNocacheCode($saved_data[2]); $compiler->getTemplate()->getCompiled()->setNocacheCode($saved_data[2]);
$compiler->template->caching = $saved_data[3]; $compiler->getTemplate()->caching = $saved_data[3];
return true; return true;
} }
@@ -146,9 +147,11 @@ class FunctionClose extends Base {
* @return string * @return string
*/ */
public function removeNocache($match) { public function removeNocache($match) {
// @TODO why is this here, and will the $this->compiler property survive long enough for the callback?
$hash = $this->compiler->getTemplate()->getCompiled()->nocache_hash;
$code = $code =
preg_replace( preg_replace(
"/((<\?php )?echo '\/\*%%SmartyNocache:{$this->compiler->template->getCompiled()->nocache_hash}%%\*\/)|(\/\*\/%%SmartyNocache:{$this->compiler->template->getCompiled()->nocache_hash}%%\*\/';(\?>\n)?)/", "/((<\?php )?echo '\/\*%%SmartyNocache:{$hash}%%\*\/)|(\/\*\/%%SmartyNocache:{$hash}%%\*\/';(\?>\n)?)/",
'', '',
$match[0] $match[0]
); );

View File

@@ -58,15 +58,15 @@ class FunctionTag extends Base {
$compiler->trigger_template_error("Function name contains invalid characters: {$_name}", null, true); $compiler->trigger_template_error("Function name contains invalid characters: {$_name}", null, true);
} }
$compiler->parent_compiler->tpl_function[$_name] = []; $compiler->getParentCompiler()->tpl_function[$_name] = [];
$save = [ $save = [
$_attr, $compiler->parser->current_buffer, $compiler->template->getCompiled()->getNocacheCode(), $_attr, $compiler->getParser()->current_buffer, $compiler->getTemplate()->getCompiled()->getNocacheCode(),
$compiler->template->caching, $compiler->getTemplate()->caching,
]; ];
$this->openTag($compiler, 'function', $save); $this->openTag($compiler, 'function', $save);
// Init temporary context // Init temporary context
$compiler->parser->current_buffer = new \Smarty\ParseTree\Template(); $compiler->getParser()->current_buffer = new \Smarty\ParseTree\Template();
$compiler->template->getCompiled()->setNocacheCode(false); $compiler->getTemplate()->getCompiled()->setNocacheCode(false);
return true; return true;
} }
} }

View File

@@ -75,20 +75,20 @@ class IncludeTag extends Base {
$variable_template = false; $variable_template = false;
// parse resource_name // parse resource_name
if (preg_match('/^([\'"])(([A-Za-z0-9_\-]{2,})[:])?(([^$()]+)|(.+))\1$/', $source_resource, $match)) { if (preg_match('/^([\'"])(([A-Za-z0-9_\-]{2,})[:])?(([^$()]+)|(.+))\1$/', $source_resource, $match)) {
$type = !empty($match[3]) ? $match[3] : $compiler->template->smarty->default_resource_type; $type = !empty($match[3]) ? $match[3] : $compiler->getTemplate()->getSmarty()->default_resource_type;
$name = !empty($match[5]) ? $match[5] : $match[6]; $name = !empty($match[5]) ? $match[5] : $match[6];
$handler = \Smarty\Resource\BasePlugin::load($compiler->smarty, $type); $handler = \Smarty\Resource\BasePlugin::load($compiler->getSmarty(), $type);
if ($handler->recompiled) { if ($handler->recompiled) {
$variable_template = true; $variable_template = true;
} }
if (!$variable_template) { if (!$variable_template) {
if ($type !== 'string') { if ($type !== 'string') {
$fullResourceName = "{$type}:{$name}"; $fullResourceName = "{$type}:{$name}";
$compiled = $compiler->parent_compiler->template->getCompiled(); $compiled = $compiler->getParentCompiler()->getTemplate()->getCompiled();
if (isset($compiled->includes[$fullResourceName])) { if (isset($compiled->includes[$fullResourceName])) {
$compiled->includes[$fullResourceName]++; $compiled->includes[$fullResourceName]++;
} else { } else {
if ("{$compiler->template->source->type}:{$compiler->template->source->name}" == if ("{$compiler->getTemplate()->getSource()->type}:{$compiler->getTemplate()->getSource()->name}" ==
$fullResourceName $fullResourceName
) { ) {
// recursive call of current template // recursive call of current template
@@ -113,12 +113,12 @@ class IncludeTag extends Base {
$_caching = Smarty::CACHING_OFF; $_caching = Smarty::CACHING_OFF;
$call_nocache = $compiler->tag_nocache || $compiler->nocache; $call_nocache = $compiler->tag_nocache || $compiler->nocache;
// caching was on and {include} is not in nocache mode // caching was on and {include} is not in nocache mode
if ($compiler->template->caching && !$compiler->nocache && !$compiler->tag_nocache) { if ($compiler->getTemplate()->caching && !$compiler->nocache && !$compiler->tag_nocache) {
$_caching = \Smarty\Template::CACHING_NOCACHE_CODE; $_caching = \Smarty\Template::CACHING_NOCACHE_CODE;
} }
// flag if included template code should be merged into caller // flag if included template code should be merged into caller
$merge_compiled_includes = ($compiler->smarty->merge_compiled_includes || $_attr['inline'] === true) && $merge_compiled_includes = ($compiler->getSmarty()->merge_compiled_includes || $_attr['inline'] === true) &&
!$compiler->template->source->handler->recompiled; !$compiler->getTemplate()->getSource()->handler->recompiled;
if ($merge_compiled_includes) { if ($merge_compiled_includes) {
// variable template name ? // variable template name ?
if ($variable_template) { if ($variable_template) {
@@ -153,7 +153,7 @@ class IncludeTag extends Base {
} }
// if subtemplate will be called in nocache mode do not merge // if subtemplate will be called in nocache mode do not merge
if ($compiler->template->caching && $call_nocache) { if ($compiler->getTemplate()->caching && $call_nocache) {
$merge_compiled_includes = false; $merge_compiled_includes = false;
} }
// assign attribute // assign attribute
@@ -171,27 +171,27 @@ class IncludeTag extends Base {
} }
$has_compiled_template = false; $has_compiled_template = false;
if ($merge_compiled_includes) { if ($merge_compiled_includes) {
$c_id = $compiler->template->compile_id; $c_id = $compiler->getTemplate()->compile_id;
// we must observe different compile_id and caching // we must observe different compile_id and caching
$t_hash = sha1($c_id . ($_caching ? '--caching' : '--nocaching')); $t_hash = sha1($c_id . ($_caching ? '--caching' : '--nocaching'));
$compiler->smarty->setAllowAmbiguousResources(true); $compiler->getSmarty()->setAllowAmbiguousResources(true);
$tpl = $compiler->smarty->createTemplate( $tpl = $compiler->getSmarty()->createTemplate(
trim($fullResourceName, '"\''), trim($fullResourceName, '"\''),
$compiler->template->cache_id, $compiler->getTemplate()->cache_id,
$c_id, $c_id,
$compiler->template, $compiler->getTemplate(),
$_caching $_caching
); );
$uid = $tpl->source->type . $tpl->source->uid; $uid = $tpl->getSource()->type . $tpl->getSource()->uid;
if (!isset($compiler->parent_compiler->mergedSubTemplatesData[$uid][$t_hash])) { if (!isset($compiler->getParentCompiler()->mergedSubTemplatesData[$uid][$t_hash])) {
$has_compiled_template = $this->compileInlineTemplate($compiler, $tpl, $t_hash); $has_compiled_template = $this->compileInlineTemplate($compiler, $tpl, $t_hash);
} else { } else {
$has_compiled_template = true; $has_compiled_template = true;
} }
$compiler->smarty->setAllowAmbiguousResources(false); $compiler->getSmarty()->setAllowAmbiguousResources(false);
} }
// delete {include} standard attributes // delete {include} standard attributes
@@ -208,7 +208,7 @@ class IncludeTag extends Base {
} }
if ($has_compiled_template && !$call_nocache) { if ($has_compiled_template && !$call_nocache) {
$_output = "<?php\n"; $_output = "<?php\n";
if (!empty($_attr) && $_caching === \Smarty\Template::CACHING_NOCACHE_CODE && $compiler->template->caching) { if (!empty($_attr) && $_caching === \Smarty\Template::CACHING_NOCACHE_CODE && $compiler->getTemplate()->caching) {
$_vars_nc = "foreach ($_vars as \$ik => \$iv) {\n"; $_vars_nc = "foreach ($_vars as \$ik => \$iv) {\n";
$_vars_nc .= "\$_smarty_tpl->assign(\$ik, \$iv);\n"; $_vars_nc .= "\$_smarty_tpl->assign(\$ik, \$iv);\n";
$_vars_nc .= "}\n"; $_vars_nc .= "}\n";
@@ -217,7 +217,7 @@ class IncludeTag extends Base {
if (isset($_assign)) { if (isset($_assign)) {
$_output .= "ob_start();\n"; $_output .= "ob_start();\n";
} }
$_output .= "\$_smarty_tpl->_subTemplateRender({$fullResourceName}, {$_cache_id}, \$_smarty_tpl->compile_id, {$_caching}, {$_cache_lifetime}, {$_vars}, '{$compiler->parent_compiler->mergedSubTemplatesData[$uid][$t_hash]['uid']}', '{$compiler->parent_compiler->mergedSubTemplatesData[$uid][$t_hash]['func']}');\n"; $_output .= "\$_smarty_tpl->_subTemplateRender({$fullResourceName}, {$_cache_id}, \$_smarty_tpl->compile_id, {$_caching}, {$_cache_lifetime}, {$_vars}, '{$compiler->getParentCompiler()->mergedSubTemplatesData[$uid][$t_hash]['uid']}', '{$compiler->getParentCompiler()->mergedSubTemplatesData[$uid][$t_hash]['func']}');\n";
if (isset($_assign)) { if (isset($_assign)) {
$_output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean(), false, {$_scope});\n"; $_output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean(), false, {$_scope});\n";
} }
@@ -256,32 +256,33 @@ class IncludeTag extends Base {
\Smarty\Template $tpl, \Smarty\Template $tpl,
$t_hash $t_hash
) { ) {
$uid = $tpl->source->type . $tpl->source->uid; $tplSource = $tpl->getSource();
if ($tpl->source->exists) { $uid = $tplSource->type . $tplSource->uid;
$compiler->parent_compiler->mergedSubTemplatesData[$uid][$t_hash]['uid'] = $tpl->source->uid; if ($tplSource->exists) {
$tpl->getCompiled(true)->nocache_hash = $compiler->parent_compiler->template->getCompiled()->nocache_hash; $compiler->getParentCompiler()->mergedSubTemplatesData[$uid][$t_hash]['uid'] = $tplSource->uid;
$tpl->getCompiled(true)->nocache_hash = $compiler->getParentCompiler()->getTemplate()->getCompiled()->nocache_hash;
// save unique function name // save unique function name
$compiler->parent_compiler->mergedSubTemplatesData[$uid][$t_hash]['func'] = $compiler->getParentCompiler()->mergedSubTemplatesData[$uid][$t_hash]['func'] =
$tpl->getCompiled()->unifunc = 'content_' . str_replace(['.', ','], '_', uniqid('', true)); $tpl->getCompiled()->unifunc = 'content_' . str_replace(['.', ','], '_', uniqid('', true));
// make sure whole chain gets compiled // make sure whole chain gets compiled
$tpl->mustCompile = true; $tpl->mustCompile = true;
$compiler->parent_compiler->mergedSubTemplatesData[$uid][$t_hash]['nocache_hash'] = $compiler->getParentCompiler()->mergedSubTemplatesData[$uid][$t_hash]['nocache_hash'] =
$tpl->getCompiled()->nocache_hash; $tpl->getCompiled()->nocache_hash;
if ($tpl->source->type === 'file') { if ($tplSource->type === 'file') {
$sourceInfo = $tpl->source->filepath; $sourceInfo = $tplSource->filepath;
} else { } else {
$basename = $tpl->source->handler->getBasename($tpl->source); $basename = $tplSource->handler->getBasename($tplSource);
$sourceInfo = $tpl->source->type . ':' . $sourceInfo = $tplSource->type . ':' .
($basename ? $basename : $tpl->source->name); ($basename ? $basename : $tplSource->name);
} }
// get compiled code // get compiled code
$compiled_code = "<?php\n\n"; $compiled_code = "<?php\n\n";
$compiled_code .= $compiler->cStyleComment(" Start inline template \"{$sourceInfo}\" =============================") . "\n"; $compiled_code .= $compiler->cStyleComment(" Start inline template \"{$sourceInfo}\" =============================") . "\n";
$compiled_code .= "function {$tpl->getCompiled()->unifunc} (\\Smarty\\Template \$_smarty_tpl) {\n"; $compiled_code .= "function {$tpl->getCompiled()->unifunc} (\\Smarty\\Template \$_smarty_tpl) {\n";
$compiled_code .= "?>\n" . $tpl->getCompiler()->compileTemplateSource($tpl, null, $compiler->parent_compiler); $compiled_code .= "?>\n" . $tpl->getCompiler()->compileTemplateSource($tpl, null, $compiler->getParentCompiler());
$compiled_code .= "<?php\n"; $compiled_code .= "<?php\n";
$compiled_code .= "}\n?>\n"; $compiled_code .= "}\n?>\n";
$compiled_code .= $tpl->smarty->runPostFilters($tpl->getCompiler()->blockOrFunctionCode, $tpl); $compiled_code .= $tpl->getSmarty()->runPostFilters($tpl->getCompiler()->blockOrFunctionCode, $tpl);
$compiled_code .= "<?php\n\n"; $compiled_code .= "<?php\n\n";
$compiled_code .= $compiler->cStyleComment(" End inline template \"{$sourceInfo}\" =============================") . "\n"; $compiled_code .= $compiler->cStyleComment(" End inline template \"{$sourceInfo}\" =============================") . "\n";
$compiled_code .= '?>'; $compiled_code .= '?>';
@@ -293,12 +294,12 @@ class IncludeTag extends Base {
$compiled_code = $compiled_code =
str_replace( str_replace(
"{$tpl->getCompiled()->nocache_hash}", "{$tpl->getCompiled()->nocache_hash}",
$compiler->template->getCompiled()->nocache_hash, $compiler->getTemplate()->getCompiled()->nocache_hash,
$compiled_code $compiled_code
); );
$compiler->template->getCompiled()->setNocacheCode(true); $compiler->getTemplate()->getCompiled()->setNocacheCode(true);
} }
$compiler->parent_compiler->mergedSubTemplatesCode[$tpl->getCompiled()->unifunc] = $compiled_code; $compiler->getParentCompiler()->mergedSubTemplatesCode[$tpl->getCompiled()->unifunc] = $compiled_code;
return true; return true;
} else { } else {
return false; return false;

View File

@@ -35,6 +35,6 @@ class Ldelim extends Base {
if ($_attr['nocache'] === true) { if ($_attr['nocache'] === true) {
$compiler->trigger_template_error('nocache option not allowed', null, true); $compiler->trigger_template_error('nocache option not allowed', null, true);
} }
return $compiler->template->getLeftDelimiter(); return $compiler->getTemplate()->getLeftDelimiter();
} }
} }

View File

@@ -30,6 +30,6 @@ class Rdelim extends Ldelim {
*/ */
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) { public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
parent::compile($args, $compiler); parent::compile($args, $compiler);
return $compiler->template->getRightDelimiter(); return $compiler->getTemplate()->getRightDelimiter();
} }
} }

View File

@@ -11,7 +11,7 @@ abstract class BaseCompiler {
* *
* @var Smarty * @var Smarty
*/ */
public $smarty = null; protected $smarty = null;
/** /**
* @return Smarty|null * @return Smarty|null

View File

@@ -59,7 +59,7 @@ class CodeFrame
"<?php\n/* Smarty version %s, created on %s\n from '%s' */\n\n", "<?php\n/* Smarty version %s, created on %s\n from '%s' */\n\n",
$properties[ 'version' ], $properties[ 'version' ],
date("Y-m-d H:i:s"), date("Y-m-d H:i:s"),
str_replace('*/', '* /', $this->_template->source->filepath) str_replace('*/', '* /', $this->_template->getSource()->filepath)
); );
$output .= "/* @var \\Smarty\\Template \$_smarty_tpl */\n"; $output .= "/* @var \\Smarty\\Template \$_smarty_tpl */\n";
$dec = "\$_smarty_tpl->isFresh(\$_smarty_tpl, " . var_export($properties, true) . ',' . $dec = "\$_smarty_tpl->isFresh(\$_smarty_tpl, " . var_export($properties, true) . ',' .
@@ -67,13 +67,13 @@ class CodeFrame
$output .= "if ({$dec}) {\n"; $output .= "if ({$dec}) {\n";
$output .= "function {$properties['unifunc']} (\\Smarty\\Template \$_smarty_tpl) {\n"; $output .= "function {$properties['unifunc']} (\\Smarty\\Template \$_smarty_tpl) {\n";
if (!$cache && !empty($compiler->tpl_function)) { if (!$cache && !empty($compiler->tpl_function)) {
$output .= '$_smarty_tpl->smarty->getRuntime(\'TplFunction\')->registerTplFunctions($_smarty_tpl, '; $output .= '$_smarty_tpl->getSmarty()->getRuntime(\'TplFunction\')->registerTplFunctions($_smarty_tpl, ';
$output .= var_export($compiler->tpl_function, true); $output .= var_export($compiler->tpl_function, true);
$output .= ");\n"; $output .= ");\n";
} }
if ($cache && $this->_template->smarty->hasRuntime('TplFunction')) { if ($cache && $this->_template->getSmarty()->hasRuntime('TplFunction')) {
$output .= "\$_smarty_tpl->smarty->getRuntime('TplFunction')->registerTplFunctions(\$_smarty_tpl, " . $output .= "\$_smarty_tpl->getSmarty()->getRuntime('TplFunction')->registerTplFunctions(\$_smarty_tpl, " .
var_export($this->_template->smarty->getRuntime('TplFunction')->getTplFunction($this->_template), true) . ");\n"; var_export($this->_template->getSmarty()->getRuntime('TplFunction')->getTplFunction($this->_template), true) . ");\n";
} }
$output .= "?>"; $output .= "?>";
$output .= $content; $output .= $content;

View File

@@ -82,11 +82,11 @@ class Configfile extends BaseCompiler {
*/ */
public function compileTemplate(Template $template) { public function compileTemplate(Template $template) {
$this->template = $template; $this->template = $template;
$this->template->getCompiled()->file_dependency[$this->template->source->uid] = $this->template->getCompiled()->file_dependency[$this->template->getSource()->uid] =
[ [
$this->template->source->filepath, $this->template->getSource()->filepath,
$this->template->source->getTimeStamp(), $this->template->getSource()->getTimeStamp(),
$this->template->source->type, $this->template->getSource()->type,
]; ];
if ($this->smarty->debugging) { if ($this->smarty->debugging) {
$this->smarty->getDebug()->start_compile($this->template); $this->smarty->getDebug()->start_compile($this->template);
@@ -100,7 +100,7 @@ class Configfile extends BaseCompiler {
"\r", "\r",
], ],
"\n", "\n",
$template->source->getContent() $template->getSource()->getContent()
) . "\n", ) . "\n",
$this $this
); );
@@ -138,7 +138,7 @@ class Configfile extends BaseCompiler {
"<?php /* Smarty version %s, created on %s\n compiled from '%s' */ ?>\n", "<?php /* Smarty version %s, created on %s\n compiled from '%s' */ ?>\n",
\Smarty\Smarty::SMARTY_VERSION, \Smarty\Smarty::SMARTY_VERSION,
date("Y-m-d H:i:s"), date("Y-m-d H:i:s"),
str_replace('*/', '* /', $this->template->source->filepath) str_replace('*/', '* /', $this->template->getSource()->filepath)
); );
$code = '<?php $_smarty_tpl->parent->assignConfigVars(' . $code = '<?php $_smarty_tpl->parent->assignConfigVars(' .
var_export($this->config_data, true) . ', $_smarty_tpl->getValue("sections")); ?>'; var_export($this->config_data, true) . ', $_smarty_tpl->getValue("sections")); ?>';
@@ -163,7 +163,7 @@ class Configfile extends BaseCompiler {
} }
$match = preg_split("/\n/", $this->lex->data); $match = preg_split("/\n/", $this->lex->data);
$error_text = $error_text =
"Syntax error in config file '{$this->template->source->filepath}' on line {$line} '{$match[$line - 1]}' "; "Syntax error in config file '{$this->template->getSource()->filepath}' on line {$line} '{$match[$line - 1]}' ";
if (isset($args)) { if (isset($args)) {
// individual error message // individual error message
$error_text .= $args; $error_text .= $args;

View File

@@ -48,7 +48,7 @@ class Template extends BaseCompiler {
* *
* @var \Smarty\Parser\TemplateParser * @var \Smarty\Parser\TemplateParser
*/ */
public $parser = null; private $parser = null;
/** /**
* hash for nocache sections * hash for nocache sections
@@ -90,7 +90,7 @@ class Template extends BaseCompiler {
* *
* @var \Smarty\Template * @var \Smarty\Template
*/ */
public $template = null; private $template = null;
/** /**
* merged included sub template data * merged included sub template data
@@ -153,7 +153,7 @@ class Template extends BaseCompiler {
* *
* @var \Smarty\Compiler\Template * @var \Smarty\Compiler\Template
*/ */
public $parent_compiler = null; private $parent_compiler = null;
/** /**
* Flag true when compiling nocache section * Flag true when compiling nocache section
@@ -401,24 +401,24 @@ class Template extends BaseCompiler {
$this->has_variable_string = false; $this->has_variable_string = false;
$this->prefix_code = []; $this->prefix_code = [];
// add file dependency // add file dependency
if ($this->smarty->merge_compiled_includes || $this->template->source->handler->checkTimestamps()) { if ($this->smarty->merge_compiled_includes || $this->template->getSource()->handler->checkTimestamps()) {
$this->parent_compiler->template->getCompiled()->file_dependency[$this->template->source->uid] = $this->parent_compiler->getTemplate()->getCompiled()->file_dependency[$this->template->getSource()->uid] =
[ [
$this->template->source->filepath, $this->template->getSource()->filepath,
$this->template->source->getTimeStamp(), $this->template->getSource()->getTimeStamp(),
$this->template->source->type, $this->template->getSource()->type,
]; ];
} }
$this->smarty->_current_file = $this->template->source->filepath; $this->smarty->_current_file = $this->template->getSource()->filepath;
// get template source // get template source
if (!empty($this->template->source->components)) { if (!empty($this->template->getSource()->components)) {
// we have array of inheritance templates by extends: resource // we have array of inheritance templates by extends: resource
// generate corresponding source code sequence // generate corresponding source code sequence
$_content = $_content =
ExtendsTag::extendsSourceArrayCode($this->template); ExtendsTag::extendsSourceArrayCode($this->template);
} else { } else {
// get template source // get template source
$_content = $this->template->source->getContent(); $_content = $this->template->getSource()->getContent();
} }
$_compiled_code = $this->smarty->runPostFilters( $_compiled_code = $this->smarty->runPostFilters(
$this->doCompile( $this->doCompile(
@@ -713,7 +713,7 @@ class Template extends BaseCompiler {
// If the template is not evaluated, and we have a nocache section and/or a nocache tag // If the template is not evaluated, and we have a nocache section and/or a nocache tag
// generate replacement code // generate replacement code
if (!empty($content) if (!empty($content)
&& !($this->template->source->handler->recompiled) && !($this->template->getSource()->handler->recompiled)
&& $this->caching && $this->caching
&& !$this->suppressNocacheProcessing && !$this->suppressNocacheProcessing
&& ($this->nocache || $this->tag_nocache) && ($this->nocache || $this->tag_nocache)
@@ -796,14 +796,14 @@ class Template extends BaseCompiler {
$line = (int)$line; $line = (int)$line;
} }
if (in_array( if (in_array(
$this->template->source->type, $this->template->getSource()->type,
[ [
'eval', 'eval',
'string', 'string',
] ]
) )
) { ) {
$templateName = $this->template->source->type . ':' . trim( $templateName = $this->template->getSource()->type . ':' . trim(
preg_replace( preg_replace(
'![\t\r\n]+!', '![\t\r\n]+!',
' ', ' ',
@@ -813,7 +813,7 @@ class Template extends BaseCompiler {
) )
); );
} else { } else {
$templateName = $this->template->source->type . ':' . $this->template->source->filepath; $templateName = $this->template->getSource()->type . ':' . $this->template->getSource()->filepath;
} }
// $line += $this->trace_line_offset; // $line += $this->trace_line_offset;
$match = preg_split("/\n/", $lex->data); $match = preg_split("/\n/", $lex->data);
@@ -850,12 +850,12 @@ class Template extends BaseCompiler {
$e = new CompilerException( $e = new CompilerException(
$error_text, $error_text,
0, 0,
$this->template->source->filepath, $this->template->getSource()->filepath,
$line $line
); );
$e->source = trim(preg_replace('![\t\r\n]+!', ' ', $match[$line - 1])); $e->source = trim(preg_replace('![\t\r\n]+!', ' ', $match[$line - 1]));
$e->desc = $args; $e->desc = $args;
$e->template = $this->template->source->filepath; $e->template = $this->template->getSource()->filepath;
throw $e; throw $e;
} }
@@ -1313,8 +1313,8 @@ class Template extends BaseCompiler {
return return
isset($this->parent_compiler->tpl_function[$tag]) isset($this->parent_compiler->tpl_function[$tag])
|| ( || (
$this->template->smarty->hasRuntime('TplFunction') $this->template->getSmarty()->hasRuntime('TplFunction')
&& ($this->template->smarty->getRuntime('TplFunction')->getTplFunction($this->template, $tag) !== false) && ($this->template->getSmarty()->getRuntime('TplFunction')->getTplFunction($this->template, $tag) !== false)
); );
} }
@@ -1363,4 +1363,46 @@ class Template extends BaseCompiler {
return $this->functionCallCompiler->compile($args, $this, $parameter, $base_tag, $base_tag); return $this->functionCallCompiler->compile($args, $this, $parameter, $base_tag, $base_tag);
} }
/**
* @return TemplateParser|null
*/
public function getParser(): ?TemplateParser {
return $this->parser;
}
/**
* @param TemplateParser|null $parser
*/
public function setParser(?TemplateParser $parser): void {
$this->parser = $parser;
}
/**
* @return \Smarty\Template|null
*/
public function getTemplate(): ?\Smarty\Template {
return $this->template;
}
/**
* @param \Smarty\Template|null $template
*/
public function setTemplate(?\Smarty\Template $template): void {
$this->template = $template;
}
/**
* @return Template|null
*/
public function getParentCompiler(): ?Template {
return $this->parent_compiler;
}
/**
* @param Template|null $parent_compiler
*/
public function setParentCompiler(?Template $parent_compiler): void {
$this->parent_compiler = $parent_compiler;
}
} }

View File

@@ -24,7 +24,7 @@ class Data
* *
* @var Smarty * @var Smarty
*/ */
public $smarty = null; protected $smarty = null;
/** /**
* template variables * template variables
@@ -95,7 +95,7 @@ class Data
switch ($scope) { switch ($scope) {
case self::SCOPE_GLOBAL: case self::SCOPE_GLOBAL:
case self::SCOPE_SMARTY: case self::SCOPE_SMARTY:
$this->_getSmartyObj()->assign($tpl_var, $value); $this->getSmarty()->assign($tpl_var, $value);
break; break;
case self::SCOPE_TPL_ROOT: case self::SCOPE_TPL_ROOT:
$ptr = $this; $ptr = $this;
@@ -180,7 +180,7 @@ class Data
{ {
trigger_error(__METHOD__ . " is deprecated. Use \\Smarty\\Smarty::assign() to assign a variable " . trigger_error(__METHOD__ . " is deprecated. Use \\Smarty\\Smarty::assign() to assign a variable " .
" at the Smarty level.", E_USER_DEPRECATED); " at the Smarty level.", E_USER_DEPRECATED);
return $this->_getSmartyObj()->assign($varName, $value, $nocache); return $this->getSmarty()->assign($varName, $value, $nocache);
} }
/** /**
@@ -238,7 +238,7 @@ class Data
return $this->parent->getVariable($varName, $searchParents, $errorEnable); return $this->parent->getVariable($varName, $searchParents, $errorEnable);
} }
if ($errorEnable && $this->_getSmartyObj()->error_unassigned) { if ($errorEnable && $this->getSmarty()->error_unassigned) {
// force a notice // force a notice
$x = $$varName; $x = $$varName;
} }
@@ -277,7 +277,7 @@ class Data
// copy global config vars // copy global config vars
foreach ($new_config_vars['vars'] as $variable => $value) { foreach ($new_config_vars['vars'] as $variable => $value) {
if ($this->_getSmartyObj()->config_overwrite || !isset($this->config_vars[$variable])) { if ($this->getSmarty()->config_overwrite || !isset($this->config_vars[$variable])) {
$this->config_vars[$variable] = $value; $this->config_vars[$variable] = $value;
} else { } else {
$this->config_vars[$variable] = array_merge((array)$this->config_vars[$variable], (array)$value); $this->config_vars[$variable] = array_merge((array)$this->config_vars[$variable], (array)$value);
@@ -287,7 +287,7 @@ class Data
foreach ($sections as $tpl_section) { foreach ($sections as $tpl_section) {
if (isset($new_config_vars['sections'][$tpl_section])) { if (isset($new_config_vars['sections'][$tpl_section])) {
foreach ($new_config_vars['sections'][$tpl_section]['vars'] as $variable => $value) { foreach ($new_config_vars['sections'][$tpl_section]['vars'] as $variable => $value) {
if ($this->_getSmartyObj()->config_overwrite || !isset($this->config_vars[$variable])) { if ($this->getSmarty()->config_overwrite || !isset($this->config_vars[$variable])) {
$this->config_vars[$variable] = $value; $this->config_vars[$variable] = $value;
} else { } else {
$this->config_vars[$variable] = array_merge((array)$this->config_vars[$variable], (array)$value); $this->config_vars[$variable] = array_merge((array)$this->config_vars[$variable], (array)$value);
@@ -302,7 +302,7 @@ class Data
* *
* @return Smarty * @return Smarty
*/ */
public function _getSmartyObj() public function getSmarty()
{ {
return $this->smarty; return $this->smarty;
} }
@@ -380,7 +380,7 @@ class Data
$returnValue = $this->parent ? $this->parent->getConfigVariable($varName) : null; $returnValue = $this->parent ? $this->parent->getConfigVariable($varName) : null;
if ($returnValue === null && $this->_getSmartyObj()->error_unassigned) { if ($returnValue === null && $this->getSmarty()->error_unassigned) {
throw new Exception("Undefined variable $varName"); throw new Exception("Undefined variable $varName");
} }
@@ -430,7 +430,7 @@ class Data
*/ */
public function configLoad($config_file, $sections = null) public function configLoad($config_file, $sections = null)
{ {
$smarty = $this->_getSmartyObj(); $smarty = $this->getSmarty();
$template = new Template($config_file, $smarty, $this, null, null, null, true); $template = new Template($config_file, $smarty, $this, null, null, null, true);
$template->caching = Smarty::CACHING_OFF; $template->caching = Smarty::CACHING_OFF;
$template->assign('sections', (array) $sections ?? []); $template->assign('sections', (array) $sections ?? []);

View File

@@ -90,7 +90,7 @@ class Debug extends Data
$this->saveTemplateData($_is_stringy, $template, $key); $this->saveTemplateData($_is_stringy, $template, $key);
} }
} else { } else {
if (isset($this->ignore_uid[ $template->source->uid ])) { if (isset($this->ignore_uid[ $template->getSource()->uid ])) {
return; return;
} }
$key = $this->get_key($template); $key = $this->get_key($template);
@@ -108,7 +108,7 @@ class Debug extends Data
if (!empty($template->getCompiler()->trace_uid)) { if (!empty($template->getCompiler()->trace_uid)) {
$key = $template->getCompiler()->trace_uid; $key = $template->getCompiler()->trace_uid;
} else { } else {
if (isset($this->ignore_uid[ $template->source->uid ])) { if (isset($this->ignore_uid[ $template->getSource()->uid ])) {
return; return;
} }
$key = $this->get_key($template); $key = $this->get_key($template);
@@ -197,7 +197,7 @@ class Debug extends Data
$savedIndex = $this->index; $savedIndex = $this->index;
$this->index = 9999; $this->index = 9999;
} }
$smarty = $obj->_getSmartyObj(); $smarty = $obj->getSmarty();
// create fresh instance of smarty for displaying the debug console // create fresh instance of smarty for displaying the debug console
// to avoid problems if the application did overload the Smarty class // to avoid problems if the application did overload the Smarty class
$debObj = new \Smarty\Smarty(); $debObj = new \Smarty\Smarty();
@@ -225,7 +225,7 @@ class Debug extends Data
$debugging = $smarty->debugging; $debugging = $smarty->debugging;
$_template = $debObj->createTemplate($debObj->debug_tpl); $_template = $debObj->createTemplate($debObj->debug_tpl);
if ($obj instanceof \Smarty\Template) { if ($obj instanceof \Smarty\Template) {
$_template->assign('template_name', $obj->source->type . ':' . $obj->source->name); $_template->assign('template_name', $obj->getSource()->type . ':' . $obj->getSource()->name);
} elseif ($obj instanceof Smarty || $full) { } elseif ($obj instanceof Smarty || $full) {
$_template->assign('template_data', $this->template_data[$this->index]); $_template->assign('template_data', $this->template_data[$this->index]);
} else { } else {
@@ -307,10 +307,10 @@ class Debug extends Data
{ {
static $_is_stringy = array('string' => true, 'eval' => true); static $_is_stringy = array('string' => true, 'eval' => true);
// calculate Uid if not already done // calculate Uid if not already done
if ($template->source->uid === '') { if ($template->getSource()->uid === '') {
$template->source->filepath; $template->getSource()->filepath;
} }
$key = $template->source->uid; $key = $template->getSource()->uid;
if (isset($this->template_data[ $this->index ][ $key ])) { if (isset($this->template_data[ $this->index ][ $key ])) {
return $key; return $key;
} else { } else {
@@ -328,10 +328,10 @@ class Debug extends Data
public function ignore(\Smarty\Template $template) public function ignore(\Smarty\Template $template)
{ {
// calculate Uid if not already done // calculate Uid if not already done
if ($template->source->uid === '') { if ($template->getSource()->uid === '') {
$template->source->filepath; $template->getSource()->filepath;
} }
$this->ignore_uid[ $template->source->uid ] = true; $this->ignore_uid[ $template->getSource()->uid ] = true;
} }
/** /**
@@ -374,11 +374,11 @@ class Debug extends Data
* @return void * @return void
*/ */
private function saveTemplateData(array $_is_stringy, \Smarty\Template $template, string $key): void { private function saveTemplateData(array $_is_stringy, \Smarty\Template $template, string $key): void {
if (isset($_is_stringy[$template->source->type])) { if (isset($_is_stringy[$template->getSource()->type])) {
$this->template_data[$this->index][$key]['name'] = $this->template_data[$this->index][$key]['name'] =
'\'' . substr($template->source->name, 0, 25) . '...\''; '\'' . substr($template->getSource()->name, 0, 25) . '...\'';
} else { } else {
$this->template_data[$this->index][$key]['name'] = $template->source->filepath; $this->template_data[$this->index][$key]['name'] = $template->getSource()->filepath;
} }
$this->template_data[$this->index][$key]['compile_time'] = 0; $this->template_data[$this->index][$key]['compile_time'] = 0;
$this->template_data[$this->index][$key]['render_time'] = 0; $this->template_data[$this->index][$key]['render_time'] = 0;

View File

@@ -35,15 +35,15 @@ class Fetch extends Base {
if ($protocol !== false) { if ($protocol !== false) {
$protocol = strtolower(substr($params['file'], 0, $protocol)); $protocol = strtolower(substr($params['file'], 0, $protocol));
} }
if (isset($template->smarty->security_policy)) { if (isset($template->getSmarty()->security_policy)) {
if ($protocol) { if ($protocol) {
// remote resource (or php stream, …) // remote resource (or php stream, …)
if (!$template->smarty->security_policy->isTrustedUri($params['file'])) { if (!$template->getSmarty()->security_policy->isTrustedUri($params['file'])) {
return; return;
} }
} else { } else {
// local file // local file
if (!$template->smarty->security_policy->isTrustedResourceDir($params['file'])) { if (!$template->getSmarty()->security_policy->isTrustedResourceDir($params['file'])) {
return; return;
} }
} }

View File

@@ -99,15 +99,15 @@ class HtmlImage extends Base {
if ($protocol !== false) { if ($protocol !== false) {
$protocol = strtolower(substr($params['file'], 0, $protocol)); $protocol = strtolower(substr($params['file'], 0, $protocol));
} }
if (isset($template->smarty->security_policy)) { if (isset($template->getSmarty()->security_policy)) {
if ($protocol) { if ($protocol) {
// remote resource (or php stream, …) // remote resource (or php stream, …)
if (!$template->smarty->security_policy->isTrustedUri($params['file'])) { if (!$template->getSmarty()->security_policy->isTrustedUri($params['file'])) {
return; return;
} }
} else { } else {
// local file // local file
if (!$template->smarty->security_policy->isTrustedResourceDir($_image_path)) { if (!$template->getSmarty()->security_policy->isTrustedResourceDir($_image_path)) {
return; return;
} }
} }

View File

@@ -38,7 +38,7 @@ class ExtendsPlugin extends BasePlugin
$uid = ''; $uid = '';
$sources = array(); $sources = array();
$components = explode('|', $source->name); $components = explode('|', $source->name);
$smarty = &$source->smarty; $smarty = $source->getSmarty();
$exists = true; $exists = true;
foreach ($components as $component) { foreach ($components as $component) {
$_s = Source::load(null, $smarty, $component); $_s = Source::load(null, $smarty, $component);
@@ -53,7 +53,7 @@ class ExtendsPlugin extends BasePlugin
} }
$source->components = $sources; $source->components = $sources;
$source->filepath = $_s->filepath; $source->filepath = $_s->filepath;
$source->uid = sha1($uid . $source->smarty->_joined_template_dir); $source->uid = sha1($uid . $source->getSmarty()->_joined_template_dir);
$source->exists = $exists; $source->exists = $exists;
if ($_template) { if ($_template) {
$source->timestamp = $_s->timestamp; $source->timestamp = $_s->timestamp;

View File

@@ -34,13 +34,13 @@ class FilePlugin extends BasePlugin {
public function populate(Source $source, Template $_template = null) { public function populate(Source $source, Template $_template = null) {
$source->filepath = $this->buildFilepath($source, $_template); $source->filepath = $this->buildFilepath($source, $_template);
if ($source->filepath !== false) { if ($source->filepath !== false) {
if (isset($source->smarty->security_policy) && is_object($source->smarty->security_policy)) { if (isset($source->getSmarty()->security_policy) && is_object($source->getSmarty()->security_policy)) {
$source->smarty->security_policy->isTrustedResourceDir($source->filepath, $source->isConfig); $source->getSmarty()->security_policy->isTrustedResourceDir($source->filepath, $source->isConfig);
} }
$source->exists = true; $source->exists = true;
$source->uid = sha1( $source->uid = sha1(
$source->filepath . ($source->isConfig ? $source->smarty->_joined_config_dir : $source->filepath . ($source->isConfig ? $source->getSmarty()->_joined_config_dir :
$source->smarty->_joined_template_dir) $source->getSmarty()->_joined_template_dir)
); );
$source->timestamp = filemtime($source->filepath); $source->timestamp = filemtime($source->filepath);
} else { } else {
@@ -104,19 +104,19 @@ class FilePlugin extends BasePlugin {
$file = $source->name; $file = $source->name;
// absolute file ? // absolute file ?
if ($file[0] === '/' || $file[1] === ':') { if ($file[0] === '/' || $file[1] === ':') {
$file = $source->smarty->_realpath($file, true); $file = $source->getSmarty()->_realpath($file, true);
return is_file($file) ? $file : false; return is_file($file) ? $file : false;
} }
// go relative to a given template? // go relative to a given template?
if ($file[0] === '.' && $_template && $_template->_isSubTpl() if ($file[0] === '.' && $_template && $_template->_isSubTpl()
&& preg_match('#^[.]{1,2}[\\\/]#', $file) && preg_match('#^[.]{1,2}[\\\/]#', $file)
) { ) {
if ($_template->parent->source->type !== 'file' && $_template->parent->source->type !== 'extends') { if ($_template->parent->getSource()->type !== 'file' && $_template->parent->getSource()->type !== 'extends') {
throw new Exception("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'"); throw new Exception("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->getSource()->type}'");
} }
// normalize path // normalize path
$path = $path =
$source->smarty->_realpath(dirname($_template->parent->source->filepath) . DIRECTORY_SEPARATOR . $file); $source->getSmarty()->_realpath(dirname($_template->parent->getSource()->filepath) . DIRECTORY_SEPARATOR . $file);
// files relative to a template only get one shot // files relative to a template only get one shot
return is_file($path) ? $path : false; return is_file($path) ? $path : false;
} }
@@ -124,7 +124,7 @@ class FilePlugin extends BasePlugin {
if (strpos($file, DIRECTORY_SEPARATOR === '/' ? '\\' : '/') !== false) { if (strpos($file, DIRECTORY_SEPARATOR === '/' ? '\\' : '/') !== false) {
$file = str_replace(DIRECTORY_SEPARATOR === '/' ? '\\' : '/', DIRECTORY_SEPARATOR, $file); $file = str_replace(DIRECTORY_SEPARATOR === '/' ? '\\' : '/', DIRECTORY_SEPARATOR, $file);
} }
$_directories = $source->smarty->getTemplateDir(null, $source->isConfig); $_directories = $source->getSmarty()->getTemplateDir(null, $source->isConfig);
// template_dir index? // template_dir index?
if ($file[0] === '[' && preg_match('#^\[([^\]]+)\](.+)$#', $file, $fileMatch)) { if ($file[0] === '[' && preg_match('#^\[([^\]]+)\](.+)$#', $file, $fileMatch)) {
$file = $fileMatch[2]; $file = $fileMatch[2];
@@ -160,12 +160,12 @@ class FilePlugin extends BasePlugin {
foreach ($_directories as $_directory) { foreach ($_directories as $_directory) {
$path = $_directory . $file; $path = $_directory . $file;
if (is_file($path)) { if (is_file($path)) {
return (strpos($path, '.' . DIRECTORY_SEPARATOR) !== false) ? $source->smarty->_realpath($path) : $path; return (strpos($path, '.' . DIRECTORY_SEPARATOR) !== false) ? $source->getSmarty()->_realpath($path) : $path;
} }
} }
if (!isset($_index_dirs)) { if (!isset($_index_dirs)) {
// Could be relative to cwd // Could be relative to cwd
$path = $source->smarty->_realpath($file, true); $path = $source->getSmarty()->_realpath($file, true);
if (is_file($path)) { if (is_file($path)) {
return $path; return $path;
} }

View File

@@ -32,7 +32,7 @@ class StringPlugin extends BasePlugin {
* @return void * @return void
*/ */
public function populate(Source $source, Template $_template = null) { public function populate(Source $source, Template $_template = null) {
$source->uid = $source->filepath = sha1($source->name . $source->smarty->_joined_template_dir); $source->uid = $source->filepath = sha1($source->name . $source->getSmarty()->_joined_template_dir);
$source->timestamp = $source->exists = true; $source->timestamp = $source->exists = true;
} }

View File

@@ -75,7 +75,7 @@ class InheritanceRuntime {
return; return;
} }
++$this->tplIndex; ++$this->tplIndex;
$this->sources[$this->tplIndex] = $tpl->source; $this->sources[$this->tplIndex] = $tpl->getSource();
// start of child sub template(s) // start of child sub template(s)
if ($initChild) { if ($initChild) {
$this->state = 1; $this->state = 1;
@@ -238,9 +238,9 @@ class InheritanceRuntime {
* @param Template $tpl * @param Template $tpl
*/ */
public function callBlock(\Smarty\Runtime\Block $block, Template $tpl) { public function callBlock(\Smarty\Runtime\Block $block, Template $tpl) {
$this->sourceStack[] = $tpl->source; $this->sourceStack[] = $tpl->getSource();
$tpl->source = $this->sources[$block->tplIndex]; $tpl->setSource($this->sources[$block->tplIndex]);
$block->callBlock($tpl); $block->callBlock($tpl);
$tpl->source = array_pop($this->sourceStack); $tpl->setSource(array_pop($this->sourceStack));
} }
} }

View File

@@ -25,7 +25,7 @@ class TplFunctionRuntime {
* @throws \Smarty\Exception * @throws \Smarty\Exception
*/ */
public function callTemplateFunction(Template $tpl, $name, $params, $nocache) { public function callTemplateFunction(Template $tpl, $name, $params, $nocache) {
$funcParam = $tpl->tplFunctions[$name] ?? ($tpl->smarty->tplFunctions[$name] ?? null); $funcParam = $tpl->tplFunctions[$name] ?? ($tpl->getSmarty()->tplFunctions[$name] ?? null);
if (isset($funcParam)) { if (isset($funcParam)) {
if (!$tpl->caching || ($tpl->caching && $nocache)) { if (!$tpl->caching || ($tpl->caching && $nocache)) {
$function = $funcParam['call_name']; $function = $funcParam['call_name'];
@@ -70,8 +70,8 @@ class TplFunctionRuntime {
if ($obj->_isSubTpl()) { if ($obj->_isSubTpl()) {
$this->registerTplFunctions($obj->parent, $tplFunctions, false); $this->registerTplFunctions($obj->parent, $tplFunctions, false);
} else { } else {
$obj->smarty->tplFunctions = $override ? array_merge($obj->smarty->tplFunctions, $tplFunctions) : $obj->getSmarty()->tplFunctions = $override ? array_merge($obj->getSmarty()->tplFunctions, $tplFunctions) :
array_merge($tplFunctions, $obj->smarty->tplFunctions); array_merge($tplFunctions, $obj->getSmarty()->tplFunctions);
} }
} }
@@ -85,9 +85,9 @@ class TplFunctionRuntime {
*/ */
public function getTplFunction(Template $tpl, $name = null) { public function getTplFunction(Template $tpl, $name = null) {
if (isset($name)) { if (isset($name)) {
return $tpl->tplFunctions[$name] ?? ($tpl->smarty->tplFunctions[$name] ?? false); return $tpl->tplFunctions[$name] ?? ($tpl->getSmarty()->tplFunctions[$name] ?? false);
} else { } else {
return empty($tpl->tplFunctions) ? $tpl->smarty->tplFunctions : $tpl->tplFunctions; return empty($tpl->tplFunctions) ? $tpl->getSmarty()->tplFunctions : $tpl->tplFunctions;
} }
} }

View File

@@ -1024,7 +1024,7 @@ class Smarty extends \Smarty\TemplateBase
$tpl->tplFunctions = array_merge($parent->tplFunctions ?? [], $tpl->tplFunctions ?? []); $tpl->tplFunctions = array_merge($parent->tplFunctions ?? [], $tpl->tplFunctions ?? []);
if (!$this->debugging && $this->debugging_ctrl === 'URL') { if (!$this->debugging && $this->debugging_ctrl === 'URL') {
$tpl->smarty->getDebug()->debugUrl($tpl->smarty); $tpl->getSmarty()->getDebug()->debugUrl($tpl->getSmarty());
} }
return $tpl; return $tpl;
} }
@@ -1062,7 +1062,7 @@ class Smarty extends \Smarty\TemplateBase
$nameIsDotted = !empty($name) && $name[0] === '.' && ($name[1] === '.' || $name[1] === '/'); $nameIsDotted = !empty($name) && $name[0] === '.' && ($name[1] === '.' || $name[1] === '/');
$id_parts[] = $type; $id_parts[] = $type;
$id_parts[] = $this->_getSmartyObj()->_joined_template_dir; $id_parts[] = $this->getSmarty()->_joined_template_dir;
// handle relative template names // handle relative template names
if ($baseFilePath && $nameIsDotted) { if ($baseFilePath && $nameIsDotted) {
@@ -1289,10 +1289,10 @@ class Smarty extends \Smarty\TemplateBase
/** /**
* Get Smarty object * Get Smarty object
* * // @TODO this is silly, remove?
* @return Smarty * @return Smarty
*/ */
public function _getSmartyObj() public function getSmarty()
{ {
return $this; return $this;
} }
@@ -1420,7 +1420,7 @@ class Smarty extends \Smarty\TemplateBase
/* @var Template $tpl */ /* @var Template $tpl */
$tpl = $this->createTemplate($resource_name); $tpl = $this->createTemplate($resource_name);
$this->caching = $_save_stat; $this->caching = $_save_stat;
if (!$tpl->source->handler->recompiled && $tpl->source->exists) { if (!$tpl->getSource()->handler->recompiled && $tpl->getSource()->exists) {
$_resource_part_1 = basename(str_replace('^', DIRECTORY_SEPARATOR, $tpl->getCompiled()->filepath)); $_resource_part_1 = basename(str_replace('^', DIRECTORY_SEPARATOR, $tpl->getCompiled()->filepath));
$_resource_part_1_length = strlen($_resource_part_1); $_resource_part_1_length = strlen($_resource_part_1);
} else { } else {
@@ -1596,8 +1596,9 @@ class Smarty extends \Smarty\TemplateBase
try { try {
$_tpl = new \Smarty\Template($_file, $_smarty); $_tpl = new \Smarty\Template($_file, $_smarty);
$_tpl->caching = self::CACHING_OFF; $_tpl->caching = self::CACHING_OFF;
$_tpl->source = $_tpl->setSource(
$isConfig ? \Smarty\Template\Config::load($_tpl) : \Smarty\Template\Source::load($_tpl); $isConfig ? \Smarty\Template\Config::load($_tpl) : \Smarty\Template\Source::load($_tpl)
);
if ($_tpl->mustCompile()) { if ($_tpl->mustCompile()) {
$_tpl->compileTemplateSource(); $_tpl->compileTemplateSource();
$_count++; $_count++;

View File

@@ -47,7 +47,7 @@ class Template extends TemplateBase {
* *
* @var Source|Config * @var Source|Config
*/ */
public $source = null; private $source = null;
/** /**
* Template resource * Template resource
@@ -161,14 +161,14 @@ class Template extends TemplateBase {
$this->smarty->getDebug()->start_template($this, $display); $this->smarty->getDebug()->start_template($this, $display);
} }
// checks if template exists // checks if template exists
if (!$this->source->exists) { if (!$this->getSource()->exists) {
throw new Exception( throw new Exception(
"Unable to load template '{$this->source->type}:{$this->source->name}'" . "Unable to load template '{$this->getSource()->type}:{$this->getSource()->name}'" .
($this->_isSubTpl() ? " in '{$this->parent->template_resource}'" : '') ($this->_isSubTpl() ? " in '{$this->parent->template_resource}'" : '')
); );
} }
// disable caching for evaluated code // disable caching for evaluated code
if ($this->source->handler->recompiled) { if ($this->getSource()->handler->recompiled) {
$this->caching = \Smarty\Smarty::CACHING_OFF; $this->caching = \Smarty\Smarty::CACHING_OFF;
} }
// read from cache or render // read from cache or render
@@ -193,7 +193,7 @@ class Template extends TemplateBase {
isset($content) ? $content : ob_get_clean() isset($content) ? $content : ob_get_clean()
); );
} else { } else {
if ((!$this->caching || $this->getCached()->getNocacheCode() || $this->source->handler->recompiled) if ((!$this->caching || $this->getCached()->getNocacheCode() || $this->getSource()->handler->recompiled)
&& !$no_output_filter && isset($this->smarty->registered_filters['output']) && !$no_output_filter && isset($this->smarty->registered_filters['output'])
) { ) {
echo $this->smarty->runOutputFilters(ob_get_clean(), $this); echo $this->smarty->runOutputFilters(ob_get_clean(), $this);
@@ -216,7 +216,7 @@ class Template extends TemplateBase {
} }
if ( if (
!$no_output_filter !$no_output_filter
&& (!$this->caching || $this->getCached()->getNocacheCode() || $this->source->handler->recompiled) && (!$this->caching || $this->getCached()->getNocacheCode() || $this->getSource()->handler->recompiled)
) { ) {
return $this->smarty->runOutputFilters(ob_get_clean(), $this); return $this->smarty->runOutputFilters(ob_get_clean(), $this);
@@ -252,9 +252,9 @@ class Template extends TemplateBase {
$content_func = null $content_func = null
) { ) {
$baseFilePath = $this->source && $this->source->filepath ? dirname($this->source->filepath) : null; $baseFilePath = $this->source && $this->getSource()->filepath ? dirname($this->getSource()->filepath) : null;
$tpl = $this->_getSmartyObj()->createTemplate($template_name, $cache_id, $compile_id, $this, $caching, $cache_lifetime, $baseFilePath); $tpl = $this->getSmarty()->createTemplate($template_name, $cache_id, $compile_id, $this, $caching, $cache_lifetime, $baseFilePath);
// copy variables // copy variables
$tpl->tpl_vars = $this->tpl_vars; $tpl->tpl_vars = $this->tpl_vars;
@@ -266,13 +266,14 @@ class Template extends TemplateBase {
if (isset($uid) && $this->getCompiled()->file_dependency) { if (isset($uid) && $this->getCompiled()->file_dependency) {
// for inline templates we can get all resource information from file dependency // for inline templates we can get all resource information from file dependency
[$filepath, $timestamp, $type] = $this->getCompiled()->file_dependency[$uid]; [$filepath, $timestamp, $type] = $this->getCompiled()->file_dependency[$uid];
$tpl->source = new Source($this->_getSmartyObj(), $filepath, $type, $filepath); $source = new Source($this->getSmarty(), $filepath, $type, $filepath);
$tpl->source->filepath = $filepath; $source->filepath = $filepath;
$tpl->source->timestamp = $timestamp; $source->timestamp = $timestamp;
$tpl->source->exists = true; $source->exists = true;
$tpl->source->uid = $uid; $source->uid = $uid;
$tpl->setSource($source);
} else { } else {
$tpl->source = Source::load($tpl); $tpl->setSource(Source::load($tpl));
$tpl->getCompiled(true); // @TODO this unset($tpl->compiled), there might be a bug here $tpl->getCompiled(true); // @TODO this unset($tpl->compiled), there might be a bug here
} }
if ($caching !== \Smarty\Template::CACHING_NOCACHE_CODE) { if ($caching !== \Smarty\Template::CACHING_NOCACHE_CODE) {
@@ -292,7 +293,7 @@ class Template extends TemplateBase {
} }
} }
if (isset($uid)) { if (isset($uid)) {
$smarty = $this->_getSmartyObj(); $smarty = $this->getSmarty();
if ($smarty->debugging) { if ($smarty->debugging) {
$smarty->getDebug()->start_template($tpl); $smarty->getDebug()->start_template($tpl);
$smarty->getDebug()->start_render($tpl); $smarty->getDebug()->start_render($tpl);
@@ -346,9 +347,9 @@ class Template extends TemplateBase {
// on cache resources other than file check version stored in cache code // on cache resources other than file check version stored in cache code
if (!isset($properties['version']) || \Smarty\Smarty::SMARTY_VERSION !== $properties['version']) { if (!isset($properties['version']) || \Smarty\Smarty::SMARTY_VERSION !== $properties['version']) {
if ($cache) { if ($cache) {
$tpl->smarty->clearAllCache(); $tpl->getSmarty()->clearAllCache();
} else { } else {
$tpl->smarty->clearCompiledTemplate(); $tpl->getSmarty()->clearCompiledTemplate();
} }
return false; return false;
} }
@@ -359,18 +360,18 @@ class Template extends TemplateBase {
// check file dependencies at compiled code // check file dependencies at compiled code
foreach ($properties['file_dependency'] as $_file_to_check) { foreach ($properties['file_dependency'] as $_file_to_check) {
if ($_file_to_check[2] === 'file' || $_file_to_check[2] === 'php') { if ($_file_to_check[2] === 'file' || $_file_to_check[2] === 'php') {
if ($tpl->source->filepath === $_file_to_check[0]) { if ($tpl->getSource()->filepath === $_file_to_check[0]) {
// do not recheck current template // do not recheck current template
continue; continue;
//$mtime = $tpl->source->getTimeStamp(); //$mtime = $tpl->getSource()->getTimeStamp();
} else { } else {
// file and php types can be checked without loading the respective resource handlers // file and php types can be checked without loading the respective resource handlers
$mtime = is_file($_file_to_check[0]) ? filemtime($_file_to_check[0]) : false; $mtime = is_file($_file_to_check[0]) ? filemtime($_file_to_check[0]) : false;
} }
} else { } else {
$handler = \Smarty\Resource\BasePlugin::load($tpl->smarty, $_file_to_check[2]); $handler = \Smarty\Resource\BasePlugin::load($tpl->getSmarty(), $_file_to_check[2]);
if ($handler->checkTimestamps()) { if ($handler->checkTimestamps()) {
$source = Source::load($tpl, $tpl->smarty, $_file_to_check[0]); $source = Source::load($tpl, $tpl->getSmarty(), $_file_to_check[0]);
$mtime = $source->getTimeStamp(); $mtime = $source->getTimeStamp();
} else { } else {
continue; continue;
@@ -415,6 +416,16 @@ class Template extends TemplateBase {
return $this->getCompiled()->compileTemplateSource($this); return $this->getCompiled()->compileTemplateSource($this);
} }
/**
* Return cached content
*
* @return null|string
* @throws Exception
*/
public function getCachedContent() {
return $this->getCachedContent($this);
}
/** /**
* Writes the content to cache resource * Writes the content to cache resource
* *
@@ -423,7 +434,7 @@ class Template extends TemplateBase {
* @return bool * @return bool
*/ */
public function writeCachedContent($content) { public function writeCachedContent($content) {
if ($this->source->handler->recompiled || !$this->caching if ($this->getSource()->handler->recompiled || !$this->caching
) { ) {
// don't write cache file // don't write cache file
return false; return false;
@@ -472,17 +483,23 @@ class Template extends TemplateBase {
*/ */
public function getCached($forceNew = false): Cached { public function getCached($forceNew = false): Cached {
if ($forceNew || !isset($this->cached)) { if ($forceNew || !isset($this->cached)) {
$this->cached = new Cached($this); $cacheResource = $this->smarty->getCacheResource();
$this->cached->handler->populate($this->cached, $this); $this->cached = new Cached(
$this->source,
$cacheResource,
$this->compile_id,
$this->cache_id
);
$cacheResource->populate($this->cached, $this);
if (!$this->isCachingEnabled()) { if (!$this->isCachingEnabled()) {
$this->cached->valid = false; $this->cached->setValid(false);
} }
} }
return $this->cached; return $this->cached;
} }
public function isCachingEnabled(): bool { public function isCachingEnabled(): bool {
return $this->caching && !$this->source->handler->recompiled; return $this->caching && !$this->getSource()->handler->recompiled;
} }
/** /**
@@ -492,7 +509,7 @@ class Template extends TemplateBase {
* @throws Exception * @throws Exception
*/ */
public function getInheritance(): InheritanceRuntime { public function getInheritance(): InheritanceRuntime {
return $this->_getSmartyObj()->getRuntime('Inheritance'); return $this->getSmarty()->getRuntime('Inheritance');
} }
/** /**
@@ -508,7 +525,7 @@ class Template extends TemplateBase {
*/ */
public function getCompiler() { public function getCompiler() {
if (!isset($this->compiler)) { if (!isset($this->compiler)) {
$this->compiler = $this->source->createCompiler(); $this->compiler = $this->getSource()->createCompiler();
} }
return $this->compiler; return $this->compiler;
} }
@@ -546,19 +563,19 @@ class Template extends TemplateBase {
* @throws \Smarty\Exception * @throws \Smarty\Exception
*/ */
public function mustCompile() { public function mustCompile() {
if (!$this->source->exists) { if (!$this->getSource()->exists) {
if ($this->_isSubTpl()) { if ($this->_isSubTpl()) {
$parent_resource = " in '{$this->parent->template_resource}'"; $parent_resource = " in '{$this->parent->template_resource}'";
} else { } else {
$parent_resource = ''; $parent_resource = '';
} }
throw new Exception("Unable to load template {$this->source->type} '{$this->source->name}'{$parent_resource}"); throw new Exception("Unable to load template {$this->getSource()->type} '{$this->getSource()->name}'{$parent_resource}");
} }
if ($this->mustCompile === null) { if ($this->mustCompile === null) {
$this->mustCompile = $this->smarty->force_compile $this->mustCompile = $this->smarty->force_compile
|| $this->source->handler->recompiled || $this->getSource()->handler->recompiled
|| !$this->getCompiled()->exists || !$this->getCompiled()->exists
|| ($this->compile_check && $this->getCompiled()->getTimeStamp() < $this->source->getTimeStamp()); || ($this->compile_check && $this->getCompiled()->getTimeStamp() < $this->getSource()->getTimeStamp());
} }
return $this->mustCompile; return $this->mustCompile;
} }
@@ -574,7 +591,7 @@ class Template extends TemplateBase {
*/ */
public function getLeftDelimiter() public function getLeftDelimiter()
{ {
return $this->left_delimiter ?? $this->_getSmartyObj()->getLeftDelimiter(); return $this->left_delimiter ?? $this->getSmarty()->getLeftDelimiter();
} }
/** /**
@@ -594,7 +611,7 @@ class Template extends TemplateBase {
*/ */
public function getRightDelimiter() public function getRightDelimiter()
{ {
return $this->right_delimiter ?? $this->_getSmartyObj()->getRightDelimiter();; return $this->right_delimiter ?? $this->getSmarty()->getRightDelimiter();;
} }
/** /**
@@ -627,7 +644,7 @@ class Template extends TemplateBase {
fclose($fp); fclose($fp);
return $_result; return $_result;
} }
if ($this->_getSmartyObj()->error_unassigned) { if ($this->getSmarty()->error_unassigned) {
throw new Exception('Undefined stream variable "' . $variable . '"'); throw new Exception('Undefined stream variable "' . $variable . '"');
} }
return null; return null;
@@ -639,8 +656,8 @@ class Template extends TemplateBase {
{ {
$confObj = parent::configLoad($config_file, $sections); $confObj = parent::configLoad($config_file, $sections);
$this->getCompiled()->file_dependency[ $confObj->source->uid ] = $this->getCompiled()->file_dependency[ $confObj->getSource()->uid ] =
array($confObj->source->filepath, $confObj->source->getTimeStamp(), $confObj->source->type); array($confObj->getSource()->filepath, $confObj->getSource()->getTimeStamp(), $confObj->getSource()->type);
return $confObj; return $confObj;
} }
@@ -683,7 +700,7 @@ class Template extends TemplateBase {
*/ */
private function _execute($function) { private function _execute($function) {
$smarty = $this->_getSmartyObj(); $smarty = $this->getSmarty();
// make sure we have integer values // make sure we have integer values
$this->caching = (int)$this->caching; $this->caching = (int)$this->caching;
@@ -773,10 +790,24 @@ class Template extends TemplateBase {
while (ob_get_level() > $level) { while (ob_get_level() > $level) {
ob_end_clean(); ob_end_clean();
} }
if (isset($this->_getSmartyObj()->security_policy)) { if (isset($this->getSmarty()->security_policy)) {
$this->_getSmartyObj()->security_policy->endTemplate(); $this->getSmarty()->security_policy->endTemplate();
} }
throw $e; throw $e;
} }
} }
/**
* @return Config|Source|null
*/
public function getSource() {
return $this->source;
}
/**
* @param Config|Source|null $source
*/
public function setSource($source): void {
$this->source = $source;
}
} }

View File

@@ -2,7 +2,9 @@
namespace Smarty\Template; namespace Smarty\Template;
use Smarty\Exception;
use Smarty\Template; use Smarty\Template;
use Smarty\Template\Cacheresource\Base;
/** /**
* Represents a cached version of a template or config file. * Represents a cached version of a template or config file.
@@ -17,6 +19,20 @@ class Cached extends GeneratedPhpFile {
*/ */
public $valid = null; public $valid = null;
/**
* @return bool|null
*/
public function getValid(): ?bool {
return $this->valid;
}
/**
* @param bool|null $valid
*/
public function setValid(?bool $valid): void {
$this->valid = $valid;
}
/** /**
* CacheResource Handler * CacheResource Handler
* *
@@ -81,15 +97,16 @@ class Cached extends GeneratedPhpFile {
/** /**
* create Cached Object container * create Cached Object container
* *
* @param Template $_template template object * @param Source $source
* * @param \Smarty\Cacheresource\Base $handler
* @throws \Smarty\Exception * @param $compile_id
* @param $cache_id
*/ */
public function __construct(Template $_template) { public function __construct(Source $source, \Smarty\Cacheresource\Base $handler, $compile_id, $cache_id) {
$this->compile_id = $_template->compile_id; $this->compile_id = $compile_id;
$this->cache_id = $_template->cache_id; $this->cache_id = $cache_id;
$this->source = $_template->source; $this->source = $source;
$this->handler = $_template->smarty->getCacheResource(); $this->handler = $handler;
} }
/** /**
@@ -102,15 +119,15 @@ class Cached extends GeneratedPhpFile {
*/ */
public function render(Template $_template, $no_output_filter = true) { public function render(Template $_template, $no_output_filter = true) {
if ($this->isCached($_template)) { if ($this->isCached($_template)) {
if ($_template->smarty->debugging) { if ($_template->getSmarty()->debugging) {
$_template->smarty->getDebug()->start_cache($_template); $_template->getSmarty()->getDebug()->start_cache($_template);
} }
if (!$this->processed) { if (!$this->processed) {
$this->process($_template); $this->process($_template);
} }
$this->renderTemplateCode($_template); $this->renderTemplateCode($_template);
if ($_template->smarty->debugging) { if ($_template->getSmarty()->debugging) {
$_template->smarty->getDebug()->end_cache($_template); $_template->getSmarty()->getDebug()->end_cache($_template);
} }
return; return;
} else { } else {
@@ -121,9 +138,10 @@ class Cached extends GeneratedPhpFile {
/** /**
* Check if cache is valid, lock cache if required * Check if cache is valid, lock cache if required
* *
* @param \Smarty\Template $_template * @param Template $_template
* *
* @return bool flag true if cache is valid * @return bool flag true if cache is valid
* @throws Exception
*/ */
public function isCached(Template $_template) { public function isCached(Template $_template) {
if ($this->valid !== null) { if ($this->valid !== null) {
@@ -131,7 +149,7 @@ class Cached extends GeneratedPhpFile {
} }
while (true) { while (true) {
while (true) { while (true) {
if ($this->exists === false || $_template->smarty->force_compile || $_template->smarty->force_cache) { if ($this->exists === false || $_template->getSmarty()->force_compile || $_template->getSmarty()->force_cache) {
$this->valid = false; $this->valid = false;
} else { } else {
$this->valid = true; $this->valid = true;
@@ -143,32 +161,32 @@ class Cached extends GeneratedPhpFile {
$this->valid = false; $this->valid = false;
} }
if ($this->valid && $_template->compile_check === \Smarty\Smarty::COMPILECHECK_ON if ($this->valid && $_template->compile_check === \Smarty\Smarty::COMPILECHECK_ON
&& $_template->source->getTimeStamp() > $this->timestamp && $_template->getSource()->getTimeStamp() > $this->timestamp
) { ) {
$this->valid = false; $this->valid = false;
} }
if ($this->valid || !$_template->smarty->cache_locking) { if ($this->valid || !$_template->getSmarty()->cache_locking) {
break; break;
} }
if (!$this->handler->locked($_template->smarty, $this)) { if (!$this->handler->locked($_template->getSmarty(), $this)) {
$this->handler->acquireLock($_template->smarty, $this); $this->handler->acquireLock($_template->getSmarty(), $this);
break 2; break 2;
} }
$this->handler->populate($this, $_template); $this->handler->populate($this, $_template);
} }
if ($this->valid) { if ($this->valid) {
if (!$_template->smarty->cache_locking || $this->handler->locked($_template->smarty, $this) === null) { if (!$_template->getSmarty()->cache_locking || $this->handler->locked($_template->getSmarty(), $this) === null) {
// load cache file for the following checks // load cache file for the following checks
if ($_template->smarty->debugging) { if ($_template->getSmarty()->debugging) {
$_template->smarty->getDebug()->start_cache($_template); $_template->getSmarty()->getDebug()->start_cache($_template);
} }
if ($this->handler->process($_template, $this) === false) { if ($this->handler->process($_template, $this) === false) {
$this->valid = false; $this->valid = false;
} else { } else {
$this->processed = true; $this->processed = true;
} }
if ($_template->smarty->debugging) { if ($_template->getSmarty()->debugging) {
$_template->smarty->getDebug()->end_cache($_template); $_template->getSmarty()->getDebug()->end_cache($_template);
} }
} else { } else {
$this->is_locked = true; $this->is_locked = true;
@@ -183,11 +201,11 @@ class Cached extends GeneratedPhpFile {
) { ) {
$this->valid = false; $this->valid = false;
} }
if ($_template->smarty->cache_locking) { if ($_template->getSmarty()->cache_locking) {
if (!$this->valid) { if (!$this->valid) {
$this->handler->acquireLock($_template->smarty, $this); $this->handler->acquireLock($_template->getSmarty(), $this);
} elseif ($this->is_locked) { } elseif ($this->is_locked) {
$this->handler->releaseLock($_template->smarty, $this); $this->handler->releaseLock($_template->getSmarty(), $this);
} }
} }
return $this->valid; return $this->valid;
@@ -220,7 +238,7 @@ class Cached extends GeneratedPhpFile {
* @return string|false content * @return string|false content
*/ */
public function readCache(Template $_template) { public function readCache(Template $_template) {
if (!$_template->source->handler->recompiled) { if (!$_template->getSource()->handler->recompiled) {
return $this->handler->retrieveCachedContent($_template); return $this->handler->retrieveCachedContent($_template);
} }
return false; return false;
@@ -234,7 +252,7 @@ class Cached extends GeneratedPhpFile {
* @return bool success * @return bool success
*/ */
public function writeCache(Template $_template, $content) { public function writeCache(Template $_template, $content) {
if (!$_template->source->handler->recompiled) { if (!$_template->getSource()->handler->recompiled) {
if ($this->handler->storeCachedContent($_template, $content)) { if ($this->handler->storeCachedContent($_template, $content)) {
$this->content = null; $this->content = null;
$this->timestamp = time(); $this->timestamp = time();
@@ -242,8 +260,8 @@ class Cached extends GeneratedPhpFile {
$this->valid = true; $this->valid = true;
$this->cache_lifetime = $_template->cache_lifetime; $this->cache_lifetime = $_template->cache_lifetime;
$this->processed = false; $this->processed = false;
if ($_template->smarty->cache_locking) { if ($_template->getSmarty()->cache_locking) {
$this->handler->releaseLock($_template->smarty, $this); $this->handler->releaseLock($_template->getSmarty(), $this);
} }
return true; return true;
} }
@@ -268,8 +286,8 @@ class Cached extends GeneratedPhpFile {
ob_start(); ob_start();
$_template->getCompiled()->render($_template); $_template->getCompiled()->render($_template);
if ($_template->smarty->debugging) { if ($_template->getSmarty()->debugging) {
$_template->smarty->getDebug()->start_cache($_template); $_template->getSmarty()->getDebug()->start_cache($_template);
} }
$this->removeNoCacheHash($_template, $no_output_filter); $this->removeNoCacheHash($_template, $no_output_filter);
$compile_check = (int)$_template->compile_check; $compile_check = (int)$_template->compile_check;
@@ -282,8 +300,8 @@ class Cached extends GeneratedPhpFile {
} }
$_template->compile_check = $compile_check; $_template->compile_check = $compile_check;
$this->renderTemplateCode($_template); $this->renderTemplateCode($_template);
if ($_template->smarty->debugging) { if ($_template->getSmarty()->debugging) {
$_template->smarty->getDebug()->end_cache($_template); $_template->getSmarty()->getDebug()->end_cache($_template);
} }
} }
@@ -347,10 +365,24 @@ class Cached extends GeneratedPhpFile {
!$no_output_filter !$no_output_filter
&& !$_template->getCached()->getNocacheCode() && !$_template->getCached()->getNocacheCode()
) { ) {
$content = $_template->smarty->runOutputFilters($content, $_template); $content = $_template->getSmarty()->runOutputFilters($content, $_template);
} }
// write cache file content // write cache file content
$_template->writeCachedContent($content); $_template->writeCachedContent($content);
} }
/**
* @return Source|null
*/
public function getSource(): ?Source {
return $this->source;
}
/**
* @param Source|null $source
*/
public function setSource(?Source $source): void {
$this->source = $source;
}
} }

View File

@@ -35,7 +35,7 @@ class Compiled extends GeneratedPhpFile {
*/ */
public static function load($_template) { public static function load($_template) {
$compiled = new Compiled(); $compiled = new Compiled();
if ($_template->source->handler->supportsCompiledTemplates()) { if ($_template->getSource()->handler->supportsCompiledTemplates()) {
$compiled->populateCompiledFilepath($_template); $compiled->populateCompiledFilepath($_template);
} }
return $compiled; return $compiled;
@@ -47,8 +47,8 @@ class Compiled extends GeneratedPhpFile {
* @param Template $_template template object * @param Template $_template template object
**/ **/
private function populateCompiledFilepath(Template $_template) { private function populateCompiledFilepath(Template $_template) {
$source = &$_template->source; $source = $_template->getSource();
$smarty = &$_template->smarty; $smarty = $_template->getSmarty();
$this->filepath = $smarty->getCompileDir(); $this->filepath = $smarty->getCompileDir();
if (isset($_template->compile_id)) { if (isset($_template->compile_id)) {
$this->filepath .= preg_replace('![^\w]+!', '_', $_template->compile_id) . $this->filepath .= preg_replace('![^\w]+!', '_', $_template->compile_id) .
@@ -93,12 +93,12 @@ class Compiled extends GeneratedPhpFile {
*/ */
public function render(Template $_template) { public function render(Template $_template) {
// checks if template exists // checks if template exists
if (!$_template->source->exists) { if (!$_template->getSource()->exists) {
$type = $_template->source->isConfig ? 'config' : 'template'; $type = $_template->getSource()->isConfig ? 'config' : 'template';
throw new \Smarty\Exception("Unable to load {$type} '{$_template->source->type}:{$_template->source->name}'"); throw new \Smarty\Exception("Unable to load {$type} '{$_template->getSource()->type}:{$_template->getSource()->name}'");
} }
if ($_template->smarty->debugging) { if ($_template->getSmarty()->debugging) {
$_template->smarty->getDebug()->start_render($_template); $_template->getSmarty()->getDebug()->start_render($_template);
} }
if (!$this->processed) { if (!$this->processed) {
$this->process($_template); $this->process($_template);
@@ -112,8 +112,8 @@ class Compiled extends GeneratedPhpFile {
if ($_template->caching && $this->getNocacheCode()) { if ($_template->caching && $this->getNocacheCode()) {
$_template->getCached()->hashes[$this->nocache_hash] = true; $_template->getCached()->hashes[$this->nocache_hash] = true;
} }
if ($_template->smarty->debugging) { if ($_template->getSmarty()->debugging) {
$_template->smarty->getDebug()->end_render($_template); $_template->getSmarty()->getDebug()->end_render($_template);
} }
} }
@@ -125,8 +125,8 @@ class Compiled extends GeneratedPhpFile {
* @throws Exception * @throws Exception
*/ */
private function process(Template $_smarty_tpl) { private function process(Template $_smarty_tpl) {
$source = &$_smarty_tpl->source; $source = $_smarty_tpl->getSource();
$smarty = &$_smarty_tpl->smarty; $smarty = $_smarty_tpl->getSmarty();
if ($source->handler->recompiled) { if ($source->handler->recompiled) {
$source->handler->process($_smarty_tpl); $source->handler->process($_smarty_tpl);
} else { } else {
@@ -166,7 +166,7 @@ class Compiled extends GeneratedPhpFile {
$this->nocache_hash = null; $this->nocache_hash = null;
$this->unifunc = null; $this->unifunc = null;
// compile locking // compile locking
if ($saved_timestamp = (!$_template->source->handler->recompiled && is_file($this->filepath))) { if ($saved_timestamp = (!$_template->getSource()->handler->recompiled && is_file($this->filepath))) {
$saved_timestamp = $this->getTimeStamp(); $saved_timestamp = $this->getTimeStamp();
touch($this->filepath); touch($this->filepath);
} }
@@ -193,8 +193,8 @@ class Compiled extends GeneratedPhpFile {
* @throws \Smarty\Exception * @throws \Smarty\Exception
*/ */
public function write(Template $_template, $code) { public function write(Template $_template, $code) {
if (!$_template->source->handler->recompiled) { if (!$_template->getSource()->handler->recompiled) {
if ($_template->smarty->writeFile($this->filepath, $code) === true) { if ($_template->getSmarty()->writeFile($this->filepath, $code) === true) {
$this->timestamp = $this->exists = is_file($this->filepath); $this->timestamp = $this->exists = is_file($this->filepath);
if ($this->exists) { if ($this->exists) {
$this->timestamp = filemtime($this->filepath); $this->timestamp = filemtime($this->filepath);
@@ -214,7 +214,7 @@ class Compiled extends GeneratedPhpFile {
* @return string content * @return string content
*/ */
public function read(Template $_template) { public function read(Template $_template) {
if (!$_template->source->handler->recompiled) { if (!$_template->getSource()->handler->recompiled) {
return file_get_contents($this->filepath); return file_get_contents($this->filepath);
} }
return false; return false;

View File

@@ -39,7 +39,7 @@ class Config extends Source {
) { ) {
static $_incompatible_resources = ['extends' => true, 'php' => true]; static $_incompatible_resources = ['extends' => true, 'php' => true];
if ($_template) { if ($_template) {
$smarty = $_template->smarty; $smarty = $_template->getSmarty();
$template_resource = $_template->template_resource; $template_resource = $_template->template_resource;
} }
if (empty($template_resource)) { if (empty($template_resource)) {

View File

@@ -87,7 +87,7 @@ class Source {
* *
* @var Smarty * @var Smarty
*/ */
public $smarty = null; protected $smarty = null;
/** /**
* Resource is source * Resource is source
@@ -140,7 +140,7 @@ class Source {
$template_resource = null $template_resource = null
) { ) {
if ($_template) { if ($_template) {
$smarty = $_template->smarty; $smarty = $_template->getSmarty();
$template_resource = $_template->template_resource; $template_resource = $_template->template_resource;
} }
if (empty($template_resource)) { if (empty($template_resource)) {
@@ -159,8 +159,8 @@ class Source {
// create new source object // create new source object
$source = new Source($smarty, $template_resource, $type, $name); $source = new Source($smarty, $template_resource, $type, $name);
$source->handler->populate($source, $_template); $source->handler->populate($source, $_template);
if (!$source->exists && isset($_template->smarty->default_template_handler_func)) { if (!$source->exists && $_template && isset($_template->getSmarty()->default_template_handler_func)) {
$source->_getDefaultTemplate($_template->smarty->default_template_handler_func); $source->_getDefaultTemplate($_template->getSmarty()->default_template_handler_func);
$source->handler->populate($source, $_template); $source->handler->populate($source, $_template);
} }
return $source; return $source;
@@ -230,4 +230,8 @@ class Source {
return new \Smarty\Compiler\Template($this->smarty); return new \Smarty\Compiler\Template($this->smarty);
} }
public function getSmarty() {
return $this->smarty;
}
} }

View File

@@ -93,7 +93,7 @@ abstract class TemplateBase extends Data {
$format = true, $format = true,
$block_methods = [] $block_methods = []
) { ) {
$smarty = $this->_getSmartyObj(); $smarty = $this->getSmarty();
// test if allowed methods callable // test if allowed methods callable
if (!empty($allowed_methods_properties)) { if (!empty($allowed_methods_properties)) {
foreach ((array)$allowed_methods_properties as $method) { foreach ((array)$allowed_methods_properties as $method) {
@@ -127,7 +127,7 @@ abstract class TemplateBase extends Data {
* *
*/ */
public function unregisterObject($object_name) { public function unregisterObject($object_name) {
$smarty = $this->_getSmartyObj(); $smarty = $this->getSmarty();
if (isset($smarty->registered_objects[$object_name])) { if (isset($smarty->registered_objects[$object_name])) {
unset($smarty->registered_objects[$object_name]); unset($smarty->registered_objects[$object_name]);
} }
@@ -191,7 +191,7 @@ abstract class TemplateBase extends Data {
*/ */
public function createData(Data $parent = null, $name = null) { public function createData(Data $parent = null, $name = null) {
/* @var Smarty $smarty */ /* @var Smarty $smarty */
$smarty = $this->_getSmartyObj(); $smarty = $this->getSmarty();
$dataObj = new Data($parent, $smarty, $name); $dataObj = new Data($parent, $smarty, $name);
if ($smarty->debugging) { if ($smarty->debugging) {
$smarty->getDebug()->register_data($dataObj); $smarty->getDebug()->register_data($dataObj);
@@ -207,7 +207,7 @@ abstract class TemplateBase extends Data {
* *
*/ */
public function getDebugTemplate() { public function getDebugTemplate() {
$smarty = $this->_getSmartyObj(); $smarty = $this->getSmarty();
return $smarty->debug_tpl; return $smarty->debug_tpl;
} }
@@ -234,7 +234,7 @@ abstract class TemplateBase extends Data {
* @api Smarty::getRegisteredObject() * @api Smarty::getRegisteredObject()
*/ */
public function getRegisteredObject($object_name) { public function getRegisteredObject($object_name) {
$smarty = $this->_getSmartyObj(); $smarty = $this->getSmarty();
if (!isset($smarty->registered_objects[$object_name])) { if (!isset($smarty->registered_objects[$object_name])) {
throw new Exception("'$object_name' is not a registered object"); throw new Exception("'$object_name' is not a registered object");
} }
@@ -252,7 +252,7 @@ abstract class TemplateBase extends Data {
* *
*/ */
public function getLiterals() { public function getLiterals() {
$smarty = $this->_getSmartyObj(); $smarty = $this->getSmarty();
return (array)$smarty->literals; return (array)$smarty->literals;
} }
@@ -269,7 +269,7 @@ abstract class TemplateBase extends Data {
*/ */
public function addLiterals($literals = null) { public function addLiterals($literals = null) {
if (isset($literals)) { if (isset($literals)) {
$this->_setLiterals($this->_getSmartyObj(), (array)$literals); $this->_setLiterals($this->getSmarty(), (array)$literals);
} }
return $this; return $this;
} }
@@ -286,7 +286,7 @@ abstract class TemplateBase extends Data {
* *
*/ */
public function setLiterals($literals = null) { public function setLiterals($literals = null) {
$smarty = $this->_getSmartyObj(); $smarty = $this->getSmarty();
$smarty->literals = []; $smarty->literals = [];
if (!empty($literals)) { if (!empty($literals)) {
$this->_setLiterals($smarty, (array)$literals); $this->_setLiterals($smarty, (array)$literals);
@@ -330,7 +330,7 @@ abstract class TemplateBase extends Data {
* *
*/ */
public function registerClass($class_name, $class_impl) { public function registerClass($class_name, $class_impl) {
$smarty = $this->_getSmartyObj(); $smarty = $this->getSmarty();
// test if exists // test if exists
if (!class_exists($class_impl)) { if (!class_exists($class_impl)) {
throw new Exception("Undefined class '$class_impl' in register template class"); throw new Exception("Undefined class '$class_impl' in register template class");
@@ -351,7 +351,7 @@ abstract class TemplateBase extends Data {
* *
*/ */
public function registerDefaultConfigHandler($callback) { public function registerDefaultConfigHandler($callback) {
$smarty = $this->_getSmartyObj(); $smarty = $this->getSmarty();
if (is_callable($callback)) { if (is_callable($callback)) {
$smarty->default_config_handler_func = $callback; $smarty->default_config_handler_func = $callback;
} else { } else {
@@ -371,7 +371,7 @@ abstract class TemplateBase extends Data {
* *
*/ */
public function registerDefaultTemplateHandler($callback) { public function registerDefaultTemplateHandler($callback) {
$smarty = $this->_getSmartyObj(); $smarty = $this->getSmarty();
if (is_callable($callback)) { if (is_callable($callback)) {
$smarty->default_template_handler_func = $callback; $smarty->default_template_handler_func = $callback;
} else { } else {
@@ -392,7 +392,7 @@ abstract class TemplateBase extends Data {
* @api Smarty::registerResource() * @api Smarty::registerResource()
*/ */
public function registerResource($name, \Smarty\Resource\BasePlugin $resource_handler) { public function registerResource($name, \Smarty\Resource\BasePlugin $resource_handler) {
$smarty = $this->_getSmartyObj(); $smarty = $this->getSmarty();
$smarty->registered_resources[$name] = $resource_handler; $smarty->registered_resources[$name] = $resource_handler;
return $this; return $this;
} }
@@ -408,7 +408,7 @@ abstract class TemplateBase extends Data {
* *
*/ */
public function unregisterResource($type) { public function unregisterResource($type) {
$smarty = $this->_getSmartyObj(); $smarty = $this->getSmarty();
if (isset($smarty->registered_resources[$type])) { if (isset($smarty->registered_resources[$type])) {
unset($smarty->registered_resources[$type]); unset($smarty->registered_resources[$type]);
} }
@@ -426,7 +426,7 @@ abstract class TemplateBase extends Data {
* *
*/ */
public function setDebugTemplate($tpl_name) { public function setDebugTemplate($tpl_name) {
$smarty = $this->_getSmartyObj(); $smarty = $this->getSmarty();
if (!is_readable($tpl_name)) { if (!is_readable($tpl_name)) {
throw new Exception("Unknown file '{$tpl_name}'"); throw new Exception("Unknown file '{$tpl_name}'");
} }

View File

@@ -256,7 +256,7 @@ KEY `name` (`name`)
*/ */
public function cleanCompileDir() public function cleanCompileDir()
{ {
$smarty = $this->getSmartyObj(); $smarty = $this->getSmarty();
if (isset($smarty)) { if (isset($smarty)) {
$dir = $smarty->getCompileDir(); $dir = $smarty->getCompileDir();
$this->cleanDir($dir); $this->cleanDir($dir);
@@ -269,7 +269,7 @@ KEY `name` (`name`)
*/ */
public function cleanCacheDir() public function cleanCacheDir()
{ {
$smarty = $this->getSmartyObj(); $smarty = $this->getSmarty();
if (isset($smarty)) { if (isset($smarty)) {
$dir = $smarty->getCacheDir(); $dir = $smarty->getCacheDir();
$this->cleanDir($dir); $this->cleanDir($dir);
@@ -356,8 +356,8 @@ KEY `name` (`name`)
*/ */
public function buildSourcePath($tpl, $name = null, $type = null, $dir = null) public function buildSourcePath($tpl, $name = null, $type = null, $dir = null)
{ {
$name = isset($name) ? $name : $tpl->source->name; $name = isset($name) ? $name : $tpl->getSource()->name;
$type = isset($type) ? $type : $tpl->source->type; $type = isset($type) ? $type : $tpl->getSource()->type;
$dir = isset($dir) ? $dir : $this->smarty->getTemplateDir(0); $dir = isset($dir) ? $dir : $this->smarty->getTemplateDir(0);
switch ($type) { switch ($type) {
case 'file': case 'file':
@@ -388,8 +388,8 @@ KEY `name` (`name`)
*/ */
public function buildUid($tpl, $value = null, $name = null, $type = null) public function buildUid($tpl, $value = null, $name = null, $type = null)
{ {
$type = isset($type) ? $type : $tpl->source->type; $type = isset($type) ? $type : $tpl->getSource()->type;
$name = isset($name) ? $name : $tpl->source->name; $name = isset($name) ? $name : $tpl->getSource()->name;
switch ($type) { switch ($type) {
case 'php': case 'php':
case 'file': case 'file':
@@ -398,7 +398,7 @@ KEY `name` (`name`)
return sha1($this->normalizePath($this->smarty->getTemplateDir(0) . $name) . return sha1($this->normalizePath($this->smarty->getTemplateDir(0) . $name) .
$this->smarty->_joined_template_dir); $this->smarty->_joined_template_dir);
} }
return sha1($tpl->source->filepath . $this->smarty->_joined_template_dir); return sha1($tpl->getSource()->filepath . $this->smarty->_joined_template_dir);
case 'mysqltest': case 'mysqltest':
case 'mysql': case 'mysql':
return sha1($type . ':' . $name); return sha1($type . ':' . $name);
@@ -459,8 +459,8 @@ KEY `name` (`name`)
*/ */
public function getBasename(Template $tpl, $name = null, $type = null) public function getBasename(Template $tpl, $name = null, $type = null)
{ {
$name = isset($name) ? $name : $tpl->source->name; $name = isset($name) ? $name : $tpl->getSource()->name;
$type = isset($type) ? $type : $tpl->source->type; $type = isset($type) ? $type : $tpl->getSource()->type;
switch ($type) { switch ($type) {
case 'file': case 'file':
case 'filetest': case 'filetest':
@@ -500,11 +500,11 @@ KEY `name` (`name`)
$sp = $this->buildSourcePath($tpl, $name, $type, $dir); $sp = $this->buildSourcePath($tpl, $name, $type, $dir);
$uid = $this->buildUid($tpl, $sp, $name, $type); $uid = $this->buildUid($tpl, $sp, $name, $type);
$_flag = ''; $_flag = '';
if (isset($tpl->source) && $tpl->source->isConfig) { if ($tpl->getSource() && $tpl->getSource()->isConfig) {
$_flag = '_' . ((int) $tpl->smarty->config_read_hidden + (int) $tpl->smarty->config_booleanize * 2 + $_flag = '_' . ((int) $tpl->getSmarty()->config_read_hidden + (int) $tpl->getSmarty()->config_booleanize * 2 +
(int) $tpl->smarty->config_overwrite * 4); (int) $tpl->getSmarty()->config_overwrite * 4);
} else { } else {
$_flag = '_' . ((int) $tpl->smarty->merge_compiled_includes + (int) $tpl->smarty->escape_html * 2); $_flag = '_' . ((int) $tpl->getSmarty()->merge_compiled_includes + (int) $tpl->getSmarty()->escape_html * 2);
} }
$_filepath = $uid . $_flag; $_filepath = $uid . $_flag;
// if use_sub_dirs, break file into directories // if use_sub_dirs, break file into directories
@@ -523,7 +523,7 @@ KEY `name` (`name`)
} else { } else {
$_cache = ''; $_cache = '';
} }
$_compile_dir = $tpl->smarty->getCompileDir(); $_compile_dir = $tpl->getSmarty()->getCompileDir();
// set basename if not specified // set basename if not specified
$_basename = $this->getBasename($tpl, $name, $type); $_basename = $this->getBasename($tpl, $name, $type);
if ($_basename === null) { if ($_basename === null) {
@@ -552,10 +552,10 @@ KEY `name` (`name`)
* @return string * @return string
* @throws \Exception * @throws \Exception
*/ */
public function buildCachedPath($tpl, $sub = true, $cache_id = null, $compile_id = null, $name = null, $type = null, public function buildCachedPath(TemplateBase $tpl, $sub = true, $cache_id = null, $compile_id = null, $name = null, $type = null,
$dir = null, $cacheType = null) $dir = null, $cacheType = null)
{ {
$cacheType = $cacheType ?? $tpl->smarty->getCachingType(); $cacheType = $cacheType ?? $tpl->getSmarty()->getCachingType();
switch ($cacheType) { switch ($cacheType) {
case 'file': case 'file':
case 'filetest': case 'filetest':
@@ -582,9 +582,7 @@ KEY `name` (`name`)
} else { } else {
$_compile_id = ''; $_compile_id = '';
} }
$smarty = isset($tpl->smarty) ? $tpl->smarty : $tpl; return $tpl->getSmarty()->getCacheDir() . $_cache_id . $_compile_id . $_filepath . '.' . basename($sp) . '.php';
$_cache_dir = $smarty->getCacheDir();
return $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($sp) . '.php';
case 'mysqltest': case 'mysqltest':
case 'pdo': case 'pdo':
case 'foobar': case 'foobar':
@@ -625,7 +623,7 @@ KEY `name` (`name`)
* Gat Smarty object * Gat Smarty object
* @return null|\Smarty * @return null|\Smarty
*/ */
public function getSmartyObj(){ public function getSmarty(){
return $this->smarty; return $this->smarty;
} }
@@ -636,18 +634,4 @@ KEY `name` (`name`)
return __DIR__ . '/../libs/plugins'; return __DIR__ . '/../libs/plugins';
} }
} }
/**
* Tears down the fixture
* This method is called after a test is executed.
*
*/
protected function tearDown(): void
{
if (isset($this->smarty->smarty)) {
$this->smarty->smarty = null;
}
if (isset($this->smarty)) {
$this->smarty = null;
}
}
} }

View File

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

View File

@@ -91,7 +91,7 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$this->smarty->cache_lifetime = 1000; $this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar'); $tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar');
$tpl->writeCachedContent('hello world'); $tpl->writeCachedContent('hello world');
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl));
// Custom CacheResources may return -1 if they can't tell the number of deleted elements // Custom CacheResources may return -1 if they can't tell the number of deleted elements
//$this->assertEquals(-1, $this->smarty->clearAllCache()); //$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 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$tpl3->writeCachedContent('hello world 3'); $tpl3->writeCachedContent('hello world 3');
// test cached content // test cached content
$this->assertEquals('hello world 1', $tpl->getCached()->handler->getCachedContent($tpl)); $this->assertEquals('hello world 1', $tpl->getCachedContent($tpl));
$this->assertEquals('hello world 2', $tpl->getCached()->handler->getCachedContent($tpl2)); $this->assertEquals('hello world 2', $tpl2->getCachedContent($tpl2));
$this->assertEquals('hello world 3', $tpl->getCached()->handler->getCachedContent($tpl3)); $this->assertEquals('hello world 3', $tpl3->getCachedContent($tpl3));
// test number of deleted caches // test number of deleted caches
$this->doClearCacheAssertion(2, $this->smarty->clearCache(null, 'foo|bar')); $this->doClearCacheAssertion(2, $this->smarty->clearCache(null, 'foo|bar'));
// test that caches are deleted properly // test that caches are deleted properly
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl)); $this->assertNull($tpl->getCachedContent($tpl));
$this->assertEquals('hello world 2', $tpl->getCached()->handler->getCachedContent($tpl2)); $this->assertEquals('hello world 2', $tpl->getCachedContent($tpl2));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl3)); $this->assertNull($tpl->getCachedContent($tpl3));
} }
public function testClearCacheCacheIdCompileId2() public function testClearCacheCacheIdCompileId2()
@@ -136,15 +136,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$tpl3->writeCachedContent('hello world'); $tpl3->writeCachedContent('hello world');
// test cached content // test cached content
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl3));
// test number of deleted caches // test number of deleted caches
$this->doClearCacheAssertion(2, $this->smarty->clearCache('helloworld.tpl')); $this->doClearCacheAssertion(2, $this->smarty->clearCache('helloworld.tpl'));
// test that caches are deleted properly // test that caches are deleted properly
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl)); $this->assertNull($tpl->getCachedContent($tpl));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl2)); $this->assertNull($tpl->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl3));
} }
public function testClearCacheCacheIdCompileId2Sub() public function testClearCacheCacheIdCompileId2Sub()
@@ -160,15 +160,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$tpl3->writeCachedContent('hello world'); $tpl3->writeCachedContent('hello world');
// test cached content // test cached content
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl3));
// test number of deleted caches // test number of deleted caches
$this->doClearCacheAssertion(2, $this->smarty->clearCache('helloworld.tpl')); $this->doClearCacheAssertion(2, $this->smarty->clearCache('helloworld.tpl'));
// test that caches are deleted properly // test that caches are deleted properly
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl)); $this->assertNull($tpl->getCachedContent($tpl));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl2)); $this->assertNull($tpl->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl3));
} }
public function testClearCacheCacheIdCompileId3() public function testClearCacheCacheIdCompileId3()
@@ -184,15 +184,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$tpl3->writeCachedContent('hello world'); $tpl3->writeCachedContent('hello world');
// test cached content // test cached content
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl3));
// test number of deleted caches // test number of deleted caches
$this->doClearCacheAssertion(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2')); $this->doClearCacheAssertion(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2'));
// test that caches are deleted properly // test that caches are deleted properly
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl2)); $this->assertNull($tpl->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl3));
} }
public function testClearCacheCacheIdCompileId3Sub() public function testClearCacheCacheIdCompileId3Sub()
@@ -208,15 +208,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$tpl3->writeCachedContent('hello world'); $tpl3->writeCachedContent('hello world');
// test cached content // test cached content
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl3));
// test number of deleted caches // test number of deleted caches
$this->doClearCacheAssertion(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2')); $this->doClearCacheAssertion(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2'));
// test that caches are deleted properly // test that caches are deleted properly
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl2)); $this->assertNull($tpl->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl3));
} }
public function testClearCacheCacheIdCompileId4() public function testClearCacheCacheIdCompileId4()
@@ -232,15 +232,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$tpl3->writeCachedContent('hello world'); $tpl3->writeCachedContent('hello world');
// test cached content // test cached content
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl3));
// test number of deleted caches // test number of deleted caches
$this->doClearCacheAssertion(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2')); $this->doClearCacheAssertion(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2'));
// test that caches are deleted properly // test that caches are deleted properly
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl2)); $this->assertNull($tpl->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl3));
} }
public function testClearCacheCacheIdCompileId4Sub() public function testClearCacheCacheIdCompileId4Sub()
@@ -256,15 +256,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$tpl3->writeCachedContent('hello world'); $tpl3->writeCachedContent('hello world');
// test cached content // test cached content
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl3));
// test number of deleted caches // test number of deleted caches
$this->doClearCacheAssertion(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2')); $this->doClearCacheAssertion(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2'));
// test that caches are deleted properly // test that caches are deleted properly
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl2)); $this->assertNull($tpl->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl3));
} }
public function testClearCacheCacheIdCompileId5() public function testClearCacheCacheIdCompileId5()
@@ -280,15 +280,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$tpl3->writeCachedContent('hello world'); $tpl3->writeCachedContent('hello world');
// test cached content // test cached content
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl3));
// test number of deleted caches // test number of deleted caches
$this->doClearCacheAssertion(2, $this->smarty->clearCache(null, null, 'blar')); $this->doClearCacheAssertion(2, $this->smarty->clearCache(null, null, 'blar'));
// test that caches are deleted properly // test that caches are deleted properly
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl)); $this->assertNull($tpl->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl2));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl3)); $this->assertNull($tpl->getCachedContent($tpl3));
} }
public function testClearCacheCacheIdCompileId5Sub() public function testClearCacheCacheIdCompileId5Sub()
@@ -304,15 +304,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar');
$tpl3->writeCachedContent('hello world'); $tpl3->writeCachedContent('hello world');
// test cached content // test cached content
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl3));
// test number of deleted caches // test number of deleted caches
$this->doClearCacheAssertion(2, $this->smarty->clearCache(null, null, 'blar')); $this->doClearCacheAssertion(2, $this->smarty->clearCache(null, null, 'blar'));
// test that caches are deleted properly // test that caches are deleted properly
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl)); $this->assertNull($tpl->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl2));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl3)); $this->assertNull($tpl->getCachedContent($tpl3));
} }
public function testClearCacheCacheFile() public function testClearCacheCacheFile()
@@ -330,17 +330,17 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$tpl4 = $this->smarty->createTemplate('helloworld2.tpl'); $tpl4 = $this->smarty->createTemplate('helloworld2.tpl');
$tpl4->writeCachedContent('hello world'); $tpl4->writeCachedContent('hello world');
// test cached content // test cached content
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl4)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl4));
// test number of deleted caches // test number of deleted caches
$this->doClearCacheAssertion(3, $this->smarty->clearCache('helloworld.tpl')); $this->doClearCacheAssertion(3, $this->smarty->clearCache('helloworld.tpl'));
// test that caches are deleted properly // test that caches are deleted properly
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl)); $this->assertNull($tpl->getCachedContent($tpl));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl2)); $this->assertNull($tpl->getCachedContent($tpl2));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl3)); $this->assertNull($tpl->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl4)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl4));
} }
/** /**
@@ -359,19 +359,19 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$tpl3 = $this->smarty->createTemplate('helloworld.tpl', 'buh|blar'); $tpl3 = $this->smarty->createTemplate('helloworld.tpl', 'buh|blar');
$tpl3->writeCachedContent('hello world'); $tpl3->writeCachedContent('hello world');
// test cached content // test cached content
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl3));
sleep(10); sleep(10);
$tpl4 = $this->smarty->createTemplate('helloworld2.tpl'); $tpl4 = $this->smarty->createTemplate('helloworld2.tpl');
$tpl4->writeCachedContent('hello world'); $tpl4->writeCachedContent('hello world');
// test number of deleted caches // test number of deleted caches
$this->doClearCacheAssertion(3,$this->smarty->clearAllCache(5)); $this->doClearCacheAssertion(3,$this->smarty->clearAllCache(5));
// test that caches are deleted properly // test that caches are deleted properly
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl)); $this->assertNull($tpl->getCachedContent($tpl));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl2)); $this->assertNull($tpl->getCachedContent($tpl2));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl3)); $this->assertNull($tpl->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl4)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl4));
} }
public function testClearCacheCacheFileSub() public function testClearCacheCacheFileSub()
@@ -389,17 +389,17 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
$tpl4 = $this->smarty->createTemplate('helloworld2.tpl'); $tpl4 = $this->smarty->createTemplate('helloworld2.tpl');
$tpl4->writeCachedContent('hello world'); $tpl4->writeCachedContent('hello world');
// test cached content // test cached content
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl2));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl4)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl4));
// test number of deleted caches // test number of deleted caches
$this->doClearCacheAssertion(3, $this->smarty->clearCache('helloworld.tpl')); $this->doClearCacheAssertion(3, $this->smarty->clearCache('helloworld.tpl'));
// test that caches are deleted properly // test that caches are deleted properly
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl)); $this->assertNull($tpl->getCachedContent($tpl));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl2)); $this->assertNull($tpl->getCachedContent($tpl2));
$this->assertNull($tpl->getCached()->handler->getCachedContent($tpl3)); $this->assertNull($tpl->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl4)); $this->assertEquals('hello world', $tpl->getCachedContent($tpl4));
} }
/** /**
* Test caching * Test caching
@@ -427,7 +427,7 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty
} }
$tpl = $this->smarty->createTemplate('cacheresource.tpl', $this->smarty); $tpl = $this->smarty->createTemplate('cacheresource.tpl', $this->smarty);
if ($update) { if ($update) {
$this->assertEquals($t,$tpl->source->getTimeStamp(), $testName . ' - source touch'); $this->assertEquals($t,$tpl->getSource()->getTimeStamp(), $testName . ' - source touch');
} }
if ($lockTime) { if ($lockTime) {
$tpl->getCached()->handler->acquireLock($this->smarty, $tpl->getCached()); $tpl->getCached()->handler->acquireLock($this->smarty, $tpl->getCached());

View File

@@ -48,7 +48,7 @@ class CustomResourceAmbiguousTest extends PHPUnit_Smarty
$this->smarty->setAllowAmbiguousResources(true); $this->smarty->setAllowAmbiguousResources(true);
$tpl = $this->smarty->createTemplate('foobar.tpl'); $tpl = $this->smarty->createTemplate('foobar.tpl');
$this->assertFalse($tpl->source->exists); $this->assertFalse($tpl->getSource()->exists);
} }
public function testCase1() public function testCase1()
@@ -61,8 +61,8 @@ class CustomResourceAmbiguousTest extends PHPUnit_Smarty
$resource_handler->setSegment('case1'); $resource_handler->setSegment('case1');
$tpl = $this->smarty->createTemplate('foobar.tpl'); $tpl = $this->smarty->createTemplate('foobar.tpl');
$this->assertTrue($tpl->source->exists); $this->assertTrue($tpl->getSource()->exists);
$this->assertEquals('case1', $tpl->source->getContent()); $this->assertEquals('case1', $tpl->getSource()->getContent());
} }
public function testCase2() public function testCase2()
@@ -75,8 +75,8 @@ class CustomResourceAmbiguousTest extends PHPUnit_Smarty
$resource_handler->setSegment('case2'); $resource_handler->setSegment('case2');
$tpl = $this->smarty->createTemplate('foobar.tpl'); $tpl = $this->smarty->createTemplate('foobar.tpl');
$this->assertTrue($tpl->source->exists); $this->assertTrue($tpl->getSource()->exists);
$this->assertEquals('case2', $tpl->source->getContent()); $this->assertEquals('case2', $tpl->getSource()->getContent());
} }
@@ -89,12 +89,12 @@ class CustomResourceAmbiguousTest extends PHPUnit_Smarty
$resource_handler->setSegment('case1'); $resource_handler->setSegment('case1');
$tpl = $this->smarty->createTemplate('foobar.tpl'); $tpl = $this->smarty->createTemplate('foobar.tpl');
$this->assertTrue($tpl->source->exists); $this->assertTrue($tpl->getSource()->exists);
$this->assertEquals('case1', $tpl->source->getContent()); $this->assertEquals('case1', $tpl->getSource()->getContent());
$resource_handler->setSegment('case2'); $resource_handler->setSegment('case2');
$tpl = $this->smarty->createTemplate('foobar.tpl'); $tpl = $this->smarty->createTemplate('foobar.tpl');
$this->assertTrue($tpl->source->exists); $this->assertTrue($tpl->getSource()->exists);
$this->assertEquals('case2', $tpl->source->getContent()); $this->assertEquals('case2', $tpl->getSource()->getContent());
} }
} }

View File

@@ -42,7 +42,7 @@ class Smarty_Resource_AmbiguousPlugin extends FilePlugin
$source->filepath = $this->directory . $segment . $source->name; $source->filepath = $this->directory . $segment . $source->name;
$source->uid = sha1($source->filepath); $source->uid = sha1($source->filepath);
if ($_template->smarty->getCompileCheck() && !isset($source->timestamp)) { if ($_template->getSmarty()->getCompileCheck() && !isset($source->timestamp)) {
$source->timestamp = @filemtime($source->filepath); $source->timestamp = @filemtime($source->filepath);
$source->exists = !!$source->timestamp; $source->exists = !!$source->timestamp;
} }

View File

@@ -31,7 +31,7 @@ class EvalResourceTest extends PHPUnit_Smarty
public function testTemplateEvalExists1() public function testTemplateEvalExists1()
{ {
$tpl = $this->smarty->createTemplate('eval:{$foo}'); $tpl = $this->smarty->createTemplate('eval:{$foo}');
$this->assertTrue($tpl->source->exists); $this->assertTrue($tpl->getSource()->exists);
} }
public function testTemplateEvalExists2() public function testTemplateEvalExists2()
@@ -45,7 +45,7 @@ class EvalResourceTest extends PHPUnit_Smarty
public function testGetTemplateFilepath() public function testGetTemplateFilepath()
{ {
$tpl = $this->smarty->createTemplate('eval:hello world'); $tpl = $this->smarty->createTemplate('eval:hello world');
$this->assertEquals('2aae6c35c94fcfb415dbe95f408b9ce91ee846ed', $tpl->source->filepath); $this->assertEquals('2aae6c35c94fcfb415dbe95f408b9ce91ee846ed', $tpl->getSource()->filepath);
} }
/** /**
@@ -54,7 +54,7 @@ class EvalResourceTest extends PHPUnit_Smarty
public function testGetTemplateTimestamp() public function testGetTemplateTimestamp()
{ {
$tpl = $this->smarty->createTemplate('eval:hello world'); $tpl = $this->smarty->createTemplate('eval:hello world');
$this->assertTrue($tpl->source->getTimeStamp()); $this->assertTrue($tpl->getSource()->getTimeStamp());
} }
/** /**
@@ -63,7 +63,7 @@ class EvalResourceTest extends PHPUnit_Smarty
public function testGetTemplateSource() public function testGetTemplateSource()
{ {
$tpl = $this->smarty->createTemplate('eval:hello world{$foo}'); $tpl = $this->smarty->createTemplate('eval:hello world{$foo}');
$this->assertEquals('hello world{$foo}', $tpl->source->getContent()); $this->assertEquals('hello world{$foo}', $tpl->getSource()->getContent());
} }
/** /**
@@ -90,7 +90,7 @@ class EvalResourceTest extends PHPUnit_Smarty
public function testIsEvaluated() public function testIsEvaluated()
{ {
$tpl = $this->smarty->createTemplate('eval:hello world'); $tpl = $this->smarty->createTemplate('eval:hello world');
$this->assertTrue($tpl->source->handler->recompiled); $this->assertTrue($tpl->getSource()->handler->recompiled);
} }
/** /**

View File

@@ -41,13 +41,13 @@ class FileResourceTest extends PHPUnit_Smarty
public function testGetTemplateFilepath() public function testGetTemplateFilepath()
{ {
$tpl = $this->smarty->createTemplate('helloworld.tpl'); $tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertEquals($this->normalizePath("./templates/helloworld.tpl"), $tpl->source->filepath); $this->assertEquals($this->normalizePath("./templates/helloworld.tpl"), $tpl->getSource()->filepath);
} }
public function testTemplateFileExists1() public function testTemplateFileExists1()
{ {
$tpl = $this->smarty->createTemplate('helloworld.tpl'); $tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertTrue($tpl->source->exists); $this->assertTrue($tpl->getSource()->exists);
} }
public function testTemplateFileExists2() public function testTemplateFileExists2()
@@ -58,7 +58,7 @@ class FileResourceTest extends PHPUnit_Smarty
public function testTemplateFileNotExists1() public function testTemplateFileNotExists1()
{ {
$tpl = $this->smarty->createTemplate('notthere.tpl'); $tpl = $this->smarty->createTemplate('notthere.tpl');
$this->assertFalse($tpl->source->exists); $this->assertFalse($tpl->getSource()->exists);
} }
public function testTemplateFileNotExists2() public function testTemplateFileNotExists2()
@@ -80,14 +80,14 @@ class FileResourceTest extends PHPUnit_Smarty
public function testGetTemplateTimestamp() public function testGetTemplateTimestamp()
{ {
$tpl = $this->smarty->createTemplate('helloworld.tpl'); $tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertTrue(is_integer($tpl->source->getTimeStamp())); $this->assertTrue(is_integer($tpl->getSource()->getTimeStamp()));
$this->assertEquals(10, strlen($tpl->source->getTimeStamp())); $this->assertEquals(10, strlen($tpl->getSource()->getTimeStamp()));
} }
public function testGetTemplateSource() public function testGetTemplateSource()
{ {
$tpl = $this->smarty->createTemplate('helloworld.tpl'); $tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertEquals('hello world', $tpl->source->getContent()); $this->assertEquals('hello world', $tpl->getSource()->getContent());
} }
public function testUsesCompiler() public function testUsesCompiler()
@@ -99,7 +99,7 @@ class FileResourceTest extends PHPUnit_Smarty
public function testIsEvaluated() public function testIsEvaluated()
{ {
$tpl = $this->smarty->createTemplate('helloworld.tpl'); $tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertFalse($tpl->source->handler->recompiled); $this->assertFalse($tpl->getSource()->handler->recompiled);
} }
public function testGetCompiledFilepath() public function testGetCompiledFilepath()
@@ -118,7 +118,7 @@ class FileResourceTest extends PHPUnit_Smarty
$tpl = $this->smarty->createTemplate('helloworld.tpl'); $tpl = $this->smarty->createTemplate('helloworld.tpl');
// create dummy compiled file // create dummy compiled file
file_put_contents($tpl->getCompiled()->filepath, '<?php ?>'); file_put_contents($tpl->getCompiled()->filepath, '<?php ?>');
touch($tpl->getCompiled()->filepath, $tpl->source->getTimeStamp()); touch($tpl->getCompiled()->filepath, $tpl->getSource()->getTimeStamp());
} }
/** /**
@@ -129,7 +129,7 @@ class FileResourceTest extends PHPUnit_Smarty
$tpl = $this->smarty->createTemplate('helloworld.tpl'); $tpl = $this->smarty->createTemplate('helloworld.tpl');
$this->assertTrue(is_integer($tpl->getCompiled()->getTimeStamp())); $this->assertTrue(is_integer($tpl->getCompiled()->getTimeStamp()));
$this->assertEquals(10, strlen($tpl->getCompiled()->getTimeStamp())); $this->assertEquals(10, strlen($tpl->getCompiled()->getTimeStamp()));
$this->assertEquals($tpl->getCompiled()->getTimeStamp(), $tpl->source->getTimeStamp()); $this->assertEquals($tpl->getCompiled()->getTimeStamp(), $tpl->getSource()->getTimeStamp());
} }
public function testMustCompileExisting() public function testMustCompileExisting()
@@ -153,7 +153,7 @@ class FileResourceTest extends PHPUnit_Smarty
// touch to prepare next test // touch to prepare next test
sleep(2); sleep(2);
$tpl = $this->smarty->createTemplate('helloworld.tpl'); $tpl = $this->smarty->createTemplate('helloworld.tpl');
touch($tpl->source->filepath); touch($tpl->getSource()->filepath);
$this->setUp(); $this->setUp();

View File

@@ -28,25 +28,25 @@ class FileResourceIndexedTest extends PHPUnit_Smarty
public function testGetTemplateFilepath() public function testGetTemplateFilepath()
{ {
$tpl = $this->smarty->createTemplate('dirname.tpl'); $tpl = $this->smarty->createTemplate('dirname.tpl');
$this->assertEquals($this->normalizePath("./templates/dirname.tpl"), $tpl->source->filepath); $this->assertEquals($this->normalizePath("./templates/dirname.tpl"), $tpl->getSource()->filepath);
} }
public function testGetTemplateFilepathNumber() public function testGetTemplateFilepathNumber()
{ {
$tpl = $this->smarty->createTemplate('[1]dirname.tpl'); $tpl = $this->smarty->createTemplate('[1]dirname.tpl');
$this->assertEquals($this->normalizePath('./templates_2/dirname.tpl'), $tpl->source->filepath); $this->assertEquals($this->normalizePath('./templates_2/dirname.tpl'), $tpl->getSource()->filepath);
} }
public function testGetTemplateFilepathNumeric() public function testGetTemplateFilepathNumeric()
{ {
$tpl = $this->smarty->createTemplate('[10]dirname.tpl'); $tpl = $this->smarty->createTemplate('[10]dirname.tpl');
$this->assertEquals($this->normalizePath('./templates_3/dirname.tpl'), $tpl->source->filepath); $this->assertEquals($this->normalizePath('./templates_3/dirname.tpl'), $tpl->getSource()->filepath);
} }
public function testGetTemplateFilepathName() public function testGetTemplateFilepathName()
{ {
$tpl = $this->smarty->createTemplate('[foo]dirname.tpl'); $tpl = $this->smarty->createTemplate('[foo]dirname.tpl');
$this->assertEquals($this->normalizePath('./templates_4/dirname.tpl'), $tpl->source->filepath); $this->assertEquals($this->normalizePath('./templates_4/dirname.tpl'), $tpl->getSource()->filepath);
} }
public function testFetch() public function testFetch()

View File

@@ -49,8 +49,8 @@ class RegisteredResourceTest extends PHPUnit_Smarty
public function testResourcePluginTimestamp() public function testResourcePluginTimestamp()
{ {
$tpl = $this->smarty->createTemplate('rr:test'); $tpl = $this->smarty->createTemplate('rr:test');
$this->assertTrue(is_integer($tpl->source->getTimeStamp())); $this->assertTrue(is_integer($tpl->getSource()->getTimeStamp()));
$this->assertEquals(10, strlen($tpl->source->getTimeStamp())); $this->assertEquals(10, strlen($tpl->getSource()->getTimeStamp()));
} }
/** /**

View File

@@ -72,8 +72,8 @@ class ResourcePluginTest extends PHPUnit_Smarty
{ {
$this->smarty->addPluginsDir("./PHPunitplugins/"); $this->smarty->addPluginsDir("./PHPunitplugins/");
$tpl = $this->smarty->createTemplate('db:test'); $tpl = $this->smarty->createTemplate('db:test');
$this->assertTrue(is_integer($tpl->source->getTimeStamp())); $this->assertTrue(is_integer($tpl->getSource()->getTimeStamp()));
$this->assertEquals(10, strlen($tpl->source->getTimeStamp())); $this->assertEquals(10, strlen($tpl->getSource()->getTimeStamp()));
} }
} }

View File

@@ -43,7 +43,7 @@ class StreamResourceTest extends PHPUnit_Smarty
public function testGetTemplateFilepath() public function testGetTemplateFilepath()
{ {
$tpl = $this->smarty->createTemplate('global:mytest'); $tpl = $this->smarty->createTemplate('global:mytest');
$this->assertEquals('global://mytest', $tpl->source->filepath); $this->assertEquals('global://mytest', $tpl->getSource()->filepath);
} }
/** /**
@@ -52,7 +52,7 @@ class StreamResourceTest extends PHPUnit_Smarty
public function testGetTemplateTimestamp() public function testGetTemplateTimestamp()
{ {
$tpl = $this->smarty->createTemplate('global:mytest'); $tpl = $this->smarty->createTemplate('global:mytest');
$this->assertTrue($tpl->source->getTimeStamp()); $this->assertTrue($tpl->getSource()->getTimeStamp());
} }
/** /**
@@ -61,7 +61,7 @@ class StreamResourceTest extends PHPUnit_Smarty
public function testGetTemplateSource() public function testGetTemplateSource()
{ {
$tpl = $this->smarty->createTemplate('global:mytest', null, null, $this->smarty); $tpl = $this->smarty->createTemplate('global:mytest', null, null, $this->smarty);
$this->assertEquals('hello world {$foo}', $tpl->source->getContent()); $this->assertEquals('hello world {$foo}', $tpl->getSource()->getContent());
} }
/** /**
@@ -79,7 +79,7 @@ class StreamResourceTest extends PHPUnit_Smarty
public function testIsEvaluated() public function testIsEvaluated()
{ {
$tpl = $this->smarty->createTemplate('global:mytest'); $tpl = $this->smarty->createTemplate('global:mytest');
$this->assertTrue($tpl->source->handler->recompiled); $this->assertTrue($tpl->getSource()->handler->recompiled);
} }
/** /**
@@ -115,7 +115,7 @@ class StreamResourceTest extends PHPUnit_Smarty
public function testTemplateStreamExists1() public function testTemplateStreamExists1()
{ {
$tpl = $this->smarty->createTemplate('global:mytest'); $tpl = $this->smarty->createTemplate('global:mytest');
$this->assertTrue($tpl->source->exists); $this->assertTrue($tpl->getSource()->exists);
} }
public function testTemplateStreamExists2() public function testTemplateStreamExists2()
@@ -129,7 +129,7 @@ class StreamResourceTest extends PHPUnit_Smarty
public function testTemplateStreamNotExists1() public function testTemplateStreamNotExists1()
{ {
$tpl = $this->smarty->createTemplate('global:notthere'); $tpl = $this->smarty->createTemplate('global:notthere');
$this->assertFalse($tpl->source->exists); $this->assertFalse($tpl->getSource()->exists);
} }
public function testTemplateStramNotExists2() public function testTemplateStramNotExists2()

View File

@@ -42,7 +42,7 @@ class StringResourceTest extends PHPUnit_Smarty
public function testTemplateStringExists1() public function testTemplateStringExists1()
{ {
$tpl = $this->smarty->createTemplate('string:{$foo}'); $tpl = $this->smarty->createTemplate('string:{$foo}');
$this->assertTrue($tpl->source->exists); $this->assertTrue($tpl->getSource()->exists);
} }
public function testTemplateStringExists2() public function testTemplateStringExists2()
@@ -56,7 +56,7 @@ class StringResourceTest extends PHPUnit_Smarty
public function testGetTemplateFilepath() public function testGetTemplateFilepath()
{ {
$tpl = $this->smarty->createTemplate('string:hello world'); $tpl = $this->smarty->createTemplate('string:hello world');
$this->assertEquals($this->buildSourcePath($tpl), $tpl->source->filepath); $this->assertEquals($this->buildSourcePath($tpl), $tpl->getSource()->filepath);
} }
/** /**
@@ -65,7 +65,7 @@ class StringResourceTest extends PHPUnit_Smarty
public function testGetTemplateTimestamp() public function testGetTemplateTimestamp()
{ {
$tpl = $this->smarty->createTemplate('string:hello world'); $tpl = $this->smarty->createTemplate('string:hello world');
$this->assertTrue($tpl->source->getTimeStamp()); $this->assertTrue($tpl->getSource()->getTimeStamp());
} }
/** /**
@@ -74,7 +74,7 @@ class StringResourceTest extends PHPUnit_Smarty
public function testGetTemplateSource() public function testGetTemplateSource()
{ {
$tpl = $this->smarty->createTemplate('string:hello world{$foo}'); $tpl = $this->smarty->createTemplate('string:hello world{$foo}');
$this->assertEquals('hello world{$foo}', $tpl->source->getContent()); $this->assertEquals('hello world{$foo}', $tpl->getSource()->getContent());
} }
/** /**
@@ -92,7 +92,7 @@ class StringResourceTest extends PHPUnit_Smarty
public function testIsEvaluated() public function testIsEvaluated()
{ {
$tpl = $this->smarty->createTemplate('string:hello world'); $tpl = $this->smarty->createTemplate('string:hello world');
$this->assertFalse($tpl->source->handler->recompiled); $this->assertFalse($tpl->getSource()->handler->recompiled);
} }
/** /**

View File

@@ -279,7 +279,7 @@ class SecurityTest extends PHPUnit_Smarty
fclose($fp); fclose($fp);
$this->smarty->security_policy->streams= array('global'); $this->smarty->security_policy->streams= array('global');
$tpl = $this->smarty->createTemplate('global:mytest'); $tpl = $this->smarty->createTemplate('global:mytest');
$this->assertTrue($tpl->source->exists); $this->assertTrue($tpl->getSource()->exists);
stream_wrapper_unregister("global"); stream_wrapper_unregister("global");
} }
/** /**
@@ -298,7 +298,7 @@ class SecurityTest extends PHPUnit_Smarty
fclose($fp); fclose($fp);
$this->smarty->security_policy->streams= array('notrusted'); $this->smarty->security_policy->streams= array('notrusted');
$tpl = $this->smarty->createTemplate('global:mytest'); $tpl = $this->smarty->createTemplate('global:mytest');
$this->assertTrue($tpl->source->exists); $this->assertTrue($tpl->getSource()->exists);
stream_wrapper_unregister("global"); stream_wrapper_unregister("global");
} }
/** /**

View File

@@ -56,7 +56,7 @@ class ClearCompiledTest extends PHPUnit_Smarty
protected function makeFiles() protected function makeFiles()
{ {
$this->_files = array(); $this->_files = array();
$directory_length = strlen($this->getSmartyObj()->getCompileDir()); $directory_length = strlen($this->getSmarty()->getCompileDir());
$templates = array( $templates = array(
'helloworld.tpl' => array(null, 'compile1', 'compile2'), 'helloworld.tpl' => array(null, 'compile1', 'compile2'),
'helloworld2.tpl' => array(null, 'compile1', 'compile2'), 'helloworld2.tpl' => array(null, 'compile1', 'compile2'),
@@ -66,7 +66,7 @@ class ClearCompiledTest extends PHPUnit_Smarty
foreach ($templates as $template => $compile_ids) { foreach ($templates as $template => $compile_ids) {
foreach ($compile_ids as $compile_id) { foreach ($compile_ids as $compile_id) {
$tpl = $this->getSmartyObj()->createTemplate($template, null, $compile_id); $tpl = $this->getSmarty()->createTemplate($template, null, $compile_id);
$tpl->fetch(); $tpl->fetch();
$this->_files[$template . '#' . $compile_id] = substr($tpl->getCompiled()->filepath, $directory_length); $this->_files[$template . '#' . $compile_id] = substr($tpl->getCompiled()->filepath, $directory_length);
} }
@@ -105,7 +105,7 @@ class ClearCompiledTest extends PHPUnit_Smarty
*/ */
protected function touchFiles($keys, $offset = 0) protected function touchFiles($keys, $offset = 0)
{ {
$base = $this->getSmartyObj()->getCompileDir(); $base = $this->getSmarty()->getCompileDir();
$time = time(); $time = time();
foreach ($keys as $key) { foreach ($keys as $key) {
if (isset($this->_files[$key])) { if (isset($this->_files[$key])) {
@@ -123,7 +123,7 @@ class ClearCompiledTest extends PHPUnit_Smarty
*/ */
protected function getFiles() protected function getFiles()
{ {
$directory = realpath($this->getSmartyObj()->getCompileDir()); $directory = realpath($this->getSmarty()->getCompileDir());
if (!$directory) { if (!$directory) {
return array(); return array();
} }
@@ -160,12 +160,12 @@ class ClearCompiledTest extends PHPUnit_Smarty
public function runClearAll($useSubDirs) public function runClearAll($useSubDirs)
{ {
$this->getSmartyObj()->setUseSubDirs($useSubDirs); $this->getSmarty()->setUseSubDirs($useSubDirs);
$this->clearFiles(); $this->clearFiles();
$this->makeFiles(); $this->makeFiles();
$expected = array(); $expected = array();
$this->assertEquals(12, $this->getSmartyObj()->{$this->methodName}()); $this->assertEquals(12, $this->getSmarty()->{$this->methodName}());
$this->assertEquals($this->expectFiles($expected), $this->getFiles()); $this->assertEquals($this->expectFiles($expected), $this->getFiles());
$this->clearFiles(); $this->clearFiles();
@@ -194,7 +194,7 @@ class ClearCompiledTest extends PHPUnit_Smarty
public function runClearTemplate($useSubDirs) public function runClearTemplate($useSubDirs)
{ {
$this->getSmartyObj()->setUseSubDirs($useSubDirs); $this->getSmarty()->setUseSubDirs($useSubDirs);
$this->clearFiles(); $this->clearFiles();
$this->makeFiles(); $this->makeFiles();
@@ -203,7 +203,7 @@ class ClearCompiledTest extends PHPUnit_Smarty
'ambiguous/case1/foobar.tpl#', 'ambiguous/case1/foobar.tpl#compile1', 'ambiguous/case1/foobar.tpl#compile2', 'ambiguous/case1/foobar.tpl#', 'ambiguous/case1/foobar.tpl#compile1', 'ambiguous/case1/foobar.tpl#compile2',
'[1]ambiguous/case1/foobar.tpl#', '[1]ambiguous/case1/foobar.tpl#compile1', '[1]ambiguous/case1/foobar.tpl#compile2', '[1]ambiguous/case1/foobar.tpl#', '[1]ambiguous/case1/foobar.tpl#compile1', '[1]ambiguous/case1/foobar.tpl#compile2',
); );
$this->assertEquals(3, $this->getSmartyObj()->{$this->methodName}('helloworld.tpl')); $this->assertEquals(3, $this->getSmarty()->{$this->methodName}('helloworld.tpl'));
$this->assertEquals($this->expectFiles($expected), $this->getFiles()); $this->assertEquals($this->expectFiles($expected), $this->getFiles());
$this->clearFiles(); $this->clearFiles();
@@ -211,12 +211,12 @@ class ClearCompiledTest extends PHPUnit_Smarty
public function runClearOtherTemplate($useSubDirs) public function runClearOtherTemplate($useSubDirs)
{ {
$this->getSmartyObj()->setUseSubDirs($useSubDirs); $this->getSmarty()->setUseSubDirs($useSubDirs);
$this->clearFiles(); $this->clearFiles();
$this->makeFiles(); $this->makeFiles();
$expected = array_keys($this->_files); $expected = array_keys($this->_files);
$this->assertEquals(0, $this->getSmartyObj()->{$this->methodName}('foobar.tpl')); $this->assertEquals(0, $this->getSmarty()->{$this->methodName}('foobar.tpl'));
$this->assertEquals($this->expectFiles($expected), $this->getFiles()); $this->assertEquals($this->expectFiles($expected), $this->getFiles());
$this->clearFiles(); $this->clearFiles();
@@ -245,7 +245,7 @@ class ClearCompiledTest extends PHPUnit_Smarty
public function runClearCompileid($useSubDirs) public function runClearCompileid($useSubDirs)
{ {
$this->getSmartyObj()->setUseSubDirs($useSubDirs); $this->getSmarty()->setUseSubDirs($useSubDirs);
$this->clearFiles(); $this->clearFiles();
$this->makeFiles(); $this->makeFiles();
@@ -255,7 +255,7 @@ class ClearCompiledTest extends PHPUnit_Smarty
'ambiguous/case1/foobar.tpl#', 'ambiguous/case1/foobar.tpl#compile2', 'ambiguous/case1/foobar.tpl#', 'ambiguous/case1/foobar.tpl#compile2',
'[1]ambiguous/case1/foobar.tpl#', '[1]ambiguous/case1/foobar.tpl#compile2', '[1]ambiguous/case1/foobar.tpl#', '[1]ambiguous/case1/foobar.tpl#compile2',
); );
$count = $this->getSmartyObj()->{$this->methodName}(null, 'compile1'); $count = $this->getSmarty()->{$this->methodName}(null, 'compile1');
$this->assertEquals(4, $count); $this->assertEquals(4, $count);
$this->assertEquals($this->expectFiles($expected), $this->getFiles()); $this->assertEquals($this->expectFiles($expected), $this->getFiles());
@@ -264,12 +264,12 @@ class ClearCompiledTest extends PHPUnit_Smarty
public function runClearOtherCompileid($useSubDirs) public function runClearOtherCompileid($useSubDirs)
{ {
$this->getSmartyObj()->setUseSubDirs($useSubDirs); $this->getSmarty()->setUseSubDirs($useSubDirs);
$this->clearFiles(); $this->clearFiles();
$this->makeFiles(); $this->makeFiles();
$expected = array_keys($this->_files); $expected = array_keys($this->_files);
$this->assertEquals(0, $this->getSmartyObj()->{$this->methodName}(null, 'other')); $this->assertEquals(0, $this->getSmarty()->{$this->methodName}(null, 'other'));
$this->assertEquals($this->expectFiles($expected), $this->getFiles()); $this->assertEquals($this->expectFiles($expected), $this->getFiles());
$this->clearFiles(); $this->clearFiles();
@@ -288,13 +288,13 @@ class ClearCompiledTest extends PHPUnit_Smarty
public function runClearExpired($useSubDirs) public function runClearExpired($useSubDirs)
{ {
$this->getSmartyObj()->setUseSubDirs($useSubDirs); $this->getSmarty()->setUseSubDirs($useSubDirs);
$this->clearFiles(); $this->clearFiles();
$this->makeFiles(); $this->makeFiles();
$expected = array('helloworld.tpl#', 'helloworld2.tpl#'); $expected = array('helloworld.tpl#', 'helloworld2.tpl#');
$this->touchFiles(array_diff(array_keys($this->_files), $expected), - 1000); $this->touchFiles(array_diff(array_keys($this->_files), $expected), - 1000);
$this->assertEquals(10, $this->getSmartyObj()->{$this->methodName}(null, null, 500)); $this->assertEquals(10, $this->getSmarty()->{$this->methodName}(null, null, 500));
$this->assertEquals($this->expectFiles($expected), $this->getFiles()); $this->assertEquals($this->expectFiles($expected), $this->getFiles());
$this->clearFiles(); $this->clearFiles();
@@ -313,7 +313,7 @@ class ClearCompiledTest extends PHPUnit_Smarty
public function runClearTemplateExpired($useSubDirs) public function runClearTemplateExpired($useSubDirs)
{ {
$this->getSmartyObj()->setUseSubDirs($useSubDirs); $this->getSmarty()->setUseSubDirs($useSubDirs);
$this->clearFiles(); $this->clearFiles();
$this->makeFiles(); $this->makeFiles();
@@ -324,7 +324,7 @@ class ClearCompiledTest extends PHPUnit_Smarty
'[1]ambiguous/case1/foobar.tpl#', '[1]ambiguous/case1/foobar.tpl#compile1', '[1]ambiguous/case1/foobar.tpl#compile2', '[1]ambiguous/case1/foobar.tpl#', '[1]ambiguous/case1/foobar.tpl#compile1', '[1]ambiguous/case1/foobar.tpl#compile2',
); );
$this->touchFiles(array('helloworld.tpl#compile1'), - 1000); $this->touchFiles(array('helloworld.tpl#compile1'), - 1000);
$this->assertEquals(1, $this->getSmartyObj()->{$this->methodName}("helloworld.tpl", null, 500)); $this->assertEquals(1, $this->getSmarty()->{$this->methodName}("helloworld.tpl", null, 500));
$this->assertEquals($this->expectFiles($expected), $this->getFiles()); $this->assertEquals($this->expectFiles($expected), $this->getFiles());
$this->clearFiles(); $this->clearFiles();
@@ -343,7 +343,7 @@ class ClearCompiledTest extends PHPUnit_Smarty
public function runClearTemplateCacheidExpired($useSubDirs) public function runClearTemplateCacheidExpired($useSubDirs)
{ {
$this->getSmartyObj()->setUseSubDirs($useSubDirs); $this->getSmarty()->setUseSubDirs($useSubDirs);
$this->clearFiles(); $this->clearFiles();
$this->makeFiles(); $this->makeFiles();
@@ -354,7 +354,7 @@ class ClearCompiledTest extends PHPUnit_Smarty
'[1]ambiguous/case1/foobar.tpl#', '[1]ambiguous/case1/foobar.tpl#compile1', '[1]ambiguous/case1/foobar.tpl#compile2', '[1]ambiguous/case1/foobar.tpl#', '[1]ambiguous/case1/foobar.tpl#compile1', '[1]ambiguous/case1/foobar.tpl#compile2',
); );
$this->touchFiles(array('helloworld.tpl#compile1', 'helloworld.tpl#compile2'), - 1000); $this->touchFiles(array('helloworld.tpl#compile1', 'helloworld.tpl#compile2'), - 1000);
$this->assertEquals(1, $this->getSmartyObj()->{$this->methodName}("helloworld.tpl", "compile1", 500)); $this->assertEquals(1, $this->getSmarty()->{$this->methodName}("helloworld.tpl", "compile1", 500));
$this->assertEquals($this->expectFiles($expected), $this->getFiles()); $this->assertEquals($this->expectFiles($expected), $this->getFiles());
$this->clearFiles(); $this->clearFiles();
@@ -373,7 +373,7 @@ class ClearCompiledTest extends PHPUnit_Smarty
public function runClearCacheidExpired($useSubDirs) public function runClearCacheidExpired($useSubDirs)
{ {
$this->getSmartyObj()->setUseSubDirs($useSubDirs); $this->getSmarty()->setUseSubDirs($useSubDirs);
$this->clearFiles(); $this->clearFiles();
$this->makeFiles(); $this->makeFiles();
@@ -384,7 +384,7 @@ class ClearCompiledTest extends PHPUnit_Smarty
'[1]ambiguous/case1/foobar.tpl#', '[1]ambiguous/case1/foobar.tpl#compile1', '[1]ambiguous/case1/foobar.tpl#compile2', '[1]ambiguous/case1/foobar.tpl#', '[1]ambiguous/case1/foobar.tpl#compile1', '[1]ambiguous/case1/foobar.tpl#compile2',
); );
$this->touchFiles(array('helloworld.tpl#compile1'), - 1000); $this->touchFiles(array('helloworld.tpl#compile1'), - 1000);
$this->assertEquals(1, $this->getSmartyObj()->{$this->methodName}(null, "compile1", 500)); $this->assertEquals(1, $this->getSmarty()->{$this->methodName}(null, "compile1", 500));
$this->assertEquals($this->expectFiles($expected), $this->getFiles()); $this->assertEquals($this->expectFiles($expected), $this->getFiles());
$this->clearFiles(); $this->clearFiles();
@@ -403,7 +403,7 @@ class ClearCompiledTest extends PHPUnit_Smarty
public function runClearTemplateCacheid($useSubDirs) public function runClearTemplateCacheid($useSubDirs)
{ {
$this->getSmartyObj()->setUseSubDirs($useSubDirs); $this->getSmarty()->setUseSubDirs($useSubDirs);
$this->clearFiles(); $this->clearFiles();
$this->makeFiles(); $this->makeFiles();
@@ -413,7 +413,7 @@ class ClearCompiledTest extends PHPUnit_Smarty
'ambiguous/case1/foobar.tpl#', 'ambiguous/case1/foobar.tpl#compile1', 'ambiguous/case1/foobar.tpl#compile2', 'ambiguous/case1/foobar.tpl#', 'ambiguous/case1/foobar.tpl#compile1', 'ambiguous/case1/foobar.tpl#compile2',
'[1]ambiguous/case1/foobar.tpl#', '[1]ambiguous/case1/foobar.tpl#compile1', '[1]ambiguous/case1/foobar.tpl#compile2', '[1]ambiguous/case1/foobar.tpl#', '[1]ambiguous/case1/foobar.tpl#compile1', '[1]ambiguous/case1/foobar.tpl#compile2',
); );
$this->assertEquals(1, $this->getSmartyObj()->{$this->methodName}("helloworld.tpl", "compile1")); $this->assertEquals(1, $this->getSmarty()->{$this->methodName}("helloworld.tpl", "compile1"));
$this->assertEquals($this->expectFiles($expected), $this->getFiles()); $this->assertEquals($this->expectFiles($expected), $this->getFiles());
$this->clearFiles(); $this->clearFiles();
@@ -431,7 +431,7 @@ class ClearCompiledTest extends PHPUnit_Smarty
public function runClearAmbiguousTemplate($useSubDirs) public function runClearAmbiguousTemplate($useSubDirs)
{ {
$this->getSmartyObj()->setUseSubDirs($useSubDirs); $this->getSmarty()->setUseSubDirs($useSubDirs);
$this->clearFiles(); $this->clearFiles();
$this->makeFiles(); $this->makeFiles();
@@ -443,7 +443,7 @@ class ClearCompiledTest extends PHPUnit_Smarty
'helloworld2.tpl#', 'helloworld2.tpl#compile1', 'helloworld2.tpl#compile2', 'helloworld2.tpl#', 'helloworld2.tpl#compile1', 'helloworld2.tpl#compile2',
'[1]ambiguous/case1/foobar.tpl#', '[1]ambiguous/case1/foobar.tpl#compile1', '[1]ambiguous/case1/foobar.tpl#compile2', '[1]ambiguous/case1/foobar.tpl#', '[1]ambiguous/case1/foobar.tpl#compile1', '[1]ambiguous/case1/foobar.tpl#compile2',
); );
$this->assertEquals(3, $this->getSmartyObj()->{$this->methodName}("ambiguous/case1/foobar.tpl")); $this->assertEquals(3, $this->getSmarty()->{$this->methodName}("ambiguous/case1/foobar.tpl"));
$this->assertEquals($this->expectFiles($expected), $this->getFiles()); $this->assertEquals($this->expectFiles($expected), $this->getFiles());
$this->clearFiles(); $this->clearFiles();

View File

@@ -27,7 +27,7 @@ function smarty_function_checkconfigvar($params, $template)
$ptr = $template; $ptr = $template;
while ($ptr) { while ($ptr) {
if (in_array('template', $types) && $ptr instanceof Template) { if (in_array('template', $types) && $ptr instanceof Template) {
$output .= "#{$ptr->source->name}:\${$var} ="; $output .= "#{$ptr->getSource()->name}:\${$var} =";
$output .= $ptr->hasConfigVariable($var) ? preg_replace('/\s/', '', var_export($ptr->getConfigVariable($var), true)) : 'null'; $output .= $ptr->hasConfigVariable($var) ? preg_replace('/\s/', '', var_export($ptr->getConfigVariable($var), true)) : 'null';
$ptr = $ptr->parent; $ptr = $ptr->parent;
} elseif (in_array('data', $types) && !($ptr instanceof Template || $ptr instanceof Smarty)) { } elseif (in_array('data', $types) && !($ptr instanceof Template || $ptr instanceof Smarty)) {
@@ -40,8 +40,8 @@ function smarty_function_checkconfigvar($params, $template)
} }
if (in_array('global', $types)) { if (in_array('global', $types)) {
$output .= "#global:\${$var} ="; $output .= "#global:\${$var} =";
$output .= $template->smarty->hasConfigVariable($var) ? $output .= $template->getSmarty()->hasConfigVariable($var) ?
preg_replace('/\s/', '', var_export($template->smarty->getConfigVariable($var), true)) : 'null'; preg_replace('/\s/', '', var_export($template->getSmarty()->getConfigVariable($var), true)) : 'null';
} }
return $output; return $output;
} }

View File

@@ -27,7 +27,7 @@ function smarty_function_checkvar($params, \Smarty\Template $template)
$ptr = $template; $ptr = $template;
while ($ptr) { while ($ptr) {
if (in_array('template', $types) && $ptr instanceof Template) { if (in_array('template', $types) && $ptr instanceof Template) {
$output .= "#{$ptr->source->name}:\${$var} ="; $output .= "#{$ptr->getSource()->name}:\${$var} =";
$output .= $ptr->hasVariable($var) ? preg_replace('/\s/', '', var_export($ptr->getValue($var), true)) : '>unassigned<'; $output .= $ptr->hasVariable($var) ? preg_replace('/\s/', '', var_export($ptr->getValue($var), true)) : '>unassigned<';
$i = 0; $i = 0;
while (isset($ptr->_var_stack[ $i ])) { while (isset($ptr->_var_stack[ $i ])) {
@@ -46,8 +46,8 @@ function smarty_function_checkvar($params, \Smarty\Template $template)
} }
if (in_array('global', $types)) { if (in_array('global', $types)) {
$output .= "#global:\${$var} ="; $output .= "#global:\${$var} =";
$output .= $template->smarty->hasVariable($var) ? $output .= $template->getSmarty()->hasVariable($var) ?
preg_replace('/\s/', '', var_export($template->smarty->getValue($var), true)) : '>unassigned<'; preg_replace('/\s/', '', var_export($template->getSmarty()->getValue($var), true)) : '>unassigned<';
} }
return $output; return $output;
} }

View File

@@ -27,9 +27,9 @@ class My_Resource_Extendsall extends \Smarty\Resource\ExtendsPlugin
$uid = ''; $uid = '';
$sources = array(); $sources = array();
$timestamp = 0; $timestamp = 0;
foreach ($source->smarty->getTemplateDir() as $key => $directory) { foreach ($source->getSmarty()->getTemplateDir() as $key => $directory) {
try { try {
$s = Smarty\Resource\BasePlugin::source(null, $source->smarty, 'file:' . '[' . $key . ']' . $source->name); $s = Smarty\Resource\BasePlugin::source(null, $source->getSmarty(), 'file:' . '[' . $key . ']' . $source->name);
if (!$s->exists) { if (!$s->exists) {
continue; continue;
} }
@@ -48,7 +48,7 @@ class My_Resource_Extendsall extends \Smarty\Resource\ExtendsPlugin
$s = current($sources); $s = current($sources);
$source->components = $sources; $source->components = $sources;
$source->filepath = $s->filepath; $source->filepath = $s->filepath;
$source->uid = sha1($uid . $source->smarty->_joined_template_dir); $source->uid = sha1($uid . $source->getSmarty()->_joined_template_dir);
$source->exists = true; $source->exists = true;
$source->timestamp = $timestamp; $source->timestamp = $timestamp;
} }