From 5c74dc4a837d160789ac3266f7f82390688dd69e Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Fri, 13 Jan 2023 16:55:15 +0100 Subject: [PATCH] Replaced a bunch of direct property access with getters/setters. --- src/Cacheresource/Base.php | 18 +- src/Cacheresource/Custom.php | 20 +-- src/Cacheresource/File.php | 9 +- src/Cacheresource/KeyValueStore.php | 14 +- src/Compile/Base.php | 4 +- src/Compile/BlockCompiler.php | 4 +- src/Compile/DefaultHandlerBlockCompiler.php | 4 +- .../DefaultHandlerFunctionCallCompiler.php | 2 +- src/Compile/FunctionCallCompiler.php | 4 +- .../Modifier/EscapeModifierCompiler.php | 2 +- src/Compile/ModifierCompiler.php | 6 +- src/Compile/ObjectMethodBlockCompiler.php | 4 +- src/Compile/ObjectMethodCallCompiler.php | 10 +- src/Compile/PrintExpressionCompiler.php | 6 +- src/Compile/SpecialVariableCompiler.php | 22 +-- src/Compile/Tag/BCPluginWrapper.php | 2 +- src/Compile/Tag/Block.php | 10 +- src/Compile/Tag/BlockClose.php | 30 ++-- src/Compile/Tag/Call.php | 6 +- src/Compile/Tag/Capture.php | 4 +- src/Compile/Tag/CaptureClose.php | 2 +- src/Compile/Tag/Child.php | 2 +- src/Compile/Tag/EvalTag.php | 2 +- src/Compile/Tag/ExtendsTag.php | 16 +- src/Compile/Tag/ForeachSection.php | 10 +- src/Compile/Tag/ForeachTag.php | 4 +- src/Compile/Tag/FunctionClose.php | 79 ++++----- src/Compile/Tag/FunctionTag.php | 10 +- src/Compile/Tag/IncludeTag.php | 69 ++++---- src/Compile/Tag/Ldelim.php | 2 +- src/Compile/Tag/Rdelim.php | 2 +- src/Compiler/BaseCompiler.php | 2 +- src/Compiler/CodeFrame.php | 10 +- src/Compiler/Configfile.php | 14 +- src/Compiler/Template.php | 80 ++++++--- src/Data.php | 18 +- src/Debug.php | 26 +-- src/FunctionHandler/Fetch.php | 6 +- src/FunctionHandler/HtmlImage.php | 6 +- src/Resource/ExtendsPlugin.php | 4 +- src/Resource/FilePlugin.php | 22 +-- src/Resource/StringPlugin.php | 2 +- src/Runtime/InheritanceRuntime.php | 8 +- src/Runtime/TplFunctionRuntime.php | 10 +- src/Smarty.php | 15 +- src/Template.php | 111 +++++++----- src/Template/Cached.php | 102 +++++++---- src/Template/Compiled.php | 32 ++-- src/Template/Config.php | 2 +- src/Template/Source.php | 12 +- src/TemplateBase.php | 28 ++-- tests/PHPUnit_Smarty.php | 52 ++---- .../CacheResourceCustomMemcacheTest.php | 8 +- .../_shared/CacheResourceTestCommon.php | 158 +++++++++--------- .../Ambiguous/CustomResourceAmbiguousTest.php | 18 +- .../PHPunitplugins/resource.ambiguous.php | 2 +- .../ResourceTests/Eval/EvalResourceTest.php | 10 +- .../ResourceTests/File/FileResourceTest.php | 20 +-- .../FileIndexed/FileResourceIndexedTest.php | 8 +- .../Registered/RegisteredResourceTest.php | 4 +- .../ResourcePlugins/ResourcePluginTest.php | 4 +- .../Stream/StreamResourceTest.php | 12 +- .../String/StringResourceTest.php | 10 +- .../UnitTests/SecurityTests/SecurityTest.php | 4 +- .../ClearCompiledTest.php | 52 +++--- .../function.checkconfigvar.php | 6 +- .../PHPunitplugins/function.checkvar.php | 6 +- .../resources/resource.extendsall.php | 6 +- 68 files changed, 684 insertions(+), 585 deletions(-) diff --git a/src/Cacheresource/Base.php b/src/Cacheresource/Base.php index 9cebf075..984ea827 100644 --- a/src/Cacheresource/Base.php +++ b/src/Cacheresource/Base.php @@ -2,6 +2,7 @@ namespace Smarty\Cacheresource; +use Smarty\Exception; use Smarty\Smarty; use Smarty\Template; use Smarty\Template\Cached; @@ -76,16 +77,17 @@ abstract class Base */ abstract public function retrieveCachedContent(Template $_template); - /** - * Return cached content - * - * @param Template $_template template object - * - * @return null|string - */ + /** + * Return cached content + * + * @param Template $_template template object + * + * @return null|string + * @throws Exception + */ public function getCachedContent(Template $_template) { - if ($_template->getCached()->handler->process($_template)) { + if ($this->process($_template)) { ob_start(); $unifunc = $_template->getCached()->unifunc; $unifunc($_template); diff --git a/src/Cacheresource/Custom.php b/src/Cacheresource/Custom.php index 0a67729a..c049246c 100644 --- a/src/Cacheresource/Custom.php +++ b/src/Cacheresource/Custom.php @@ -91,9 +91,9 @@ abstract class Custom extends Base { $_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; - $path = $cached->source->uid . $_cache_id . $_compile_id; + $path = $cached->getSource()->uid . $_cache_id . $_compile_id; $cached->filepath = sha1($path); - if ($_template->smarty->cache_locking) { + if ($_template->getSmarty()->cache_locking) { $cached->lock_id = sha1('lock.' . $path); } $this->populateTimestamp($cached); @@ -109,7 +109,7 @@ abstract class Custom extends Base public function populateTimestamp(\Smarty\Template\Cached $cached) { $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) { $cached->timestamp = $mtime; $cached->exists = !!$cached->timestamp; @@ -118,7 +118,7 @@ abstract class Custom extends Base $timestamp = null; $this->fetch( $cached->filepath, - $cached->source->name, + $cached->getSource()->name, $cached->cache_id, $cached->compile_id, $cached->content, @@ -150,7 +150,7 @@ abstract class Custom extends Base if ($content === null || !$timestamp) { $this->fetch( $_smarty_tpl->getCached()->filepath, - $_smarty_tpl->source->name, + $_smarty_tpl->getSource()->name, $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, $content, @@ -177,7 +177,7 @@ abstract class Custom extends Base { return $this->save( $_template->getCached()->filepath, - $_template->source->name, + $_template->getSource()->name, $_template->cache_id, $_template->compile_id, $_template->cache_lifetime, @@ -199,7 +199,7 @@ abstract class Custom extends Base $timestamp = null; $this->fetch( $_template->getCached()->filepath, - $_template->source->name, + $_template->getSource()->name, $_template->cache_id, $_template->compile_id, $content, @@ -262,7 +262,7 @@ abstract class Custom extends Base public function hasLock(\Smarty\Smarty $smarty, \Smarty\Template\Cached $cached) { $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); if ($mtime === null) { $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; $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, ''); } @@ -297,7 +297,7 @@ abstract class Custom extends Base public function releaseLock(\Smarty\Smarty $smarty, \Smarty\Template\Cached $cached) { $cached->is_locked = false; - $name = $cached->source->name . '.lock'; + $name = $cached->getSource()->name . '.lock'; $this->delete($name, $cached->cache_id, $cached->compile_id, null); } } diff --git a/src/Cacheresource/File.php b/src/Cacheresource/File.php index 032949b2..63430a2a 100644 --- a/src/Cacheresource/File.php +++ b/src/Cacheresource/File.php @@ -33,8 +33,8 @@ class File extends Base */ public function populate(Cached $cached, Template $_template) { - $source = &$_template->source; - $smarty = &$_template->smarty; + $source = $_template->getSource(); + $smarty = $_template->getSmarty(); $_compile_dir_sep = $smarty->use_sub_dirs ? DIRECTORY_SEPARATOR : '^'; $_filepath = sha1($source->uid . $smarty->_joined_template_dir); $cached->filepath = $smarty->getCacheDir(); @@ -125,7 +125,7 @@ class File extends Base */ 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') && (!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); $smarty->caching = $_save_stat; // remove from template cache - $tpl->source; // have the template registered before unset() - if ($tpl->source->exists) { + if ($tpl->getSource()->exists) { $_resourcename_parts = basename(str_replace('^', '/', $tpl->getCached()->filepath)); } else { return 0; diff --git a/src/Cacheresource/KeyValueStore.php b/src/Cacheresource/KeyValueStore.php index e3322e22..733d2776 100644 --- a/src/Cacheresource/KeyValueStore.php +++ b/src/Cacheresource/KeyValueStore.php @@ -61,7 +61,7 @@ abstract class KeyValueStore extends Base */ 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->populateTimestamp($cached); } @@ -77,12 +77,12 @@ abstract class KeyValueStore extends Base { if (!$this->fetch( $cached->filepath, - $cached->source->name, + $cached->getSource()->name, $cached->cache_id, $cached->compile_id, $content, $timestamp, - $cached->source->uid + $cached->getSource()->uid ) ) { return; @@ -114,12 +114,12 @@ abstract class KeyValueStore extends Base if ($content === null || !$timestamp) { if (!$this->fetch( $_smarty_tpl->getCached()->filepath, - $_smarty_tpl->source->name, + $_smarty_tpl->getSource()->name, $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, $content, $timestamp, - $_smarty_tpl->source->uid + $_smarty_tpl->getSource()->uid ) ) { return false; @@ -160,12 +160,12 @@ abstract class KeyValueStore extends Base if ($content === null) { if (!$this->fetch( $_template->getCached()->filepath, - $_template->source->name, + $_template->getSource()->name, $_template->cache_id, $_template->compile_id, $content, $timestamp, - $_template->source->uid + $_template->getSource()->uid ) ) { return false; diff --git a/src/Compile/Base.php b/src/Compile/Base.php index c555e48c..df19b136 100644 --- a/src/Compile/Base.php +++ b/src/Compile/Base.php @@ -214,8 +214,8 @@ abstract class Base implements CompilerInterface { } } // wrong nesting of tags - $compiler->trigger_template_error("unclosed '" . $compiler->template->getLeftDelimiter() . "{$_openTag}" . - $compiler->template->getRightDelimiter() . "' tag"); + $compiler->trigger_template_error("unclosed '" . $compiler->getTemplate()->getLeftDelimiter() . "{$_openTag}" . + $compiler->getTemplate()->getRightDelimiter() . "' tag"); return; } // wrong nesting of tags diff --git a/src/Compile/BlockCompiler.php b/src/Compile/BlockCompiler.php index b96d5257..0c409101 100644 --- a/src/Compile/BlockCompiler.php +++ b/src/Compile/BlockCompiler.php @@ -70,7 +70,7 @@ class BlockCompiler extends Base { * @return 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 */ 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"; } /** diff --git a/src/Compile/DefaultHandlerBlockCompiler.php b/src/Compile/DefaultHandlerBlockCompiler.php index faa322a9..034ea04e 100644 --- a/src/Compile/DefaultHandlerBlockCompiler.php +++ b/src/Compile/DefaultHandlerBlockCompiler.php @@ -7,7 +7,7 @@ class DefaultHandlerBlockCompiler extends BlockCompiler { * @inheritDoc */ 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')"; } @@ -15,7 +15,7 @@ class DefaultHandlerBlockCompiler extends BlockCompiler { * @inheritDoc */ 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')"; } } \ No newline at end of file diff --git a/src/Compile/DefaultHandlerFunctionCallCompiler.php b/src/Compile/DefaultHandlerFunctionCallCompiler.php index 5b9833ec..ff2f131c 100644 --- a/src/Compile/DefaultHandlerFunctionCallCompiler.php +++ b/src/Compile/DefaultHandlerFunctionCallCompiler.php @@ -35,7 +35,7 @@ class DefaultHandlerFunctionCallCompiler extends Base { $_paramsArray = $this->formatParamsArray($_attr); $_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)"; if (!empty($parameter['modifierlist'])) { diff --git a/src/Compile/FunctionCallCompiler.php b/src/Compile/FunctionCallCompiler.php index a2bedddf..849655ce 100644 --- a/src/Compile/FunctionCallCompiler.php +++ b/src/Compile/FunctionCallCompiler.php @@ -55,7 +55,7 @@ class FunctionCallCompiler extends Base { $_attr = $this->getAttributes($compiler, $args); unset($_attr['nocache']); - if (!$functionHandler = $compiler->smarty->getFunctionHandler($function)) { + if (!$functionHandler = $compiler->getSmarty()->getFunctionHandler($function)) { throw new CompilerException("Cannot compile unknown function $function."); } @@ -66,7 +66,7 @@ class FunctionCallCompiler extends Base { $_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)"; if (!empty($parameter['modifierlist'])) { diff --git a/src/Compile/Modifier/EscapeModifierCompiler.php b/src/Compile/Modifier/EscapeModifierCompiler.php index 4847ecd3..6e093a3e 100644 --- a/src/Compile/Modifier/EscapeModifierCompiler.php +++ b/src/Compile/Modifier/EscapeModifierCompiler.php @@ -50,6 +50,6 @@ class EscapeModifierCompiler extends Base { } catch (Exception $e) { // pass through to regular plugin fallback } - return '$_smarty_tpl->smarty->getModifierCallback(\'escape\')(' . join(', ', $params) . ')'; + return '$_smarty_tpl->getSmarty()->getModifierCallback(\'escape\')(' . join(', ', $params) . ')'; } } \ No newline at end of file diff --git a/src/Compile/ModifierCompiler.php b/src/Compile/ModifierCompiler.php index 678e2ed4..ea50cfcf 100644 --- a/src/Compile/ModifierCompiler.php +++ b/src/Compile/ModifierCompiler.php @@ -45,8 +45,8 @@ class ModifierCompiler extends Base { $single_modifier[0] = $output; $params = implode(',', $single_modifier); - if (!is_object($compiler->smarty->security_policy) - || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler) + if (!is_object($compiler->getSmarty()->security_policy) + || $compiler->getSmarty()->security_policy->isTrustedModifier($modifier, $compiler) ) { if ($handler = $compiler->getModifierCompiler($modifier)) { @@ -54,7 +54,7 @@ class ModifierCompiler extends Base { } elseif ($compiler->getSmarty()->getModifierCallback($modifier)) { $output = sprintf( - '$_smarty_tpl->smarty->getModifierCallback(%s)(%s)', + '$_smarty_tpl->getSmarty()->getModifierCallback(%s)(%s)', var_export($modifier, true), $params ); diff --git a/src/Compile/ObjectMethodBlockCompiler.php b/src/Compile/ObjectMethodBlockCompiler.php index 76af1009..f8fba227 100644 --- a/src/Compile/ObjectMethodBlockCompiler.php +++ b/src/Compile/ObjectMethodBlockCompiler.php @@ -22,7 +22,7 @@ class ObjectMethodBlockCompiler extends BlockCompiler { * @inheritDoc */ 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}')))"; } @@ -30,7 +30,7 @@ class ObjectMethodBlockCompiler extends BlockCompiler { * @inheritDoc */ 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}"; } diff --git a/src/Compile/ObjectMethodCallCompiler.php b/src/Compile/ObjectMethodCallCompiler.php index 4e30b8c7..f3ce6960 100644 --- a/src/Compile/ObjectMethodCallCompiler.php +++ b/src/Compile/ObjectMethodCallCompiler.php @@ -49,19 +49,19 @@ class ObjectMethodCallCompiler extends Base { unset($_attr['assign']); } // 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 - if ($compiler->smarty->registered_objects[$tag][2]) { + if ($compiler->getSmarty()->registered_objects[$tag][2]) { $_paramsArray = $this->formatParamsArray($_attr); $_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 { $_params = implode(',', $_attr); - $output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$function}({$_params})"; + $output = "\$_smarty_tpl->getSmarty()->registered_objects['{$tag}'][0]->{$function}({$_params})"; } } else { // object property - $output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$function}"; + $output = "\$_smarty_tpl->getSmarty()->registered_objects['{$tag}'][0]->{$function}"; } if (!empty($parameter['modifierlist'])) { $output = $compiler->compileModifier($parameter['modifierlist'], $output); diff --git a/src/Compile/PrintExpressionCompiler.php b/src/Compile/PrintExpressionCompiler.php index 13fe746f..99a03901 100644 --- a/src/Compile/PrintExpressionCompiler.php +++ b/src/Compile/PrintExpressionCompiler.php @@ -65,9 +65,9 @@ class PrintExpressionCompiler extends Base { // display value if (!$_attr['nofilter']) { // default modifier - if ($compiler->smarty->getDefaultModifiers()) { + if ($compiler->getSmarty()->getDefaultModifiers()) { $modifierlist = []; - foreach ($compiler->smarty->getDefaultModifiers() as $key => $single_default_modifier) { + foreach ($compiler->getSmarty()->getDefaultModifiers() as $key => $single_default_modifier) { preg_match_all( '/(\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|:|[^:]+)/', $single_default_modifier, @@ -83,7 +83,7 @@ class PrintExpressionCompiler extends Base { $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) . "')"; } diff --git a/src/Compile/SpecialVariableCompiler.php b/src/Compile/SpecialVariableCompiler.php index d138688a..0ba96656 100644 --- a/src/Compile/SpecialVariableCompiler.php +++ b/src/Compile/SpecialVariableCompiler.php @@ -46,8 +46,8 @@ class SpecialVariableCompiler extends Base { if ($variable === false) { $compiler->trigger_template_error("special \$Smarty variable name index can not be variable", null, true); } - if (!isset($compiler->smarty->security_policy) - || $compiler->smarty->security_policy->isTrustedSpecialSmartyVar($variable, $compiler) + if (!isset($compiler->getSmarty()->security_policy) + || $compiler->getSmarty()->security_policy->isTrustedSpecialSmartyVar($variable, $compiler) ) { switch ($variable) { case 'foreach': @@ -59,8 +59,8 @@ class SpecialVariableCompiler extends Base { case 'now': return 'time()'; case 'cookies': - if (isset($compiler->smarty->security_policy) - && !$compiler->smarty->security_policy->allow_super_globals + if (isset($compiler->getSmarty()->security_policy) + && !$compiler->getSmarty()->security_policy->allow_super_globals ) { $compiler->trigger_template_error("(secure mode) super globals not permitted"); break; @@ -73,8 +73,8 @@ class SpecialVariableCompiler extends Base { case 'server': case 'session': case 'request': - if (isset($compiler->smarty->security_policy) - && !$compiler->smarty->security_policy->allow_super_globals + if (isset($compiler->getSmarty()->security_policy) + && !$compiler->getSmarty()->security_policy->allow_super_globals ) { $compiler->trigger_template_error("(secure mode) super globals not permitted"); break; @@ -82,20 +82,20 @@ class SpecialVariableCompiler extends Base { $compiled_ref = '$_' . smarty_strtoupper_ascii($variable); break; case 'template': - return 'basename($_smarty_tpl->source->filepath)'; + return 'basename($_smarty_tpl->getSource()->filepath)'; 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"); break; } return '$_smarty_tpl'; case 'current_dir': - return 'dirname($_smarty_tpl->source->filepath)'; + return 'dirname($_smarty_tpl->getSource()->filepath)'; case 'version': return "\\Smarty\\Smarty::SMARTY_VERSION"; case 'const': - if (isset($compiler->smarty->security_policy) - && !$compiler->smarty->security_policy->allow_constants + if (isset($compiler->getSmarty()->security_policy) + && !$compiler->getSmarty()->security_policy->allow_constants ) { $compiler->trigger_template_error("(secure mode) constants not permitted"); break; diff --git a/src/Compile/Tag/BCPluginWrapper.php b/src/Compile/Tag/BCPluginWrapper.php index 58f11166..6e0ce1fa 100644 --- a/src/Compile/Tag/BCPluginWrapper.php +++ b/src/Compile/Tag/BCPluginWrapper.php @@ -17,6 +17,6 @@ class BCPluginWrapper extends Base { * @inheritDoc */ 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()); } } \ No newline at end of file diff --git a/src/Compile/Tag/Block.php b/src/Compile/Tag/Block.php index 51f373bc..85fb4dbc 100644 --- a/src/Compile/Tag/Block.php +++ b/src/Compile/Tag/Block.php @@ -82,14 +82,14 @@ class Block extends Inheritance { $compiler, 'block', [ - $_attr, $compiler->nocache, $compiler->parser->current_buffer, - $compiler->template->getCompiled()->getNocacheCode(), - $compiler->template->caching, + $_attr, $compiler->nocache, $compiler->getParser()->current_buffer, + $compiler->getTemplate()->getCompiled()->getNocacheCode(), + $compiler->getTemplate()->caching, ] ); $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; - $compiler->parser->current_buffer = new Template(); - $compiler->template->getCompiled()->setNocacheCode(false); + $compiler->getParser()->current_buffer = new Template(); + $compiler->getTemplate()->getCompiled()->setNocacheCode(false); $compiler->suppressNocacheProcessing = true; } } diff --git a/src/Compile/Tag/BlockClose.php b/src/Compile/Tag/BlockClose.php index 95317e27..8458ee5f 100644 --- a/src/Compile/Tag/BlockClose.php +++ b/src/Compile/Tag/BlockClose.php @@ -34,9 +34,9 @@ class BlockClose extends Inheritance { } $_className = $compiler->_cache['blockClass'][$compiler->_cache['blockNesting']]; // get compiled block code - $_functionCode = $compiler->parser->current_buffer; + $_functionCode = $compiler->getParser()->current_buffer; // setup buffer for template function code - $compiler->parser->current_buffer = new Template(); + $compiler->getParser()->current_buffer = new Template(); $output = "cStyleComment(" {block {$_name}} ") . "\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 function callBlock(\\Smarty\\Template \$_smarty_tpl) {\n"; - if ($compiler->template->getCompiled()->getNocacheCode()) { - $output .= "\$_smarty_tpl->getCached()->hashes['{$compiler->template->getCompiled()->nocache_hash}'] = true;\n"; + if ($compiler->getTemplate()->getCompiled()->getNocacheCode()) { + $output .= "\$_smarty_tpl->getCached()->hashes['{$compiler->getTemplate()->getCompiled()->nocache_hash}'] = true;\n"; } if (isset($_assign)) { $output .= "ob_start();\n"; } $output .= "?>\n"; - $compiler->parser->current_buffer->append_subtree( - $compiler->parser, + $compiler->getParser()->current_buffer->append_subtree( + $compiler->getParser(), new \Smarty\ParseTree\Tag( - $compiler->parser, + $compiler->getParser(), $output ) ); - $compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode); + $compiler->getParser()->current_buffer->append_subtree($compiler->getParser(), $_functionCode); $output = "assign({$_assign}, ob_get_clean());\n"; @@ -68,20 +68,20 @@ class BlockClose extends Inheritance { $output .= "}\n"; $output .= $compiler->cStyleComment(" {/block {$_name}} ") . "\n\n"; $output .= "?>\n"; - $compiler->parser->current_buffer->append_subtree( - $compiler->parser, + $compiler->getParser()->current_buffer->append_subtree( + $compiler->getParser(), new \Smarty\ParseTree\Tag( - $compiler->parser, + $compiler->getParser(), $output ) ); - $compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser); - $compiler->parser->current_buffer = new Template(); + $compiler->blockOrFunctionCode .= $compiler->getParser()->current_buffer->to_smarty_php($compiler->getParser()); + $compiler->getParser()->current_buffer = new Template(); // restore old status - $compiler->template->getCompiled()->setNocacheCode($_has_nocache_code); + $compiler->getTemplate()->getCompiled()->setNocacheCode($_has_nocache_code); $compiler->tag_nocache = $compiler->nocache; $compiler->nocache = $_nocache; - $compiler->parser->current_buffer = $_buffer; + $compiler->getParser()->current_buffer = $_buffer; $output = "_cache['blockNesting'] === 1) { $output .= "\$_smarty_tpl->getInheritance()->instanceBlock(\$_smarty_tpl, '$_className', $_name);\n"; diff --git a/src/Compile/Tag/Call.php b/src/Compile/Tag/Call.php index 3d552f10..1c691add 100644 --- a/src/Compile/Tag/Call.php +++ b/src/Compile/Tag/Call.php @@ -59,7 +59,7 @@ class Call extends Base { $_name = $_attr['name']; unset($_attr['name'], $_attr['assign'], $_attr['nocache']); // 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'; } else { $_nocache = 'false'; @@ -70,10 +70,10 @@ class Call extends Base { // was there an assign attribute if (isset($_assign)) { $_output = - "smarty->getRuntime('TplFunction')->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});\n\$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n"; + "getSmarty()->getRuntime('TplFunction')->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});\n\$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n"; } else { $_output = - "smarty->getRuntime('TplFunction')->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});?>\n"; + "getSmarty()->getRuntime('TplFunction')->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});?>\n"; } return $_output; } diff --git a/src/Compile/Tag/Capture.php b/src/Compile/Tag/Capture.php index 8dee4a8e..d089e8c9 100644 --- a/src/Compile/Tag/Capture.php +++ b/src/Compile/Tag/Capture.php @@ -40,7 +40,7 @@ class Capture extends Base { \Smarty\Compiler\Template $compiler, $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 ]})" : ')'); } @@ -62,7 +62,7 @@ class Capture extends Base { $compiler->_cache['capture_stack'][] = [$compiler->nocache]; // maybe nocache because of nocache variables $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; - $_output = "smarty->getRuntime('Capture')->open(\$_smarty_tpl, $buffer, $assign, $append);?>"; + $_output = "getSmarty()->getRuntime('Capture')->open(\$_smarty_tpl, $buffer, $assign, $append);?>"; return $_output; } } \ No newline at end of file diff --git a/src/Compile/Tag/CaptureClose.php b/src/Compile/Tag/CaptureClose.php index e15766b6..a6e3aded 100644 --- a/src/Compile/Tag/CaptureClose.php +++ b/src/Compile/Tag/CaptureClose.php @@ -37,6 +37,6 @@ class CaptureClose extends Base { $compiler->tag_nocache = true; } [$compiler->nocache] = array_pop($compiler->_cache['capture_stack']); - return "smarty->getRuntime('Capture')->close(\$_smarty_tpl);?>"; + return "getSmarty()->getRuntime('Capture')->close(\$_smarty_tpl);?>"; } } diff --git a/src/Compile/Tag/Child.php b/src/Compile/Tag/Child.php index b775cec9..03e045ab 100644 --- a/src/Compile/Tag/Child.php +++ b/src/Compile/Tag/Child.php @@ -58,7 +58,7 @@ class Child extends Base { if (!isset($compiler->_cache['blockNesting'])) { $compiler->trigger_template_error( "{$tag} used outside {block} tags ", - $compiler->parser->lex->taglineno + $compiler->getParser()->lex->taglineno ); } $compiler->has_code = true; diff --git a/src/Compile/Tag/EvalTag.php b/src/Compile/Tag/EvalTag.php index 191dee3c..c6535570 100644 --- a/src/Compile/Tag/EvalTag.php +++ b/src/Compile/Tag/EvalTag.php @@ -61,7 +61,7 @@ class EvalTag extends Base { } // create template object $_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? if (isset($_assign)) { $_output .= "\$_smarty_tpl->assign($_assign,\$_template->fetch());"; diff --git a/src/Compile/Tag/ExtendsTag.php b/src/Compile/Tag/ExtendsTag.php index a74919e4..26dd7d15 100644 --- a/src/Compile/Tag/ExtendsTag.php +++ b/src/Compile/Tag/ExtendsTag.php @@ -56,10 +56,10 @@ class ExtendsTag extends Inheritance { // check and get attributes $_attr = $this->getAttributes($compiler, $args); 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) { - $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 $this->registerInit($compiler, true); @@ -101,14 +101,14 @@ class ExtendsTag extends Inheritance { */ private function compileEndChild(\Smarty\Compiler\Template $compiler, $template = null) { $inlineUids = ''; - if (isset($template) && $compiler->smarty->merge_compiled_includes) { + if (isset($template) && $compiler->getSmarty()->merge_compiled_includes) { $code = $compiler->compileTag('include', [$template, ['scope' => 'parent']]); if (preg_match('/([,][\s]*[\'][a-z0-9]+[\'][,][\s]*[\']content.*[\'])[)]/', $code, $match)) { $inlineUids = $match[1]; } } - $compiler->parser->template_postfix[] = new \Smarty\ParseTree\Tag( - $compiler->parser, + $compiler->getParser()->template_postfix[] = new \Smarty\ParseTree\Tag( + $compiler->getParser(), 'getInheritance()->endChild($_smarty_tpl' . (isset($template) ? ", {$template}{$inlineUids}" : @@ -126,8 +126,8 @@ class ExtendsTag extends Inheritance { * @throws \Smarty\Exception */ private function compileInclude(\Smarty\Compiler\Template $compiler, $template) { - $compiler->parser->template_postfix[] = new \Smarty\ParseTree\Tag( - $compiler->parser, + $compiler->getParser()->template_postfix[] = new \Smarty\ParseTree\Tag( + $compiler->getParser(), $compiler->compileTag( 'include', [ @@ -147,7 +147,7 @@ class ExtendsTag extends Inheritance { */ public static function extendsSourceArrayCode(\Smarty\Template $template) { $resources = []; - foreach ($template->source->components as $source) { + foreach ($template->getSource()->components as $source) { $resources[] = $source->resource; } return $template->getLeftDelimiter() . 'extends file=\'extends:' . join('|', $resources) . diff --git a/src/Compile/Tag/ForeachSection.php b/src/Compile/Tag/ForeachSection.php index d72936d9..dd257401 100644 --- a/src/Compile/Tag/ForeachSection.php +++ b/src/Compile/Tag/ForeachSection.php @@ -154,7 +154,7 @@ abstract class ForeachSection extends Base { * @param \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) { // search parent compiler template source $nextCompiler = $compiler; - while ($nextCompiler !== $nextCompiler->parent_compiler) { - $nextCompiler = $nextCompiler->parent_compiler; + while ($nextCompiler !== $nextCompiler->getParentCompiler()) { + $nextCompiler = $nextCompiler->getParentCompiler(); if ($compiler !== $nextCompiler) { // get template source - $_content = $nextCompiler->template->source->getContent(); + $_content = $nextCompiler->getTemplate()->getSource()->getContent(); if ($_content !== '') { // run pre filter if required - $_content = $nextCompiler->smarty->runPreFilters($_content, $nextCompiler->template); + $_content = $nextCompiler->getSmarty()->runPreFilters($_content, $nextCompiler->getTemplate()); $this->matchProperty($_content); } } diff --git a/src/Compile/Tag/ForeachTag.php b/src/Compile/Tag/ForeachTag.php index 458e9676..bc567bc9 100644 --- a/src/Compile/Tag/ForeachTag.php +++ b/src/Compile/Tag/ForeachTag.php @@ -191,7 +191,7 @@ class ForeachTag extends ForeachSection { $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; // generate output code $output = "smarty->getRuntime('Foreach')->init(\$_smarty_tpl, $from, " . + $output .= "\$_from = \$_smarty_tpl->getSmarty()->getRuntime('Foreach')->init(\$_smarty_tpl, $from, " . var_export($item, true); if ($name || $needTotal || $key) { $output .= ', ' . var_export($needTotal, true); @@ -273,6 +273,6 @@ class ForeachTag extends ForeachSection { * @return string compiled code */ public function compileRestore($levels) { - return "\$_smarty_tpl->smarty->getRuntime('Foreach')->restore(\$_smarty_tpl, {$levels});"; + return "\$_smarty_tpl->getSmarty()->getRuntime('Foreach')->restore(\$_smarty_tpl, {$levels});"; } } \ No newline at end of file diff --git a/src/Compile/Tag/FunctionClose.php b/src/Compile/Tag/FunctionClose.php index 1cb576e4..353c5cca 100644 --- a/src/Compile/Tag/FunctionClose.php +++ b/src/Compile/Tag/FunctionClose.php @@ -40,9 +40,10 @@ class FunctionClose extends Base { $saved_data = $this->closeTag($compiler, ['function']); $_attr = $saved_data[0]; $_name = trim($_attr['name'], '\'"'); - $compiler->parent_compiler->tpl_function[$_name]['compiled_filepath'] = - $compiler->parent_compiler->template->getCompiled()->filepath; - $compiler->parent_compiler->tpl_function[$_name]['uid'] = $compiler->template->source->uid; + $parentCompiler = $compiler->getParentCompiler(); + $parentCompiler->tpl_function[$_name]['compiled_filepath'] = + $parentCompiler->getTemplate()->getCompiled()->filepath; + $parentCompiler->tpl_function[$_name]['uid'] = $compiler->getTemplate()->getSource()->uid; $_parameter = $_attr; unset($_parameter['name']); // default parameter @@ -53,13 +54,13 @@ class FunctionClose extends Base { } else { $_paramsCode = ''; } - $_functionCode = $compiler->parser->current_buffer; + $_functionCode = $compiler->getParser()->current_buffer; // setup buffer for template function code - $compiler->parser->current_buffer = new \Smarty\ParseTree\Template(); - $_funcName = "smarty_template_function_{$_name}_{$compiler->template->getCompiled()->nocache_hash}"; + $compiler->getParser()->current_buffer = new \Smarty\ParseTree\Template(); + $_funcName = "smarty_template_function_{$_name}_{$compiler->getTemplate()->getCompiled()->nocache_hash}"; $_funcNameCaching = $_funcName . 'Smarty\Compile\Tag\Nocache'; - if ($compiler->template->getCompiled()->getNocacheCode()) { - $compiler->parent_compiler->tpl_function[$_name]['call_name_caching'] = $_funcNameCaching; + if ($compiler->getTemplate()->getCompiled()->getNocacheCode()) { + $parentCompiler->tpl_function[$_name]['call_name_caching'] = $_funcNameCaching; $output = "cStyleComment(" {$_funcNameCaching} ") . "\n"; $output .= "if (!function_exists('{$_funcNameCaching}')) {\n"; @@ -69,41 +70,41 @@ class FunctionClose extends Base { $output .= $_paramsCode; $output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->assign(\$key, \$value);\n}\n"; $output .= "\$params = var_export(\$params, true);\n"; - $output .= "echo \"/*%%SmartyNocache:{$compiler->template->getCompiled()->nocache_hash}%%*/smarty->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}%%*/\";?>"; - $compiler->parser->current_buffer->append_subtree( - $compiler->parser, + $output .= "echo \"/*%%SmartyNocache:{$compiler->getTemplate()->getCompiled()->nocache_hash}%%*/getSmarty()->getRuntime('TplFunction')->saveTemplateVariables(\\\$_smarty_tpl, '{$_name}');\nforeach (\$params as \\\$key => \\\$value) {\n\\\$_smarty_tpl->assign(\\\$key, \\\$value);\n}\n?>"; + $output .= "/*/%%SmartyNocache:{$compiler->getTemplate()->getCompiled()->nocache_hash}%%*/\";?>"; + $compiler->getParser()->current_buffer->append_subtree( + $compiler->getParser(), new \Smarty\ParseTree\Tag( - $compiler->parser, + $compiler->getParser(), $output ) ); - $compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode); - $output = "template->getCompiled()->nocache_hash}%%*/smarty->getRuntime('TplFunction')->restoreTemplateVariables(\\\$_smarty_tpl, '{$_name}');?>\n"; - $output .= "/*/%%SmartyNocache:{$compiler->template->getCompiled()->nocache_hash}%%*/\";\n?>"; - $output .= "template->getCompiled()->nocache_hash}', \$_smarty_tpl->getCompiled()->nocache_hash ?? '', ob_get_clean());\n"; + $compiler->getParser()->current_buffer->append_subtree($compiler->getParser(), $_functionCode); + $output = "getTemplate()->getCompiled()->nocache_hash}%%*/getSmarty()->getRuntime('TplFunction')->restoreTemplateVariables(\\\$_smarty_tpl, '{$_name}');?>\n"; + $output .= "/*/%%SmartyNocache:{$compiler->getTemplate()->getCompiled()->nocache_hash}%%*/\";\n?>"; + $output .= "getTemplate()->getCompiled()->nocache_hash}', \$_smarty_tpl->getCompiled()->nocache_hash ?? '', ob_get_clean());\n"; $output .= "}\n}\n"; $output .= $compiler->cStyleComment("/ {$_funcName}_nocache ") . "\n\n"; $output .= "?>\n"; - $compiler->parser->current_buffer->append_subtree( - $compiler->parser, + $compiler->getParser()->current_buffer->append_subtree( + $compiler->getParser(), new \Smarty\ParseTree\Tag( - $compiler->parser, + $compiler->getParser(), $output ) ); $_functionCode = new \Smarty\ParseTree\Tag( - $compiler->parser, + $compiler->getParser(), 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'], - $_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 = "cStyleComment(" {$_funcName} ") . "\n"; $output .= "if (!function_exists('{$_funcName}')) {\n"; @@ -111,30 +112,30 @@ class FunctionClose extends Base { $output .= $_paramsCode; $output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->assign(\$key, \$value);\n}\n"; $output .= "?>\n"; - $compiler->parser->current_buffer->append_subtree( - $compiler->parser, + $compiler->getParser()->current_buffer->append_subtree( + $compiler->getParser(), new \Smarty\ParseTree\Tag( - $compiler->parser, + $compiler->getParser(), $output ) ); - $compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode); + $compiler->getParser()->current_buffer->append_subtree($compiler->getParser(), $_functionCode); $output = "cStyleComment("/ {$_funcName} ") . "\n\n"; $output .= "?>\n"; - $compiler->parser->current_buffer->append_subtree( - $compiler->parser, + $compiler->getParser()->current_buffer->append_subtree( + $compiler->getParser(), new \Smarty\ParseTree\Tag( - $compiler->parser, + $compiler->getParser(), $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 - $compiler->parser->current_buffer = $saved_data[1]; + $compiler->getParser()->current_buffer = $saved_data[1]; // restore old status - $compiler->template->getCompiled()->setNocacheCode($saved_data[2]); - $compiler->template->caching = $saved_data[3]; + $compiler->getTemplate()->getCompiled()->setNocacheCode($saved_data[2]); + $compiler->getTemplate()->caching = $saved_data[3]; return true; } @@ -146,9 +147,11 @@ class FunctionClose extends Base { * @return string */ 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 = 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] ); diff --git a/src/Compile/Tag/FunctionTag.php b/src/Compile/Tag/FunctionTag.php index a14fb1db..aa41abdb 100644 --- a/src/Compile/Tag/FunctionTag.php +++ b/src/Compile/Tag/FunctionTag.php @@ -58,15 +58,15 @@ class FunctionTag extends Base { $compiler->trigger_template_error("Function name contains invalid characters: {$_name}", null, true); } - $compiler->parent_compiler->tpl_function[$_name] = []; + $compiler->getParentCompiler()->tpl_function[$_name] = []; $save = [ - $_attr, $compiler->parser->current_buffer, $compiler->template->getCompiled()->getNocacheCode(), - $compiler->template->caching, + $_attr, $compiler->getParser()->current_buffer, $compiler->getTemplate()->getCompiled()->getNocacheCode(), + $compiler->getTemplate()->caching, ]; $this->openTag($compiler, 'function', $save); // Init temporary context - $compiler->parser->current_buffer = new \Smarty\ParseTree\Template(); - $compiler->template->getCompiled()->setNocacheCode(false); + $compiler->getParser()->current_buffer = new \Smarty\ParseTree\Template(); + $compiler->getTemplate()->getCompiled()->setNocacheCode(false); return true; } } \ No newline at end of file diff --git a/src/Compile/Tag/IncludeTag.php b/src/Compile/Tag/IncludeTag.php index 9c1dbe3e..6d2bcd52 100644 --- a/src/Compile/Tag/IncludeTag.php +++ b/src/Compile/Tag/IncludeTag.php @@ -75,20 +75,20 @@ class IncludeTag extends Base { $variable_template = false; // parse resource_name 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]; - $handler = \Smarty\Resource\BasePlugin::load($compiler->smarty, $type); + $handler = \Smarty\Resource\BasePlugin::load($compiler->getSmarty(), $type); if ($handler->recompiled) { $variable_template = true; } if (!$variable_template) { if ($type !== 'string') { $fullResourceName = "{$type}:{$name}"; - $compiled = $compiler->parent_compiler->template->getCompiled(); + $compiled = $compiler->getParentCompiler()->getTemplate()->getCompiled(); if (isset($compiled->includes[$fullResourceName])) { $compiled->includes[$fullResourceName]++; } else { - if ("{$compiler->template->source->type}:{$compiler->template->source->name}" == + if ("{$compiler->getTemplate()->getSource()->type}:{$compiler->getTemplate()->getSource()->name}" == $fullResourceName ) { // recursive call of current template @@ -113,12 +113,12 @@ class IncludeTag extends Base { $_caching = Smarty::CACHING_OFF; $call_nocache = $compiler->tag_nocache || $compiler->nocache; // caching was on and {include} is not in nocache mode - if ($compiler->template->caching && !$compiler->nocache && !$compiler->tag_nocache) { + if ($compiler->getTemplate()->caching && !$compiler->nocache && !$compiler->tag_nocache) { $_caching = \Smarty\Template::CACHING_NOCACHE_CODE; } // flag if included template code should be merged into caller - $merge_compiled_includes = ($compiler->smarty->merge_compiled_includes || $_attr['inline'] === true) && - !$compiler->template->source->handler->recompiled; + $merge_compiled_includes = ($compiler->getSmarty()->merge_compiled_includes || $_attr['inline'] === true) && + !$compiler->getTemplate()->getSource()->handler->recompiled; if ($merge_compiled_includes) { // variable template name ? if ($variable_template) { @@ -153,7 +153,7 @@ class IncludeTag extends Base { } // 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; } // assign attribute @@ -171,27 +171,27 @@ class IncludeTag extends Base { } $has_compiled_template = false; if ($merge_compiled_includes) { - $c_id = $compiler->template->compile_id; + $c_id = $compiler->getTemplate()->compile_id; // we must observe different compile_id and caching $t_hash = sha1($c_id . ($_caching ? '--caching' : '--nocaching')); - $compiler->smarty->setAllowAmbiguousResources(true); - $tpl = $compiler->smarty->createTemplate( + $compiler->getSmarty()->setAllowAmbiguousResources(true); + $tpl = $compiler->getSmarty()->createTemplate( trim($fullResourceName, '"\''), - $compiler->template->cache_id, + $compiler->getTemplate()->cache_id, $c_id, - $compiler->template, + $compiler->getTemplate(), $_caching ); - $uid = $tpl->source->type . $tpl->source->uid; - if (!isset($compiler->parent_compiler->mergedSubTemplatesData[$uid][$t_hash])) { + $uid = $tpl->getSource()->type . $tpl->getSource()->uid; + if (!isset($compiler->getParentCompiler()->mergedSubTemplatesData[$uid][$t_hash])) { $has_compiled_template = $this->compileInlineTemplate($compiler, $tpl, $t_hash); } else { $has_compiled_template = true; } - $compiler->smarty->setAllowAmbiguousResources(false); + $compiler->getSmarty()->setAllowAmbiguousResources(false); } // delete {include} standard attributes @@ -208,7 +208,7 @@ class IncludeTag extends Base { } if ($has_compiled_template && !$call_nocache) { $_output = "template->caching) { + if (!empty($_attr) && $_caching === \Smarty\Template::CACHING_NOCACHE_CODE && $compiler->getTemplate()->caching) { $_vars_nc = "foreach ($_vars as \$ik => \$iv) {\n"; $_vars_nc .= "\$_smarty_tpl->assign(\$ik, \$iv);\n"; $_vars_nc .= "}\n"; @@ -217,7 +217,7 @@ class IncludeTag extends Base { if (isset($_assign)) { $_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)) { $_output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean(), false, {$_scope});\n"; } @@ -256,32 +256,33 @@ class IncludeTag extends Base { \Smarty\Template $tpl, $t_hash ) { - $uid = $tpl->source->type . $tpl->source->uid; - if ($tpl->source->exists) { - $compiler->parent_compiler->mergedSubTemplatesData[$uid][$t_hash]['uid'] = $tpl->source->uid; - $tpl->getCompiled(true)->nocache_hash = $compiler->parent_compiler->template->getCompiled()->nocache_hash; + $tplSource = $tpl->getSource(); + $uid = $tplSource->type . $tplSource->uid; + if ($tplSource->exists) { + $compiler->getParentCompiler()->mergedSubTemplatesData[$uid][$t_hash]['uid'] = $tplSource->uid; + $tpl->getCompiled(true)->nocache_hash = $compiler->getParentCompiler()->getTemplate()->getCompiled()->nocache_hash; // 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)); // make sure whole chain gets compiled $tpl->mustCompile = true; - $compiler->parent_compiler->mergedSubTemplatesData[$uid][$t_hash]['nocache_hash'] = + $compiler->getParentCompiler()->mergedSubTemplatesData[$uid][$t_hash]['nocache_hash'] = $tpl->getCompiled()->nocache_hash; - if ($tpl->source->type === 'file') { - $sourceInfo = $tpl->source->filepath; + if ($tplSource->type === 'file') { + $sourceInfo = $tplSource->filepath; } else { - $basename = $tpl->source->handler->getBasename($tpl->source); - $sourceInfo = $tpl->source->type . ':' . - ($basename ? $basename : $tpl->source->name); + $basename = $tplSource->handler->getBasename($tplSource); + $sourceInfo = $tplSource->type . ':' . + ($basename ? $basename : $tplSource->name); } // get compiled code $compiled_code = "cStyleComment(" Start inline template \"{$sourceInfo}\" =============================") . "\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 .= "\n"; - $compiled_code .= $tpl->smarty->runPostFilters($tpl->getCompiler()->blockOrFunctionCode, $tpl); + $compiled_code .= $tpl->getSmarty()->runPostFilters($tpl->getCompiler()->blockOrFunctionCode, $tpl); $compiled_code .= "cStyleComment(" End inline template \"{$sourceInfo}\" =============================") . "\n"; $compiled_code .= '?>'; @@ -293,12 +294,12 @@ class IncludeTag extends Base { $compiled_code = str_replace( "{$tpl->getCompiled()->nocache_hash}", - $compiler->template->getCompiled()->nocache_hash, + $compiler->getTemplate()->getCompiled()->nocache_hash, $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; } else { return false; diff --git a/src/Compile/Tag/Ldelim.php b/src/Compile/Tag/Ldelim.php index 71b1389c..5a48d3ad 100644 --- a/src/Compile/Tag/Ldelim.php +++ b/src/Compile/Tag/Ldelim.php @@ -35,6 +35,6 @@ class Ldelim extends Base { if ($_attr['nocache'] === true) { $compiler->trigger_template_error('nocache option not allowed', null, true); } - return $compiler->template->getLeftDelimiter(); + return $compiler->getTemplate()->getLeftDelimiter(); } } diff --git a/src/Compile/Tag/Rdelim.php b/src/Compile/Tag/Rdelim.php index 173d1231..87bd1889 100644 --- a/src/Compile/Tag/Rdelim.php +++ b/src/Compile/Tag/Rdelim.php @@ -30,6 +30,6 @@ class Rdelim extends Ldelim { */ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) { parent::compile($args, $compiler); - return $compiler->template->getRightDelimiter(); + return $compiler->getTemplate()->getRightDelimiter(); } } diff --git a/src/Compiler/BaseCompiler.php b/src/Compiler/BaseCompiler.php index 84963ea3..78c35a69 100644 --- a/src/Compiler/BaseCompiler.php +++ b/src/Compiler/BaseCompiler.php @@ -11,7 +11,7 @@ abstract class BaseCompiler { * * @var Smarty */ - public $smarty = null; + protected $smarty = null; /** * @return Smarty|null diff --git a/src/Compiler/CodeFrame.php b/src/Compiler/CodeFrame.php index bc01de7b..38dac6d8 100644 --- a/src/Compiler/CodeFrame.php +++ b/src/Compiler/CodeFrame.php @@ -59,7 +59,7 @@ class CodeFrame "_template->source->filepath) + str_replace('*/', '* /', $this->_template->getSource()->filepath) ); $output .= "/* @var \\Smarty\\Template \$_smarty_tpl */\n"; $dec = "\$_smarty_tpl->isFresh(\$_smarty_tpl, " . var_export($properties, true) . ',' . @@ -67,13 +67,13 @@ class CodeFrame $output .= "if ({$dec}) {\n"; $output .= "function {$properties['unifunc']} (\\Smarty\\Template \$_smarty_tpl) {\n"; 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 .= ");\n"; } - if ($cache && $this->_template->smarty->hasRuntime('TplFunction')) { - $output .= "\$_smarty_tpl->smarty->getRuntime('TplFunction')->registerTplFunctions(\$_smarty_tpl, " . - var_export($this->_template->smarty->getRuntime('TplFunction')->getTplFunction($this->_template), true) . ");\n"; + if ($cache && $this->_template->getSmarty()->hasRuntime('TplFunction')) { + $output .= "\$_smarty_tpl->getSmarty()->getRuntime('TplFunction')->registerTplFunctions(\$_smarty_tpl, " . + var_export($this->_template->getSmarty()->getRuntime('TplFunction')->getTplFunction($this->_template), true) . ");\n"; } $output .= "?>"; $output .= $content; diff --git a/src/Compiler/Configfile.php b/src/Compiler/Configfile.php index 27a53dfc..1eaedb9f 100644 --- a/src/Compiler/Configfile.php +++ b/src/Compiler/Configfile.php @@ -82,11 +82,11 @@ class Configfile extends BaseCompiler { */ public function compileTemplate(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->source->getTimeStamp(), - $this->template->source->type, + $this->template->getSource()->filepath, + $this->template->getSource()->getTimeStamp(), + $this->template->getSource()->type, ]; if ($this->smarty->debugging) { $this->smarty->getDebug()->start_compile($this->template); @@ -100,7 +100,7 @@ class Configfile extends BaseCompiler { "\r", ], "\n", - $template->source->getContent() + $template->getSource()->getContent() ) . "\n", $this ); @@ -138,7 +138,7 @@ class Configfile extends BaseCompiler { "\n", \Smarty\Smarty::SMARTY_VERSION, date("Y-m-d H:i:s"), - str_replace('*/', '* /', $this->template->source->filepath) + str_replace('*/', '* /', $this->template->getSource()->filepath) ); $code = 'parent->assignConfigVars(' . 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); $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)) { // individual error message $error_text .= $args; diff --git a/src/Compiler/Template.php b/src/Compiler/Template.php index ba9b6606..32a5db3a 100644 --- a/src/Compiler/Template.php +++ b/src/Compiler/Template.php @@ -48,7 +48,7 @@ class Template extends BaseCompiler { * * @var \Smarty\Parser\TemplateParser */ - public $parser = null; + private $parser = null; /** * hash for nocache sections @@ -90,7 +90,7 @@ class Template extends BaseCompiler { * * @var \Smarty\Template */ - public $template = null; + private $template = null; /** * merged included sub template data @@ -153,7 +153,7 @@ class Template extends BaseCompiler { * * @var \Smarty\Compiler\Template */ - public $parent_compiler = null; + private $parent_compiler = null; /** * Flag true when compiling nocache section @@ -401,24 +401,24 @@ class Template extends BaseCompiler { $this->has_variable_string = false; $this->prefix_code = []; // add file dependency - if ($this->smarty->merge_compiled_includes || $this->template->source->handler->checkTimestamps()) { - $this->parent_compiler->template->getCompiled()->file_dependency[$this->template->source->uid] = + if ($this->smarty->merge_compiled_includes || $this->template->getSource()->handler->checkTimestamps()) { + $this->parent_compiler->getTemplate()->getCompiled()->file_dependency[$this->template->getSource()->uid] = [ - $this->template->source->filepath, - $this->template->source->getTimeStamp(), - $this->template->source->type, + $this->template->getSource()->filepath, + $this->template->getSource()->getTimeStamp(), + $this->template->getSource()->type, ]; } - $this->smarty->_current_file = $this->template->source->filepath; + $this->smarty->_current_file = $this->template->getSource()->filepath; // get template source - if (!empty($this->template->source->components)) { + if (!empty($this->template->getSource()->components)) { // we have array of inheritance templates by extends: resource // generate corresponding source code sequence $_content = ExtendsTag::extendsSourceArrayCode($this->template); } else { // get template source - $_content = $this->template->source->getContent(); + $_content = $this->template->getSource()->getContent(); } $_compiled_code = $this->smarty->runPostFilters( $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 // generate replacement code if (!empty($content) - && !($this->template->source->handler->recompiled) + && !($this->template->getSource()->handler->recompiled) && $this->caching && !$this->suppressNocacheProcessing && ($this->nocache || $this->tag_nocache) @@ -796,14 +796,14 @@ class Template extends BaseCompiler { $line = (int)$line; } if (in_array( - $this->template->source->type, + $this->template->getSource()->type, [ 'eval', 'string', ] ) ) { - $templateName = $this->template->source->type . ':' . trim( + $templateName = $this->template->getSource()->type . ':' . trim( preg_replace( '![\t\r\n]+!', ' ', @@ -813,7 +813,7 @@ class Template extends BaseCompiler { ) ); } else { - $templateName = $this->template->source->type . ':' . $this->template->source->filepath; + $templateName = $this->template->getSource()->type . ':' . $this->template->getSource()->filepath; } // $line += $this->trace_line_offset; $match = preg_split("/\n/", $lex->data); @@ -850,12 +850,12 @@ class Template extends BaseCompiler { $e = new CompilerException( $error_text, 0, - $this->template->source->filepath, + $this->template->getSource()->filepath, $line ); $e->source = trim(preg_replace('![\t\r\n]+!', ' ', $match[$line - 1])); $e->desc = $args; - $e->template = $this->template->source->filepath; + $e->template = $this->template->getSource()->filepath; throw $e; } @@ -1313,8 +1313,8 @@ class Template extends BaseCompiler { return isset($this->parent_compiler->tpl_function[$tag]) || ( - $this->template->smarty->hasRuntime('TplFunction') - && ($this->template->smarty->getRuntime('TplFunction')->getTplFunction($this->template, $tag) !== false) + $this->template->getSmarty()->hasRuntime('TplFunction') + && ($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 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; + } + } diff --git a/src/Data.php b/src/Data.php index b68153af..4b44969a 100644 --- a/src/Data.php +++ b/src/Data.php @@ -24,7 +24,7 @@ class Data * * @var Smarty */ - public $smarty = null; + protected $smarty = null; /** * template variables @@ -95,7 +95,7 @@ class Data switch ($scope) { case self::SCOPE_GLOBAL: case self::SCOPE_SMARTY: - $this->_getSmartyObj()->assign($tpl_var, $value); + $this->getSmarty()->assign($tpl_var, $value); break; case self::SCOPE_TPL_ROOT: $ptr = $this; @@ -180,7 +180,7 @@ class Data { trigger_error(__METHOD__ . " is deprecated. Use \\Smarty\\Smarty::assign() to assign a variable " . " 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); } - if ($errorEnable && $this->_getSmartyObj()->error_unassigned) { + if ($errorEnable && $this->getSmarty()->error_unassigned) { // force a notice $x = $$varName; } @@ -277,7 +277,7 @@ class Data // copy global config vars 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; } else { $this->config_vars[$variable] = array_merge((array)$this->config_vars[$variable], (array)$value); @@ -287,7 +287,7 @@ class Data foreach ($sections as $tpl_section) { if (isset($new_config_vars['sections'][$tpl_section])) { 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; } else { $this->config_vars[$variable] = array_merge((array)$this->config_vars[$variable], (array)$value); @@ -302,7 +302,7 @@ class Data * * @return Smarty */ - public function _getSmartyObj() + public function getSmarty() { return $this->smarty; } @@ -380,7 +380,7 @@ class Data $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"); } @@ -430,7 +430,7 @@ class Data */ 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->caching = Smarty::CACHING_OFF; $template->assign('sections', (array) $sections ?? []); diff --git a/src/Debug.php b/src/Debug.php index 0c237168..6a83b8f8 100644 --- a/src/Debug.php +++ b/src/Debug.php @@ -90,7 +90,7 @@ class Debug extends Data $this->saveTemplateData($_is_stringy, $template, $key); } } else { - if (isset($this->ignore_uid[ $template->source->uid ])) { + if (isset($this->ignore_uid[ $template->getSource()->uid ])) { return; } $key = $this->get_key($template); @@ -108,7 +108,7 @@ class Debug extends Data if (!empty($template->getCompiler()->trace_uid)) { $key = $template->getCompiler()->trace_uid; } else { - if (isset($this->ignore_uid[ $template->source->uid ])) { + if (isset($this->ignore_uid[ $template->getSource()->uid ])) { return; } $key = $this->get_key($template); @@ -197,7 +197,7 @@ class Debug extends Data $savedIndex = $this->index; $this->index = 9999; } - $smarty = $obj->_getSmartyObj(); + $smarty = $obj->getSmarty(); // create fresh instance of smarty for displaying the debug console // to avoid problems if the application did overload the Smarty class $debObj = new \Smarty\Smarty(); @@ -225,7 +225,7 @@ class Debug extends Data $debugging = $smarty->debugging; $_template = $debObj->createTemplate($debObj->debug_tpl); 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) { $_template->assign('template_data', $this->template_data[$this->index]); } else { @@ -307,10 +307,10 @@ class Debug extends Data { static $_is_stringy = array('string' => true, 'eval' => true); // calculate Uid if not already done - if ($template->source->uid === '') { - $template->source->filepath; + if ($template->getSource()->uid === '') { + $template->getSource()->filepath; } - $key = $template->source->uid; + $key = $template->getSource()->uid; if (isset($this->template_data[ $this->index ][ $key ])) { return $key; } else { @@ -328,10 +328,10 @@ class Debug extends Data public function ignore(\Smarty\Template $template) { // calculate Uid if not already done - if ($template->source->uid === '') { - $template->source->filepath; + if ($template->getSource()->uid === '') { + $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 */ 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'] = - '\'' . substr($template->source->name, 0, 25) . '...\''; + '\'' . substr($template->getSource()->name, 0, 25) . '...\''; } 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]['render_time'] = 0; diff --git a/src/FunctionHandler/Fetch.php b/src/FunctionHandler/Fetch.php index b4581a06..3031ac88 100644 --- a/src/FunctionHandler/Fetch.php +++ b/src/FunctionHandler/Fetch.php @@ -35,15 +35,15 @@ class Fetch extends Base { if ($protocol !== false) { $protocol = strtolower(substr($params['file'], 0, $protocol)); } - if (isset($template->smarty->security_policy)) { + if (isset($template->getSmarty()->security_policy)) { if ($protocol) { // remote resource (or php stream, …) - if (!$template->smarty->security_policy->isTrustedUri($params['file'])) { + if (!$template->getSmarty()->security_policy->isTrustedUri($params['file'])) { return; } } else { // local file - if (!$template->smarty->security_policy->isTrustedResourceDir($params['file'])) { + if (!$template->getSmarty()->security_policy->isTrustedResourceDir($params['file'])) { return; } } diff --git a/src/FunctionHandler/HtmlImage.php b/src/FunctionHandler/HtmlImage.php index 143c2e3b..a524eef9 100644 --- a/src/FunctionHandler/HtmlImage.php +++ b/src/FunctionHandler/HtmlImage.php @@ -99,15 +99,15 @@ class HtmlImage extends Base { if ($protocol !== false) { $protocol = strtolower(substr($params['file'], 0, $protocol)); } - if (isset($template->smarty->security_policy)) { + if (isset($template->getSmarty()->security_policy)) { if ($protocol) { // remote resource (or php stream, …) - if (!$template->smarty->security_policy->isTrustedUri($params['file'])) { + if (!$template->getSmarty()->security_policy->isTrustedUri($params['file'])) { return; } } else { // local file - if (!$template->smarty->security_policy->isTrustedResourceDir($_image_path)) { + if (!$template->getSmarty()->security_policy->isTrustedResourceDir($_image_path)) { return; } } diff --git a/src/Resource/ExtendsPlugin.php b/src/Resource/ExtendsPlugin.php index 3ca3f781..808a6a12 100644 --- a/src/Resource/ExtendsPlugin.php +++ b/src/Resource/ExtendsPlugin.php @@ -38,7 +38,7 @@ class ExtendsPlugin extends BasePlugin $uid = ''; $sources = array(); $components = explode('|', $source->name); - $smarty = &$source->smarty; + $smarty = $source->getSmarty(); $exists = true; foreach ($components as $component) { $_s = Source::load(null, $smarty, $component); @@ -53,7 +53,7 @@ class ExtendsPlugin extends BasePlugin } $source->components = $sources; $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; if ($_template) { $source->timestamp = $_s->timestamp; diff --git a/src/Resource/FilePlugin.php b/src/Resource/FilePlugin.php index 9ac304c6..481c2efb 100644 --- a/src/Resource/FilePlugin.php +++ b/src/Resource/FilePlugin.php @@ -34,13 +34,13 @@ class FilePlugin extends BasePlugin { public function populate(Source $source, Template $_template = null) { $source->filepath = $this->buildFilepath($source, $_template); if ($source->filepath !== false) { - if (isset($source->smarty->security_policy) && is_object($source->smarty->security_policy)) { - $source->smarty->security_policy->isTrustedResourceDir($source->filepath, $source->isConfig); + if (isset($source->getSmarty()->security_policy) && is_object($source->getSmarty()->security_policy)) { + $source->getSmarty()->security_policy->isTrustedResourceDir($source->filepath, $source->isConfig); } $source->exists = true; $source->uid = sha1( - $source->filepath . ($source->isConfig ? $source->smarty->_joined_config_dir : - $source->smarty->_joined_template_dir) + $source->filepath . ($source->isConfig ? $source->getSmarty()->_joined_config_dir : + $source->getSmarty()->_joined_template_dir) ); $source->timestamp = filemtime($source->filepath); } else { @@ -104,19 +104,19 @@ class FilePlugin extends BasePlugin { $file = $source->name; // absolute file ? if ($file[0] === '/' || $file[1] === ':') { - $file = $source->smarty->_realpath($file, true); + $file = $source->getSmarty()->_realpath($file, true); return is_file($file) ? $file : false; } // go relative to a given template? if ($file[0] === '.' && $_template && $_template->_isSubTpl() && preg_match('#^[.]{1,2}[\\\/]#', $file) ) { - if ($_template->parent->source->type !== 'file' && $_template->parent->source->type !== 'extends') { - throw new Exception("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'"); + 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->getSource()->type}'"); } // normalize 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 return is_file($path) ? $path : false; } @@ -124,7 +124,7 @@ class FilePlugin extends BasePlugin { if (strpos($file, DIRECTORY_SEPARATOR === '/' ? '\\' : '/') !== false) { $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? if ($file[0] === '[' && preg_match('#^\[([^\]]+)\](.+)$#', $file, $fileMatch)) { $file = $fileMatch[2]; @@ -160,12 +160,12 @@ class FilePlugin extends BasePlugin { foreach ($_directories as $_directory) { $path = $_directory . $file; 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)) { // Could be relative to cwd - $path = $source->smarty->_realpath($file, true); + $path = $source->getSmarty()->_realpath($file, true); if (is_file($path)) { return $path; } diff --git a/src/Resource/StringPlugin.php b/src/Resource/StringPlugin.php index 834e2234..a78bcc02 100644 --- a/src/Resource/StringPlugin.php +++ b/src/Resource/StringPlugin.php @@ -32,7 +32,7 @@ class StringPlugin extends BasePlugin { * @return void */ 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; } diff --git a/src/Runtime/InheritanceRuntime.php b/src/Runtime/InheritanceRuntime.php index 4c6ffa4e..b0ca670d 100644 --- a/src/Runtime/InheritanceRuntime.php +++ b/src/Runtime/InheritanceRuntime.php @@ -75,7 +75,7 @@ class InheritanceRuntime { return; } ++$this->tplIndex; - $this->sources[$this->tplIndex] = $tpl->source; + $this->sources[$this->tplIndex] = $tpl->getSource(); // start of child sub template(s) if ($initChild) { $this->state = 1; @@ -238,9 +238,9 @@ class InheritanceRuntime { * @param Template $tpl */ public function callBlock(\Smarty\Runtime\Block $block, Template $tpl) { - $this->sourceStack[] = $tpl->source; - $tpl->source = $this->sources[$block->tplIndex]; + $this->sourceStack[] = $tpl->getSource(); + $tpl->setSource($this->sources[$block->tplIndex]); $block->callBlock($tpl); - $tpl->source = array_pop($this->sourceStack); + $tpl->setSource(array_pop($this->sourceStack)); } } diff --git a/src/Runtime/TplFunctionRuntime.php b/src/Runtime/TplFunctionRuntime.php index f4abef38..905defb8 100644 --- a/src/Runtime/TplFunctionRuntime.php +++ b/src/Runtime/TplFunctionRuntime.php @@ -25,7 +25,7 @@ class TplFunctionRuntime { * @throws \Smarty\Exception */ 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 (!$tpl->caching || ($tpl->caching && $nocache)) { $function = $funcParam['call_name']; @@ -70,8 +70,8 @@ class TplFunctionRuntime { if ($obj->_isSubTpl()) { $this->registerTplFunctions($obj->parent, $tplFunctions, false); } else { - $obj->smarty->tplFunctions = $override ? array_merge($obj->smarty->tplFunctions, $tplFunctions) : - array_merge($tplFunctions, $obj->smarty->tplFunctions); + $obj->getSmarty()->tplFunctions = $override ? array_merge($obj->getSmarty()->tplFunctions, $tplFunctions) : + array_merge($tplFunctions, $obj->getSmarty()->tplFunctions); } } @@ -85,9 +85,9 @@ class TplFunctionRuntime { */ public function getTplFunction(Template $tpl, $name = null) { if (isset($name)) { - return $tpl->tplFunctions[$name] ?? ($tpl->smarty->tplFunctions[$name] ?? false); + return $tpl->tplFunctions[$name] ?? ($tpl->getSmarty()->tplFunctions[$name] ?? false); } else { - return empty($tpl->tplFunctions) ? $tpl->smarty->tplFunctions : $tpl->tplFunctions; + return empty($tpl->tplFunctions) ? $tpl->getSmarty()->tplFunctions : $tpl->tplFunctions; } } diff --git a/src/Smarty.php b/src/Smarty.php index 745376be..a23071fa 100644 --- a/src/Smarty.php +++ b/src/Smarty.php @@ -1024,7 +1024,7 @@ class Smarty extends \Smarty\TemplateBase $tpl->tplFunctions = array_merge($parent->tplFunctions ?? [], $tpl->tplFunctions ?? []); if (!$this->debugging && $this->debugging_ctrl === 'URL') { - $tpl->smarty->getDebug()->debugUrl($tpl->smarty); + $tpl->getSmarty()->getDebug()->debugUrl($tpl->getSmarty()); } return $tpl; } @@ -1062,7 +1062,7 @@ class Smarty extends \Smarty\TemplateBase $nameIsDotted = !empty($name) && $name[0] === '.' && ($name[1] === '.' || $name[1] === '/'); $id_parts[] = $type; - $id_parts[] = $this->_getSmartyObj()->_joined_template_dir; + $id_parts[] = $this->getSmarty()->_joined_template_dir; // handle relative template names if ($baseFilePath && $nameIsDotted) { @@ -1289,10 +1289,10 @@ class Smarty extends \Smarty\TemplateBase /** * Get Smarty object - * + * // @TODO this is silly, remove? * @return Smarty */ - public function _getSmartyObj() + public function getSmarty() { return $this; } @@ -1420,7 +1420,7 @@ class Smarty extends \Smarty\TemplateBase /* @var Template $tpl */ $tpl = $this->createTemplate($resource_name); $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_length = strlen($_resource_part_1); } else { @@ -1596,8 +1596,9 @@ class Smarty extends \Smarty\TemplateBase try { $_tpl = new \Smarty\Template($_file, $_smarty); $_tpl->caching = self::CACHING_OFF; - $_tpl->source = - $isConfig ? \Smarty\Template\Config::load($_tpl) : \Smarty\Template\Source::load($_tpl); + $_tpl->setSource( + $isConfig ? \Smarty\Template\Config::load($_tpl) : \Smarty\Template\Source::load($_tpl) + ); if ($_tpl->mustCompile()) { $_tpl->compileTemplateSource(); $_count++; diff --git a/src/Template.php b/src/Template.php index 0039d68f..e1316cfe 100644 --- a/src/Template.php +++ b/src/Template.php @@ -47,7 +47,7 @@ class Template extends TemplateBase { * * @var Source|Config */ - public $source = null; + private $source = null; /** * Template resource @@ -161,14 +161,14 @@ class Template extends TemplateBase { $this->smarty->getDebug()->start_template($this, $display); } // checks if template exists - if (!$this->source->exists) { + if (!$this->getSource()->exists) { 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}'" : '') ); } // disable caching for evaluated code - if ($this->source->handler->recompiled) { + if ($this->getSource()->handler->recompiled) { $this->caching = \Smarty\Smarty::CACHING_OFF; } // read from cache or render @@ -193,7 +193,7 @@ class Template extends TemplateBase { isset($content) ? $content : ob_get_clean() ); } 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']) ) { echo $this->smarty->runOutputFilters(ob_get_clean(), $this); @@ -216,7 +216,7 @@ class Template extends TemplateBase { } if ( !$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); @@ -252,9 +252,9 @@ class Template extends TemplateBase { $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 $tpl->tpl_vars = $this->tpl_vars; @@ -266,13 +266,14 @@ class Template extends TemplateBase { if (isset($uid) && $this->getCompiled()->file_dependency) { // for inline templates we can get all resource information from file dependency [$filepath, $timestamp, $type] = $this->getCompiled()->file_dependency[$uid]; - $tpl->source = new Source($this->_getSmartyObj(), $filepath, $type, $filepath); - $tpl->source->filepath = $filepath; - $tpl->source->timestamp = $timestamp; - $tpl->source->exists = true; - $tpl->source->uid = $uid; + $source = new Source($this->getSmarty(), $filepath, $type, $filepath); + $source->filepath = $filepath; + $source->timestamp = $timestamp; + $source->exists = true; + $source->uid = $uid; + $tpl->setSource($source); } 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 } if ($caching !== \Smarty\Template::CACHING_NOCACHE_CODE) { @@ -292,7 +293,7 @@ class Template extends TemplateBase { } } if (isset($uid)) { - $smarty = $this->_getSmartyObj(); + $smarty = $this->getSmarty(); if ($smarty->debugging) { $smarty->getDebug()->start_template($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 if (!isset($properties['version']) || \Smarty\Smarty::SMARTY_VERSION !== $properties['version']) { if ($cache) { - $tpl->smarty->clearAllCache(); + $tpl->getSmarty()->clearAllCache(); } else { - $tpl->smarty->clearCompiledTemplate(); + $tpl->getSmarty()->clearCompiledTemplate(); } return false; } @@ -359,18 +360,18 @@ class Template extends TemplateBase { // check file dependencies at compiled code foreach ($properties['file_dependency'] as $_file_to_check) { 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 continue; - //$mtime = $tpl->source->getTimeStamp(); + //$mtime = $tpl->getSource()->getTimeStamp(); } else { // 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; } } 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()) { - $source = Source::load($tpl, $tpl->smarty, $_file_to_check[0]); + $source = Source::load($tpl, $tpl->getSmarty(), $_file_to_check[0]); $mtime = $source->getTimeStamp(); } else { continue; @@ -415,6 +416,16 @@ class Template extends TemplateBase { 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 * @@ -423,7 +434,7 @@ class Template extends TemplateBase { * @return bool */ public function writeCachedContent($content) { - if ($this->source->handler->recompiled || !$this->caching + if ($this->getSource()->handler->recompiled || !$this->caching ) { // don't write cache file return false; @@ -472,17 +483,23 @@ class Template extends TemplateBase { */ public function getCached($forceNew = false): Cached { if ($forceNew || !isset($this->cached)) { - $this->cached = new Cached($this); - $this->cached->handler->populate($this->cached, $this); + $cacheResource = $this->smarty->getCacheResource(); + $this->cached = new Cached( + $this->source, + $cacheResource, + $this->compile_id, + $this->cache_id + ); + $cacheResource->populate($this->cached, $this); if (!$this->isCachingEnabled()) { - $this->cached->valid = false; + $this->cached->setValid(false); } } return $this->cached; } 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 */ 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() { if (!isset($this->compiler)) { - $this->compiler = $this->source->createCompiler(); + $this->compiler = $this->getSource()->createCompiler(); } return $this->compiler; } @@ -546,19 +563,19 @@ class Template extends TemplateBase { * @throws \Smarty\Exception */ public function mustCompile() { - if (!$this->source->exists) { + if (!$this->getSource()->exists) { if ($this->_isSubTpl()) { $parent_resource = " in '{$this->parent->template_resource}'"; } else { $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) { $this->mustCompile = $this->smarty->force_compile - || $this->source->handler->recompiled + || $this->getSource()->handler->recompiled || !$this->getCompiled()->exists - || ($this->compile_check && $this->getCompiled()->getTimeStamp() < $this->source->getTimeStamp()); + || ($this->compile_check && $this->getCompiled()->getTimeStamp() < $this->getSource()->getTimeStamp()); } return $this->mustCompile; } @@ -574,7 +591,7 @@ class Template extends TemplateBase { */ 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() { - return $this->right_delimiter ?? $this->_getSmartyObj()->getRightDelimiter();; + return $this->right_delimiter ?? $this->getSmarty()->getRightDelimiter();; } /** @@ -627,7 +644,7 @@ class Template extends TemplateBase { fclose($fp); return $_result; } - if ($this->_getSmartyObj()->error_unassigned) { + if ($this->getSmarty()->error_unassigned) { throw new Exception('Undefined stream variable "' . $variable . '"'); } return null; @@ -639,8 +656,8 @@ class Template extends TemplateBase { { $confObj = parent::configLoad($config_file, $sections); - $this->getCompiled()->file_dependency[ $confObj->source->uid ] = - array($confObj->source->filepath, $confObj->source->getTimeStamp(), $confObj->source->type); + $this->getCompiled()->file_dependency[ $confObj->getSource()->uid ] = + array($confObj->getSource()->filepath, $confObj->getSource()->getTimeStamp(), $confObj->getSource()->type); return $confObj; } @@ -683,7 +700,7 @@ class Template extends TemplateBase { */ private function _execute($function) { - $smarty = $this->_getSmartyObj(); + $smarty = $this->getSmarty(); // make sure we have integer values $this->caching = (int)$this->caching; @@ -773,10 +790,24 @@ class Template extends TemplateBase { while (ob_get_level() > $level) { ob_end_clean(); } - if (isset($this->_getSmartyObj()->security_policy)) { - $this->_getSmartyObj()->security_policy->endTemplate(); + if (isset($this->getSmarty()->security_policy)) { + $this->getSmarty()->security_policy->endTemplate(); } 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; + } } diff --git a/src/Template/Cached.php b/src/Template/Cached.php index 65860447..26e38a55 100644 --- a/src/Template/Cached.php +++ b/src/Template/Cached.php @@ -2,7 +2,9 @@ namespace Smarty\Template; +use Smarty\Exception; use Smarty\Template; +use Smarty\Template\Cacheresource\Base; /** * Represents a cached version of a template or config file. @@ -17,6 +19,20 @@ class Cached extends GeneratedPhpFile { */ 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 * @@ -81,15 +97,16 @@ class Cached extends GeneratedPhpFile { /** * create Cached Object container * - * @param Template $_template template object - * - * @throws \Smarty\Exception + * @param Source $source + * @param \Smarty\Cacheresource\Base $handler + * @param $compile_id + * @param $cache_id */ - public function __construct(Template $_template) { - $this->compile_id = $_template->compile_id; - $this->cache_id = $_template->cache_id; - $this->source = $_template->source; - $this->handler = $_template->smarty->getCacheResource(); + public function __construct(Source $source, \Smarty\Cacheresource\Base $handler, $compile_id, $cache_id) { + $this->compile_id = $compile_id; + $this->cache_id = $cache_id; + $this->source = $source; + $this->handler = $handler; } /** @@ -102,15 +119,15 @@ class Cached extends GeneratedPhpFile { */ public function render(Template $_template, $no_output_filter = true) { if ($this->isCached($_template)) { - if ($_template->smarty->debugging) { - $_template->smarty->getDebug()->start_cache($_template); + if ($_template->getSmarty()->debugging) { + $_template->getSmarty()->getDebug()->start_cache($_template); } if (!$this->processed) { $this->process($_template); } $this->renderTemplateCode($_template); - if ($_template->smarty->debugging) { - $_template->smarty->getDebug()->end_cache($_template); + if ($_template->getSmarty()->debugging) { + $_template->getSmarty()->getDebug()->end_cache($_template); } return; } else { @@ -121,9 +138,10 @@ class Cached extends GeneratedPhpFile { /** * Check if cache is valid, lock cache if required * - * @param \Smarty\Template $_template + * @param Template $_template * * @return bool flag true if cache is valid + * @throws Exception */ public function isCached(Template $_template) { if ($this->valid !== null) { @@ -131,7 +149,7 @@ class Cached extends GeneratedPhpFile { } 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; } else { $this->valid = true; @@ -143,32 +161,32 @@ class Cached extends GeneratedPhpFile { $this->valid = false; } if ($this->valid && $_template->compile_check === \Smarty\Smarty::COMPILECHECK_ON - && $_template->source->getTimeStamp() > $this->timestamp + && $_template->getSource()->getTimeStamp() > $this->timestamp ) { $this->valid = false; } - if ($this->valid || !$_template->smarty->cache_locking) { + if ($this->valid || !$_template->getSmarty()->cache_locking) { break; } - if (!$this->handler->locked($_template->smarty, $this)) { - $this->handler->acquireLock($_template->smarty, $this); + if (!$this->handler->locked($_template->getSmarty(), $this)) { + $this->handler->acquireLock($_template->getSmarty(), $this); break 2; } $this->handler->populate($this, $_template); } 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 - if ($_template->smarty->debugging) { - $_template->smarty->getDebug()->start_cache($_template); + if ($_template->getSmarty()->debugging) { + $_template->getSmarty()->getDebug()->start_cache($_template); } if ($this->handler->process($_template, $this) === false) { $this->valid = false; } else { $this->processed = true; } - if ($_template->smarty->debugging) { - $_template->smarty->getDebug()->end_cache($_template); + if ($_template->getSmarty()->debugging) { + $_template->getSmarty()->getDebug()->end_cache($_template); } } else { $this->is_locked = true; @@ -183,11 +201,11 @@ class Cached extends GeneratedPhpFile { ) { $this->valid = false; } - if ($_template->smarty->cache_locking) { + if ($_template->getSmarty()->cache_locking) { if (!$this->valid) { - $this->handler->acquireLock($_template->smarty, $this); + $this->handler->acquireLock($_template->getSmarty(), $this); } elseif ($this->is_locked) { - $this->handler->releaseLock($_template->smarty, $this); + $this->handler->releaseLock($_template->getSmarty(), $this); } } return $this->valid; @@ -220,7 +238,7 @@ class Cached extends GeneratedPhpFile { * @return string|false content */ public function readCache(Template $_template) { - if (!$_template->source->handler->recompiled) { + if (!$_template->getSource()->handler->recompiled) { return $this->handler->retrieveCachedContent($_template); } return false; @@ -234,7 +252,7 @@ class Cached extends GeneratedPhpFile { * @return bool success */ public function writeCache(Template $_template, $content) { - if (!$_template->source->handler->recompiled) { + if (!$_template->getSource()->handler->recompiled) { if ($this->handler->storeCachedContent($_template, $content)) { $this->content = null; $this->timestamp = time(); @@ -242,8 +260,8 @@ class Cached extends GeneratedPhpFile { $this->valid = true; $this->cache_lifetime = $_template->cache_lifetime; $this->processed = false; - if ($_template->smarty->cache_locking) { - $this->handler->releaseLock($_template->smarty, $this); + if ($_template->getSmarty()->cache_locking) { + $this->handler->releaseLock($_template->getSmarty(), $this); } return true; } @@ -268,8 +286,8 @@ class Cached extends GeneratedPhpFile { ob_start(); $_template->getCompiled()->render($_template); - if ($_template->smarty->debugging) { - $_template->smarty->getDebug()->start_cache($_template); + if ($_template->getSmarty()->debugging) { + $_template->getSmarty()->getDebug()->start_cache($_template); } $this->removeNoCacheHash($_template, $no_output_filter); $compile_check = (int)$_template->compile_check; @@ -282,8 +300,8 @@ class Cached extends GeneratedPhpFile { } $_template->compile_check = $compile_check; $this->renderTemplateCode($_template); - if ($_template->smarty->debugging) { - $_template->smarty->getDebug()->end_cache($_template); + if ($_template->getSmarty()->debugging) { + $_template->getSmarty()->getDebug()->end_cache($_template); } } @@ -347,10 +365,24 @@ class Cached extends GeneratedPhpFile { !$no_output_filter && !$_template->getCached()->getNocacheCode() ) { - $content = $_template->smarty->runOutputFilters($content, $_template); + $content = $_template->getSmarty()->runOutputFilters($content, $_template); } // write cache file 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; + } + } diff --git a/src/Template/Compiled.php b/src/Template/Compiled.php index 8bfc616c..4e1d51aa 100644 --- a/src/Template/Compiled.php +++ b/src/Template/Compiled.php @@ -35,7 +35,7 @@ class Compiled extends GeneratedPhpFile { */ public static function load($_template) { $compiled = new Compiled(); - if ($_template->source->handler->supportsCompiledTemplates()) { + if ($_template->getSource()->handler->supportsCompiledTemplates()) { $compiled->populateCompiledFilepath($_template); } return $compiled; @@ -47,8 +47,8 @@ class Compiled extends GeneratedPhpFile { * @param Template $_template template object **/ private function populateCompiledFilepath(Template $_template) { - $source = &$_template->source; - $smarty = &$_template->smarty; + $source = $_template->getSource(); + $smarty = $_template->getSmarty(); $this->filepath = $smarty->getCompileDir(); if (isset($_template->compile_id)) { $this->filepath .= preg_replace('![^\w]+!', '_', $_template->compile_id) . @@ -93,12 +93,12 @@ class Compiled extends GeneratedPhpFile { */ public function render(Template $_template) { // checks if template exists - if (!$_template->source->exists) { - $type = $_template->source->isConfig ? 'config' : 'template'; - throw new \Smarty\Exception("Unable to load {$type} '{$_template->source->type}:{$_template->source->name}'"); + if (!$_template->getSource()->exists) { + $type = $_template->getSource()->isConfig ? 'config' : 'template'; + throw new \Smarty\Exception("Unable to load {$type} '{$_template->getSource()->type}:{$_template->getSource()->name}'"); } - if ($_template->smarty->debugging) { - $_template->smarty->getDebug()->start_render($_template); + if ($_template->getSmarty()->debugging) { + $_template->getSmarty()->getDebug()->start_render($_template); } if (!$this->processed) { $this->process($_template); @@ -112,8 +112,8 @@ class Compiled extends GeneratedPhpFile { if ($_template->caching && $this->getNocacheCode()) { $_template->getCached()->hashes[$this->nocache_hash] = true; } - if ($_template->smarty->debugging) { - $_template->smarty->getDebug()->end_render($_template); + if ($_template->getSmarty()->debugging) { + $_template->getSmarty()->getDebug()->end_render($_template); } } @@ -125,8 +125,8 @@ class Compiled extends GeneratedPhpFile { * @throws Exception */ private function process(Template $_smarty_tpl) { - $source = &$_smarty_tpl->source; - $smarty = &$_smarty_tpl->smarty; + $source = $_smarty_tpl->getSource(); + $smarty = $_smarty_tpl->getSmarty(); if ($source->handler->recompiled) { $source->handler->process($_smarty_tpl); } else { @@ -166,7 +166,7 @@ class Compiled extends GeneratedPhpFile { $this->nocache_hash = null; $this->unifunc = null; // 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(); touch($this->filepath); } @@ -193,8 +193,8 @@ class Compiled extends GeneratedPhpFile { * @throws \Smarty\Exception */ public function write(Template $_template, $code) { - if (!$_template->source->handler->recompiled) { - if ($_template->smarty->writeFile($this->filepath, $code) === true) { + if (!$_template->getSource()->handler->recompiled) { + if ($_template->getSmarty()->writeFile($this->filepath, $code) === true) { $this->timestamp = $this->exists = is_file($this->filepath); if ($this->exists) { $this->timestamp = filemtime($this->filepath); @@ -214,7 +214,7 @@ class Compiled extends GeneratedPhpFile { * @return string content */ public function read(Template $_template) { - if (!$_template->source->handler->recompiled) { + if (!$_template->getSource()->handler->recompiled) { return file_get_contents($this->filepath); } return false; diff --git a/src/Template/Config.php b/src/Template/Config.php index ecaedfb7..7d55e7eb 100644 --- a/src/Template/Config.php +++ b/src/Template/Config.php @@ -39,7 +39,7 @@ class Config extends Source { ) { static $_incompatible_resources = ['extends' => true, 'php' => true]; if ($_template) { - $smarty = $_template->smarty; + $smarty = $_template->getSmarty(); $template_resource = $_template->template_resource; } if (empty($template_resource)) { diff --git a/src/Template/Source.php b/src/Template/Source.php index 918a4bde..72d3f531 100644 --- a/src/Template/Source.php +++ b/src/Template/Source.php @@ -87,7 +87,7 @@ class Source { * * @var Smarty */ - public $smarty = null; + protected $smarty = null; /** * Resource is source @@ -140,7 +140,7 @@ class Source { $template_resource = null ) { if ($_template) { - $smarty = $_template->smarty; + $smarty = $_template->getSmarty(); $template_resource = $_template->template_resource; } if (empty($template_resource)) { @@ -159,8 +159,8 @@ class Source { // create new source object $source = new Source($smarty, $template_resource, $type, $name); $source->handler->populate($source, $_template); - if (!$source->exists && isset($_template->smarty->default_template_handler_func)) { - $source->_getDefaultTemplate($_template->smarty->default_template_handler_func); + if (!$source->exists && $_template && isset($_template->getSmarty()->default_template_handler_func)) { + $source->_getDefaultTemplate($_template->getSmarty()->default_template_handler_func); $source->handler->populate($source, $_template); } return $source; @@ -230,4 +230,8 @@ class Source { return new \Smarty\Compiler\Template($this->smarty); } + public function getSmarty() { + return $this->smarty; + } + } diff --git a/src/TemplateBase.php b/src/TemplateBase.php index 28b7b514..a61e5254 100644 --- a/src/TemplateBase.php +++ b/src/TemplateBase.php @@ -93,7 +93,7 @@ abstract class TemplateBase extends Data { $format = true, $block_methods = [] ) { - $smarty = $this->_getSmartyObj(); + $smarty = $this->getSmarty(); // test if allowed methods callable if (!empty($allowed_methods_properties)) { foreach ((array)$allowed_methods_properties as $method) { @@ -127,7 +127,7 @@ abstract class TemplateBase extends Data { * */ public function unregisterObject($object_name) { - $smarty = $this->_getSmartyObj(); + $smarty = $this->getSmarty(); if (isset($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) { /* @var Smarty $smarty */ - $smarty = $this->_getSmartyObj(); + $smarty = $this->getSmarty(); $dataObj = new Data($parent, $smarty, $name); if ($smarty->debugging) { $smarty->getDebug()->register_data($dataObj); @@ -207,7 +207,7 @@ abstract class TemplateBase extends Data { * */ public function getDebugTemplate() { - $smarty = $this->_getSmartyObj(); + $smarty = $this->getSmarty(); return $smarty->debug_tpl; } @@ -234,7 +234,7 @@ abstract class TemplateBase extends Data { * @api Smarty::getRegisteredObject() */ public function getRegisteredObject($object_name) { - $smarty = $this->_getSmartyObj(); + $smarty = $this->getSmarty(); if (!isset($smarty->registered_objects[$object_name])) { throw new Exception("'$object_name' is not a registered object"); } @@ -252,7 +252,7 @@ abstract class TemplateBase extends Data { * */ public function getLiterals() { - $smarty = $this->_getSmartyObj(); + $smarty = $this->getSmarty(); return (array)$smarty->literals; } @@ -269,7 +269,7 @@ abstract class TemplateBase extends Data { */ public function addLiterals($literals = null) { if (isset($literals)) { - $this->_setLiterals($this->_getSmartyObj(), (array)$literals); + $this->_setLiterals($this->getSmarty(), (array)$literals); } return $this; } @@ -286,7 +286,7 @@ abstract class TemplateBase extends Data { * */ public function setLiterals($literals = null) { - $smarty = $this->_getSmartyObj(); + $smarty = $this->getSmarty(); $smarty->literals = []; if (!empty($literals)) { $this->_setLiterals($smarty, (array)$literals); @@ -330,7 +330,7 @@ abstract class TemplateBase extends Data { * */ public function registerClass($class_name, $class_impl) { - $smarty = $this->_getSmartyObj(); + $smarty = $this->getSmarty(); // test if exists if (!class_exists($class_impl)) { throw new Exception("Undefined class '$class_impl' in register template class"); @@ -351,7 +351,7 @@ abstract class TemplateBase extends Data { * */ public function registerDefaultConfigHandler($callback) { - $smarty = $this->_getSmartyObj(); + $smarty = $this->getSmarty(); if (is_callable($callback)) { $smarty->default_config_handler_func = $callback; } else { @@ -371,7 +371,7 @@ abstract class TemplateBase extends Data { * */ public function registerDefaultTemplateHandler($callback) { - $smarty = $this->_getSmartyObj(); + $smarty = $this->getSmarty(); if (is_callable($callback)) { $smarty->default_template_handler_func = $callback; } else { @@ -392,7 +392,7 @@ abstract class TemplateBase extends Data { * @api Smarty::registerResource() */ public function registerResource($name, \Smarty\Resource\BasePlugin $resource_handler) { - $smarty = $this->_getSmartyObj(); + $smarty = $this->getSmarty(); $smarty->registered_resources[$name] = $resource_handler; return $this; } @@ -408,7 +408,7 @@ abstract class TemplateBase extends Data { * */ public function unregisterResource($type) { - $smarty = $this->_getSmartyObj(); + $smarty = $this->getSmarty(); if (isset($smarty->registered_resources[$type])) { unset($smarty->registered_resources[$type]); } @@ -426,7 +426,7 @@ abstract class TemplateBase extends Data { * */ public function setDebugTemplate($tpl_name) { - $smarty = $this->_getSmartyObj(); + $smarty = $this->getSmarty(); if (!is_readable($tpl_name)) { throw new Exception("Unknown file '{$tpl_name}'"); } diff --git a/tests/PHPUnit_Smarty.php b/tests/PHPUnit_Smarty.php index b8d45a51..c75a8232 100644 --- a/tests/PHPUnit_Smarty.php +++ b/tests/PHPUnit_Smarty.php @@ -256,7 +256,7 @@ KEY `name` (`name`) */ public function cleanCompileDir() { - $smarty = $this->getSmartyObj(); + $smarty = $this->getSmarty(); if (isset($smarty)) { $dir = $smarty->getCompileDir(); $this->cleanDir($dir); @@ -269,7 +269,7 @@ KEY `name` (`name`) */ public function cleanCacheDir() { - $smarty = $this->getSmartyObj(); + $smarty = $this->getSmarty(); if (isset($smarty)) { $dir = $smarty->getCacheDir(); $this->cleanDir($dir); @@ -356,8 +356,8 @@ KEY `name` (`name`) */ public function buildSourcePath($tpl, $name = null, $type = null, $dir = null) { - $name = isset($name) ? $name : $tpl->source->name; - $type = isset($type) ? $type : $tpl->source->type; + $name = isset($name) ? $name : $tpl->getSource()->name; + $type = isset($type) ? $type : $tpl->getSource()->type; $dir = isset($dir) ? $dir : $this->smarty->getTemplateDir(0); switch ($type) { case 'file': @@ -388,8 +388,8 @@ KEY `name` (`name`) */ public function buildUid($tpl, $value = null, $name = null, $type = null) { - $type = isset($type) ? $type : $tpl->source->type; - $name = isset($name) ? $name : $tpl->source->name; + $type = isset($type) ? $type : $tpl->getSource()->type; + $name = isset($name) ? $name : $tpl->getSource()->name; switch ($type) { case 'php': case 'file': @@ -398,7 +398,7 @@ KEY `name` (`name`) return sha1($this->normalizePath($this->smarty->getTemplateDir(0) . $name) . $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 'mysql': return sha1($type . ':' . $name); @@ -459,8 +459,8 @@ KEY `name` (`name`) */ public function getBasename(Template $tpl, $name = null, $type = null) { - $name = isset($name) ? $name : $tpl->source->name; - $type = isset($type) ? $type : $tpl->source->type; + $name = isset($name) ? $name : $tpl->getSource()->name; + $type = isset($type) ? $type : $tpl->getSource()->type; switch ($type) { case 'file': case 'filetest': @@ -500,11 +500,11 @@ KEY `name` (`name`) $sp = $this->buildSourcePath($tpl, $name, $type, $dir); $uid = $this->buildUid($tpl, $sp, $name, $type); $_flag = ''; - if (isset($tpl->source) && $tpl->source->isConfig) { - $_flag = '_' . ((int) $tpl->smarty->config_read_hidden + (int) $tpl->smarty->config_booleanize * 2 + - (int) $tpl->smarty->config_overwrite * 4); + if ($tpl->getSource() && $tpl->getSource()->isConfig) { + $_flag = '_' . ((int) $tpl->getSmarty()->config_read_hidden + (int) $tpl->getSmarty()->config_booleanize * 2 + + (int) $tpl->getSmarty()->config_overwrite * 4); } 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; // if use_sub_dirs, break file into directories @@ -523,7 +523,7 @@ KEY `name` (`name`) } else { $_cache = ''; } - $_compile_dir = $tpl->smarty->getCompileDir(); + $_compile_dir = $tpl->getSmarty()->getCompileDir(); // set basename if not specified $_basename = $this->getBasename($tpl, $name, $type); if ($_basename === null) { @@ -552,10 +552,10 @@ KEY `name` (`name`) * @return string * @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) { - $cacheType = $cacheType ?? $tpl->smarty->getCachingType(); + $cacheType = $cacheType ?? $tpl->getSmarty()->getCachingType(); switch ($cacheType) { case 'file': case 'filetest': @@ -582,9 +582,7 @@ KEY `name` (`name`) } else { $_compile_id = ''; } - $smarty = isset($tpl->smarty) ? $tpl->smarty : $tpl; - $_cache_dir = $smarty->getCacheDir(); - return $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($sp) . '.php'; + return $tpl->getSmarty()->getCacheDir() . $_cache_id . $_compile_id . $_filepath . '.' . basename($sp) . '.php'; case 'mysqltest': case 'pdo': case 'foobar': @@ -625,7 +623,7 @@ KEY `name` (`name`) * Gat Smarty object * @return null|\Smarty */ - public function getSmartyObj(){ + public function getSmarty(){ return $this->smarty; } @@ -636,18 +634,4 @@ KEY `name` (`name`) 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; - } - } } diff --git a/tests/UnitTests/CacheResourceTests/Memcache/CacheResourceCustomMemcacheTest.php b/tests/UnitTests/CacheResourceTests/Memcache/CacheResourceCustomMemcacheTest.php index 49e23f7f..865f427d 100644 --- a/tests/UnitTests/CacheResourceTests/Memcache/CacheResourceCustomMemcacheTest.php +++ b/tests/UnitTests/CacheResourceTests/Memcache/CacheResourceCustomMemcacheTest.php @@ -47,7 +47,7 @@ class CacheResourceCustomMemcacheTest extends CacheResourceTestCommon $this->smarty->caching = true; $this->smarty->cache_lifetime = 1000; $tpl = $this->smarty->createTemplate('helloworld.tpl'); - $sha1 = $tpl->source->uid . '#helloworld_tpl##'; + $sha1 = $tpl->getSource()->uid . '#helloworld_tpl##'; $this->assertEquals($sha1, $tpl->getCached()->filepath); } @@ -59,7 +59,7 @@ class CacheResourceCustomMemcacheTest extends CacheResourceTestCommon $this->smarty->caching = true; $this->smarty->cache_lifetime = 1000; $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); } @@ -71,7 +71,7 @@ class CacheResourceCustomMemcacheTest extends CacheResourceTestCommon $this->smarty->caching = true; $this->smarty->cache_lifetime = 1000; $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); } @@ -83,7 +83,7 @@ class CacheResourceCustomMemcacheTest extends CacheResourceTestCommon $this->smarty->caching = true; $this->smarty->cache_lifetime = 1000; $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); } } diff --git a/tests/UnitTests/CacheResourceTests/_shared/CacheResourceTestCommon.php b/tests/UnitTests/CacheResourceTests/_shared/CacheResourceTestCommon.php index 6e489dde..3b1ebaa1 100644 --- a/tests/UnitTests/CacheResourceTests/_shared/CacheResourceTestCommon.php +++ b/tests/UnitTests/CacheResourceTests/_shared/CacheResourceTestCommon.php @@ -91,7 +91,7 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty $this->smarty->cache_lifetime = 1000; $tpl = $this->smarty->createTemplate('helloworld.tpl', 'foo|bar', 'blar'); $tpl->writeCachedContent('hello world'); - $this->assertEquals('hello world', $tpl->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 //$this->assertEquals(-1, $this->smarty->clearAllCache()); } @@ -112,15 +112,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3->writeCachedContent('hello world 3'); // test cached content - $this->assertEquals('hello world 1', $tpl->getCached()->handler->getCachedContent($tpl)); - $this->assertEquals('hello world 2', $tpl->getCached()->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world 3', $tpl->getCached()->handler->getCachedContent($tpl3)); + $this->assertEquals('hello world 1', $tpl->getCachedContent($tpl)); + $this->assertEquals('hello world 2', $tpl2->getCachedContent($tpl2)); + $this->assertEquals('hello world 3', $tpl3->getCachedContent($tpl3)); // test number of deleted caches $this->doClearCacheAssertion(2, $this->smarty->clearCache(null, 'foo|bar')); // test that caches are deleted properly - $this->assertNull($tpl->getCached()->handler->getCachedContent($tpl)); - $this->assertEquals('hello world 2', $tpl->getCached()->handler->getCachedContent($tpl2)); - $this->assertNull($tpl->getCached()->handler->getCachedContent($tpl3)); + $this->assertNull($tpl->getCachedContent($tpl)); + $this->assertEquals('hello world 2', $tpl->getCachedContent($tpl2)); + $this->assertNull($tpl->getCachedContent($tpl3)); } public function testClearCacheCacheIdCompileId2() @@ -136,15 +136,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl2)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); // test number of deleted caches $this->doClearCacheAssertion(2, $this->smarty->clearCache('helloworld.tpl')); // test that caches are deleted properly - $this->assertNull($tpl->getCached()->handler->getCachedContent($tpl)); - $this->assertNull($tpl->getCached()->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); + $this->assertNull($tpl->getCachedContent($tpl)); + $this->assertNull($tpl->getCachedContent($tpl2)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); } public function testClearCacheCacheIdCompileId2Sub() @@ -160,15 +160,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl2)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); // test number of deleted caches $this->doClearCacheAssertion(2, $this->smarty->clearCache('helloworld.tpl')); // test that caches are deleted properly - $this->assertNull($tpl->getCached()->handler->getCachedContent($tpl)); - $this->assertNull($tpl->getCached()->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); + $this->assertNull($tpl->getCachedContent($tpl)); + $this->assertNull($tpl->getCachedContent($tpl2)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); } public function testClearCacheCacheIdCompileId3() @@ -184,15 +184,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl2)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); // test number of deleted caches $this->doClearCacheAssertion(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2')); // test that caches are deleted properly - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); - $this->assertNull($tpl->getCached()->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); + $this->assertNull($tpl->getCachedContent($tpl2)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); } public function testClearCacheCacheIdCompileId3Sub() @@ -208,15 +208,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl2)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); // test number of deleted caches $this->doClearCacheAssertion(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2')); // test that caches are deleted properly - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); - $this->assertNull($tpl->getCached()->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); + $this->assertNull($tpl->getCachedContent($tpl2)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); } public function testClearCacheCacheIdCompileId4() @@ -232,15 +232,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl2)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); // test number of deleted caches $this->doClearCacheAssertion(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2')); // test that caches are deleted properly - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); - $this->assertNull($tpl->getCached()->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); + $this->assertNull($tpl->getCachedContent($tpl2)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); } public function testClearCacheCacheIdCompileId4Sub() @@ -256,15 +256,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl2)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); // test number of deleted caches $this->doClearCacheAssertion(1, $this->smarty->clearCache('helloworld.tpl', null, 'blar2')); // test that caches are deleted properly - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); - $this->assertNull($tpl->getCached()->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); + $this->assertNull($tpl->getCachedContent($tpl2)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); } public function testClearCacheCacheIdCompileId5() @@ -280,15 +280,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl2)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); // test number of deleted caches $this->doClearCacheAssertion(2, $this->smarty->clearCache(null, null, 'blar')); // test that caches are deleted properly - $this->assertNull($tpl->getCached()->handler->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2)); - $this->assertNull($tpl->getCached()->handler->getCachedContent($tpl3)); + $this->assertNull($tpl->getCachedContent($tpl)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl2)); + $this->assertNull($tpl->getCachedContent($tpl3)); } public function testClearCacheCacheIdCompileId5Sub() @@ -304,15 +304,15 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty $tpl3 = $this->smarty->createTemplate('helloworld2.tpl', 'foo|bar', 'blar'); $tpl3->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl2)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); // test number of deleted caches $this->doClearCacheAssertion(2, $this->smarty->clearCache(null, null, 'blar')); // test that caches are deleted properly - $this->assertNull($tpl->getCached()->handler->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2)); - $this->assertNull($tpl->getCached()->handler->getCachedContent($tpl3)); + $this->assertNull($tpl->getCachedContent($tpl)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl2)); + $this->assertNull($tpl->getCachedContent($tpl3)); } public function testClearCacheCacheFile() @@ -330,17 +330,17 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty $tpl4 = $this->smarty->createTemplate('helloworld2.tpl'); $tpl4->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl4)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl2)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl4)); // test number of deleted caches $this->doClearCacheAssertion(3, $this->smarty->clearCache('helloworld.tpl')); // test that caches are deleted properly - $this->assertNull($tpl->getCached()->handler->getCachedContent($tpl)); - $this->assertNull($tpl->getCached()->handler->getCachedContent($tpl2)); - $this->assertNull($tpl->getCached()->handler->getCachedContent($tpl3)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl4)); + $this->assertNull($tpl->getCachedContent($tpl)); + $this->assertNull($tpl->getCachedContent($tpl2)); + $this->assertNull($tpl->getCachedContent($tpl3)); + $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->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl2)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); sleep(10); $tpl4 = $this->smarty->createTemplate('helloworld2.tpl'); $tpl4->writeCachedContent('hello world'); // test number of deleted caches $this->doClearCacheAssertion(3,$this->smarty->clearAllCache(5)); // test that caches are deleted properly - $this->assertNull($tpl->getCached()->handler->getCachedContent($tpl)); - $this->assertNull($tpl->getCached()->handler->getCachedContent($tpl2)); - $this->assertNull($tpl->getCached()->handler->getCachedContent($tpl3)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl4)); + $this->assertNull($tpl->getCachedContent($tpl)); + $this->assertNull($tpl->getCachedContent($tpl2)); + $this->assertNull($tpl->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl4)); } public function testClearCacheCacheFileSub() @@ -389,17 +389,17 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty $tpl4 = $this->smarty->createTemplate('helloworld2.tpl'); $tpl4->writeCachedContent('hello world'); // test cached content - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl2)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl3)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl4)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl2)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl4)); // test number of deleted caches $this->doClearCacheAssertion(3, $this->smarty->clearCache('helloworld.tpl')); // test that caches are deleted properly - $this->assertNull($tpl->getCached()->handler->getCachedContent($tpl)); - $this->assertNull($tpl->getCached()->handler->getCachedContent($tpl2)); - $this->assertNull($tpl->getCached()->handler->getCachedContent($tpl3)); - $this->assertEquals('hello world', $tpl->getCached()->handler->getCachedContent($tpl4)); + $this->assertNull($tpl->getCachedContent($tpl)); + $this->assertNull($tpl->getCachedContent($tpl2)); + $this->assertNull($tpl->getCachedContent($tpl3)); + $this->assertEquals('hello world', $tpl->getCachedContent($tpl4)); } /** * Test caching @@ -427,7 +427,7 @@ abstract class CacheResourceTestCommon extends PHPUnit_Smarty } $tpl = $this->smarty->createTemplate('cacheresource.tpl', $this->smarty); if ($update) { - $this->assertEquals($t,$tpl->source->getTimeStamp(), $testName . ' - source touch'); + $this->assertEquals($t,$tpl->getSource()->getTimeStamp(), $testName . ' - source touch'); } if ($lockTime) { $tpl->getCached()->handler->acquireLock($this->smarty, $tpl->getCached()); diff --git a/tests/UnitTests/ResourceTests/Custom/Ambiguous/CustomResourceAmbiguousTest.php b/tests/UnitTests/ResourceTests/Custom/Ambiguous/CustomResourceAmbiguousTest.php index 824e9d66..571b3d87 100644 --- a/tests/UnitTests/ResourceTests/Custom/Ambiguous/CustomResourceAmbiguousTest.php +++ b/tests/UnitTests/ResourceTests/Custom/Ambiguous/CustomResourceAmbiguousTest.php @@ -48,7 +48,7 @@ class CustomResourceAmbiguousTest extends PHPUnit_Smarty $this->smarty->setAllowAmbiguousResources(true); $tpl = $this->smarty->createTemplate('foobar.tpl'); - $this->assertFalse($tpl->source->exists); + $this->assertFalse($tpl->getSource()->exists); } public function testCase1() @@ -61,8 +61,8 @@ class CustomResourceAmbiguousTest extends PHPUnit_Smarty $resource_handler->setSegment('case1'); $tpl = $this->smarty->createTemplate('foobar.tpl'); - $this->assertTrue($tpl->source->exists); - $this->assertEquals('case1', $tpl->source->getContent()); + $this->assertTrue($tpl->getSource()->exists); + $this->assertEquals('case1', $tpl->getSource()->getContent()); } public function testCase2() @@ -75,8 +75,8 @@ class CustomResourceAmbiguousTest extends PHPUnit_Smarty $resource_handler->setSegment('case2'); $tpl = $this->smarty->createTemplate('foobar.tpl'); - $this->assertTrue($tpl->source->exists); - $this->assertEquals('case2', $tpl->source->getContent()); + $this->assertTrue($tpl->getSource()->exists); + $this->assertEquals('case2', $tpl->getSource()->getContent()); } @@ -89,12 +89,12 @@ class CustomResourceAmbiguousTest extends PHPUnit_Smarty $resource_handler->setSegment('case1'); $tpl = $this->smarty->createTemplate('foobar.tpl'); - $this->assertTrue($tpl->source->exists); - $this->assertEquals('case1', $tpl->source->getContent()); + $this->assertTrue($tpl->getSource()->exists); + $this->assertEquals('case1', $tpl->getSource()->getContent()); $resource_handler->setSegment('case2'); $tpl = $this->smarty->createTemplate('foobar.tpl'); - $this->assertTrue($tpl->source->exists); - $this->assertEquals('case2', $tpl->source->getContent()); + $this->assertTrue($tpl->getSource()->exists); + $this->assertEquals('case2', $tpl->getSource()->getContent()); } } diff --git a/tests/UnitTests/ResourceTests/Custom/Ambiguous/PHPunitplugins/resource.ambiguous.php b/tests/UnitTests/ResourceTests/Custom/Ambiguous/PHPunitplugins/resource.ambiguous.php index 2f2c44ca..e1a109a8 100644 --- a/tests/UnitTests/ResourceTests/Custom/Ambiguous/PHPunitplugins/resource.ambiguous.php +++ b/tests/UnitTests/ResourceTests/Custom/Ambiguous/PHPunitplugins/resource.ambiguous.php @@ -42,7 +42,7 @@ class Smarty_Resource_AmbiguousPlugin extends FilePlugin $source->filepath = $this->directory . $segment . $source->name; $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->exists = !!$source->timestamp; } diff --git a/tests/UnitTests/ResourceTests/Eval/EvalResourceTest.php b/tests/UnitTests/ResourceTests/Eval/EvalResourceTest.php index 0c7f4c83..cbe7c549 100644 --- a/tests/UnitTests/ResourceTests/Eval/EvalResourceTest.php +++ b/tests/UnitTests/ResourceTests/Eval/EvalResourceTest.php @@ -31,7 +31,7 @@ class EvalResourceTest extends PHPUnit_Smarty public function testTemplateEvalExists1() { $tpl = $this->smarty->createTemplate('eval:{$foo}'); - $this->assertTrue($tpl->source->exists); + $this->assertTrue($tpl->getSource()->exists); } public function testTemplateEvalExists2() @@ -45,7 +45,7 @@ class EvalResourceTest extends PHPUnit_Smarty public function testGetTemplateFilepath() { $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() { $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() { $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() { $tpl = $this->smarty->createTemplate('eval:hello world'); - $this->assertTrue($tpl->source->handler->recompiled); + $this->assertTrue($tpl->getSource()->handler->recompiled); } /** diff --git a/tests/UnitTests/ResourceTests/File/FileResourceTest.php b/tests/UnitTests/ResourceTests/File/FileResourceTest.php index 179faea4..17a1be3f 100644 --- a/tests/UnitTests/ResourceTests/File/FileResourceTest.php +++ b/tests/UnitTests/ResourceTests/File/FileResourceTest.php @@ -41,13 +41,13 @@ class FileResourceTest extends PHPUnit_Smarty public function testGetTemplateFilepath() { $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() { $tpl = $this->smarty->createTemplate('helloworld.tpl'); - $this->assertTrue($tpl->source->exists); + $this->assertTrue($tpl->getSource()->exists); } public function testTemplateFileExists2() @@ -58,7 +58,7 @@ class FileResourceTest extends PHPUnit_Smarty public function testTemplateFileNotExists1() { $tpl = $this->smarty->createTemplate('notthere.tpl'); - $this->assertFalse($tpl->source->exists); + $this->assertFalse($tpl->getSource()->exists); } public function testTemplateFileNotExists2() @@ -80,14 +80,14 @@ class FileResourceTest extends PHPUnit_Smarty public function testGetTemplateTimestamp() { $tpl = $this->smarty->createTemplate('helloworld.tpl'); - $this->assertTrue(is_integer($tpl->source->getTimeStamp())); - $this->assertEquals(10, strlen($tpl->source->getTimeStamp())); + $this->assertTrue(is_integer($tpl->getSource()->getTimeStamp())); + $this->assertEquals(10, strlen($tpl->getSource()->getTimeStamp())); } public function testGetTemplateSource() { $tpl = $this->smarty->createTemplate('helloworld.tpl'); - $this->assertEquals('hello world', $tpl->source->getContent()); + $this->assertEquals('hello world', $tpl->getSource()->getContent()); } public function testUsesCompiler() @@ -99,7 +99,7 @@ class FileResourceTest extends PHPUnit_Smarty public function testIsEvaluated() { $tpl = $this->smarty->createTemplate('helloworld.tpl'); - $this->assertFalse($tpl->source->handler->recompiled); + $this->assertFalse($tpl->getSource()->handler->recompiled); } public function testGetCompiledFilepath() @@ -118,7 +118,7 @@ class FileResourceTest extends PHPUnit_Smarty $tpl = $this->smarty->createTemplate('helloworld.tpl'); // create dummy compiled file file_put_contents($tpl->getCompiled()->filepath, ''); - 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'); $this->assertTrue(is_integer($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() @@ -153,7 +153,7 @@ class FileResourceTest extends PHPUnit_Smarty // touch to prepare next test sleep(2); $tpl = $this->smarty->createTemplate('helloworld.tpl'); - touch($tpl->source->filepath); + touch($tpl->getSource()->filepath); $this->setUp(); diff --git a/tests/UnitTests/ResourceTests/FileIndexed/FileResourceIndexedTest.php b/tests/UnitTests/ResourceTests/FileIndexed/FileResourceIndexedTest.php index 343dda9e..c85c8b95 100644 --- a/tests/UnitTests/ResourceTests/FileIndexed/FileResourceIndexedTest.php +++ b/tests/UnitTests/ResourceTests/FileIndexed/FileResourceIndexedTest.php @@ -28,25 +28,25 @@ class FileResourceIndexedTest extends PHPUnit_Smarty public function testGetTemplateFilepath() { $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() { $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() { $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() { $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() diff --git a/tests/UnitTests/ResourceTests/Registered/RegisteredResourceTest.php b/tests/UnitTests/ResourceTests/Registered/RegisteredResourceTest.php index dc27690c..c171b263 100644 --- a/tests/UnitTests/ResourceTests/Registered/RegisteredResourceTest.php +++ b/tests/UnitTests/ResourceTests/Registered/RegisteredResourceTest.php @@ -49,8 +49,8 @@ class RegisteredResourceTest extends PHPUnit_Smarty public function testResourcePluginTimestamp() { $tpl = $this->smarty->createTemplate('rr:test'); - $this->assertTrue(is_integer($tpl->source->getTimeStamp())); - $this->assertEquals(10, strlen($tpl->source->getTimeStamp())); + $this->assertTrue(is_integer($tpl->getSource()->getTimeStamp())); + $this->assertEquals(10, strlen($tpl->getSource()->getTimeStamp())); } /** diff --git a/tests/UnitTests/ResourceTests/ResourcePlugins/ResourcePluginTest.php b/tests/UnitTests/ResourceTests/ResourcePlugins/ResourcePluginTest.php index f61b2629..5b1b3854 100644 --- a/tests/UnitTests/ResourceTests/ResourcePlugins/ResourcePluginTest.php +++ b/tests/UnitTests/ResourceTests/ResourcePlugins/ResourcePluginTest.php @@ -72,8 +72,8 @@ class ResourcePluginTest extends PHPUnit_Smarty { $this->smarty->addPluginsDir("./PHPunitplugins/"); $tpl = $this->smarty->createTemplate('db:test'); - $this->assertTrue(is_integer($tpl->source->getTimeStamp())); - $this->assertEquals(10, strlen($tpl->source->getTimeStamp())); + $this->assertTrue(is_integer($tpl->getSource()->getTimeStamp())); + $this->assertEquals(10, strlen($tpl->getSource()->getTimeStamp())); } } diff --git a/tests/UnitTests/ResourceTests/Stream/StreamResourceTest.php b/tests/UnitTests/ResourceTests/Stream/StreamResourceTest.php index ec9d2e3f..acaa8a31 100644 --- a/tests/UnitTests/ResourceTests/Stream/StreamResourceTest.php +++ b/tests/UnitTests/ResourceTests/Stream/StreamResourceTest.php @@ -43,7 +43,7 @@ class StreamResourceTest extends PHPUnit_Smarty public function testGetTemplateFilepath() { $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() { $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() { $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() { $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() { $tpl = $this->smarty->createTemplate('global:mytest'); - $this->assertTrue($tpl->source->exists); + $this->assertTrue($tpl->getSource()->exists); } public function testTemplateStreamExists2() @@ -129,7 +129,7 @@ class StreamResourceTest extends PHPUnit_Smarty public function testTemplateStreamNotExists1() { $tpl = $this->smarty->createTemplate('global:notthere'); - $this->assertFalse($tpl->source->exists); + $this->assertFalse($tpl->getSource()->exists); } public function testTemplateStramNotExists2() diff --git a/tests/UnitTests/ResourceTests/String/StringResourceTest.php b/tests/UnitTests/ResourceTests/String/StringResourceTest.php index 7bcb8e22..4e4cdd13 100644 --- a/tests/UnitTests/ResourceTests/String/StringResourceTest.php +++ b/tests/UnitTests/ResourceTests/String/StringResourceTest.php @@ -42,7 +42,7 @@ class StringResourceTest extends PHPUnit_Smarty public function testTemplateStringExists1() { $tpl = $this->smarty->createTemplate('string:{$foo}'); - $this->assertTrue($tpl->source->exists); + $this->assertTrue($tpl->getSource()->exists); } public function testTemplateStringExists2() @@ -56,7 +56,7 @@ class StringResourceTest extends PHPUnit_Smarty public function testGetTemplateFilepath() { $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() { $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() { $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() { $tpl = $this->smarty->createTemplate('string:hello world'); - $this->assertFalse($tpl->source->handler->recompiled); + $this->assertFalse($tpl->getSource()->handler->recompiled); } /** diff --git a/tests/UnitTests/SecurityTests/SecurityTest.php b/tests/UnitTests/SecurityTests/SecurityTest.php index d70f7e5e..6b54069a 100644 --- a/tests/UnitTests/SecurityTests/SecurityTest.php +++ b/tests/UnitTests/SecurityTests/SecurityTest.php @@ -279,7 +279,7 @@ class SecurityTest extends PHPUnit_Smarty fclose($fp); $this->smarty->security_policy->streams= array('global'); $tpl = $this->smarty->createTemplate('global:mytest'); - $this->assertTrue($tpl->source->exists); + $this->assertTrue($tpl->getSource()->exists); stream_wrapper_unregister("global"); } /** @@ -298,7 +298,7 @@ class SecurityTest extends PHPUnit_Smarty fclose($fp); $this->smarty->security_policy->streams= array('notrusted'); $tpl = $this->smarty->createTemplate('global:mytest'); - $this->assertTrue($tpl->source->exists); + $this->assertTrue($tpl->getSource()->exists); stream_wrapper_unregister("global"); } /** diff --git a/tests/UnitTests/SmartyMethodsTests/ClearCompiledTemplate/ClearCompiledTest.php b/tests/UnitTests/SmartyMethodsTests/ClearCompiledTemplate/ClearCompiledTest.php index e7adcabd..ed1c818c 100644 --- a/tests/UnitTests/SmartyMethodsTests/ClearCompiledTemplate/ClearCompiledTest.php +++ b/tests/UnitTests/SmartyMethodsTests/ClearCompiledTemplate/ClearCompiledTest.php @@ -56,7 +56,7 @@ class ClearCompiledTest extends PHPUnit_Smarty protected function makeFiles() { $this->_files = array(); - $directory_length = strlen($this->getSmartyObj()->getCompileDir()); + $directory_length = strlen($this->getSmarty()->getCompileDir()); $templates = array( 'helloworld.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 ($compile_ids as $compile_id) { - $tpl = $this->getSmartyObj()->createTemplate($template, null, $compile_id); + $tpl = $this->getSmarty()->createTemplate($template, null, $compile_id); $tpl->fetch(); $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) { - $base = $this->getSmartyObj()->getCompileDir(); + $base = $this->getSmarty()->getCompileDir(); $time = time(); foreach ($keys as $key) { if (isset($this->_files[$key])) { @@ -123,7 +123,7 @@ class ClearCompiledTest extends PHPUnit_Smarty */ protected function getFiles() { - $directory = realpath($this->getSmartyObj()->getCompileDir()); + $directory = realpath($this->getSmarty()->getCompileDir()); if (!$directory) { return array(); } @@ -160,12 +160,12 @@ class ClearCompiledTest extends PHPUnit_Smarty public function runClearAll($useSubDirs) { - $this->getSmartyObj()->setUseSubDirs($useSubDirs); + $this->getSmarty()->setUseSubDirs($useSubDirs); $this->clearFiles(); $this->makeFiles(); $expected = array(); - $this->assertEquals(12, $this->getSmartyObj()->{$this->methodName}()); + $this->assertEquals(12, $this->getSmarty()->{$this->methodName}()); $this->assertEquals($this->expectFiles($expected), $this->getFiles()); $this->clearFiles(); @@ -194,7 +194,7 @@ class ClearCompiledTest extends PHPUnit_Smarty public function runClearTemplate($useSubDirs) { - $this->getSmartyObj()->setUseSubDirs($useSubDirs); + $this->getSmarty()->setUseSubDirs($useSubDirs); $this->clearFiles(); $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', '[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->clearFiles(); @@ -211,12 +211,12 @@ class ClearCompiledTest extends PHPUnit_Smarty public function runClearOtherTemplate($useSubDirs) { - $this->getSmartyObj()->setUseSubDirs($useSubDirs); + $this->getSmarty()->setUseSubDirs($useSubDirs); $this->clearFiles(); $this->makeFiles(); $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->clearFiles(); @@ -245,7 +245,7 @@ class ClearCompiledTest extends PHPUnit_Smarty public function runClearCompileid($useSubDirs) { - $this->getSmartyObj()->setUseSubDirs($useSubDirs); + $this->getSmarty()->setUseSubDirs($useSubDirs); $this->clearFiles(); $this->makeFiles(); @@ -255,7 +255,7 @@ class ClearCompiledTest extends PHPUnit_Smarty 'ambiguous/case1/foobar.tpl#', '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($this->expectFiles($expected), $this->getFiles()); @@ -264,12 +264,12 @@ class ClearCompiledTest extends PHPUnit_Smarty public function runClearOtherCompileid($useSubDirs) { - $this->getSmartyObj()->setUseSubDirs($useSubDirs); + $this->getSmarty()->setUseSubDirs($useSubDirs); $this->clearFiles(); $this->makeFiles(); $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->clearFiles(); @@ -288,13 +288,13 @@ class ClearCompiledTest extends PHPUnit_Smarty public function runClearExpired($useSubDirs) { - $this->getSmartyObj()->setUseSubDirs($useSubDirs); + $this->getSmarty()->setUseSubDirs($useSubDirs); $this->clearFiles(); $this->makeFiles(); $expected = array('helloworld.tpl#', 'helloworld2.tpl#'); $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->clearFiles(); @@ -313,7 +313,7 @@ class ClearCompiledTest extends PHPUnit_Smarty public function runClearTemplateExpired($useSubDirs) { - $this->getSmartyObj()->setUseSubDirs($useSubDirs); + $this->getSmarty()->setUseSubDirs($useSubDirs); $this->clearFiles(); $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', ); $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->clearFiles(); @@ -343,7 +343,7 @@ class ClearCompiledTest extends PHPUnit_Smarty public function runClearTemplateCacheidExpired($useSubDirs) { - $this->getSmartyObj()->setUseSubDirs($useSubDirs); + $this->getSmarty()->setUseSubDirs($useSubDirs); $this->clearFiles(); $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', ); $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->clearFiles(); @@ -373,7 +373,7 @@ class ClearCompiledTest extends PHPUnit_Smarty public function runClearCacheidExpired($useSubDirs) { - $this->getSmartyObj()->setUseSubDirs($useSubDirs); + $this->getSmarty()->setUseSubDirs($useSubDirs); $this->clearFiles(); $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', ); $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->clearFiles(); @@ -403,7 +403,7 @@ class ClearCompiledTest extends PHPUnit_Smarty public function runClearTemplateCacheid($useSubDirs) { - $this->getSmartyObj()->setUseSubDirs($useSubDirs); + $this->getSmarty()->setUseSubDirs($useSubDirs); $this->clearFiles(); $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', '[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->clearFiles(); @@ -431,7 +431,7 @@ class ClearCompiledTest extends PHPUnit_Smarty public function runClearAmbiguousTemplate($useSubDirs) { - $this->getSmartyObj()->setUseSubDirs($useSubDirs); + $this->getSmarty()->setUseSubDirs($useSubDirs); $this->clearFiles(); $this->makeFiles(); @@ -443,7 +443,7 @@ class ClearCompiledTest extends PHPUnit_Smarty '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', ); - $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->clearFiles(); diff --git a/tests/UnitTests/__shared/PHPunitplugins/function.checkconfigvar.php b/tests/UnitTests/__shared/PHPunitplugins/function.checkconfigvar.php index 6534f859..bc2452ef 100644 --- a/tests/UnitTests/__shared/PHPunitplugins/function.checkconfigvar.php +++ b/tests/UnitTests/__shared/PHPunitplugins/function.checkconfigvar.php @@ -27,7 +27,7 @@ function smarty_function_checkconfigvar($params, $template) $ptr = $template; while ($ptr) { 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'; $ptr = $ptr->parent; } 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)) { $output .= "#global:\${$var} ="; - $output .= $template->smarty->hasConfigVariable($var) ? - preg_replace('/\s/', '', var_export($template->smarty->getConfigVariable($var), true)) : 'null'; + $output .= $template->getSmarty()->hasConfigVariable($var) ? + preg_replace('/\s/', '', var_export($template->getSmarty()->getConfigVariable($var), true)) : 'null'; } return $output; } diff --git a/tests/UnitTests/__shared/PHPunitplugins/function.checkvar.php b/tests/UnitTests/__shared/PHPunitplugins/function.checkvar.php index 6621af34..1082b6d7 100644 --- a/tests/UnitTests/__shared/PHPunitplugins/function.checkvar.php +++ b/tests/UnitTests/__shared/PHPunitplugins/function.checkvar.php @@ -27,7 +27,7 @@ function smarty_function_checkvar($params, \Smarty\Template $template) $ptr = $template; while ($ptr) { 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<'; $i = 0; while (isset($ptr->_var_stack[ $i ])) { @@ -46,8 +46,8 @@ function smarty_function_checkvar($params, \Smarty\Template $template) } if (in_array('global', $types)) { $output .= "#global:\${$var} ="; - $output .= $template->smarty->hasVariable($var) ? - preg_replace('/\s/', '', var_export($template->smarty->getValue($var), true)) : '>unassigned<'; + $output .= $template->getSmarty()->hasVariable($var) ? + preg_replace('/\s/', '', var_export($template->getSmarty()->getValue($var), true)) : '>unassigned<'; } return $output; } diff --git a/tests/UnitTests/__shared/resources/resource.extendsall.php b/tests/UnitTests/__shared/resources/resource.extendsall.php index c0a18bd0..10f7d437 100644 --- a/tests/UnitTests/__shared/resources/resource.extendsall.php +++ b/tests/UnitTests/__shared/resources/resource.extendsall.php @@ -27,9 +27,9 @@ class My_Resource_Extendsall extends \Smarty\Resource\ExtendsPlugin $uid = ''; $sources = array(); $timestamp = 0; - foreach ($source->smarty->getTemplateDir() as $key => $directory) { + foreach ($source->getSmarty()->getTemplateDir() as $key => $directory) { 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) { continue; } @@ -48,7 +48,7 @@ class My_Resource_Extendsall extends \Smarty\Resource\ExtendsPlugin $s = current($sources); $source->components = $sources; $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->timestamp = $timestamp; }