diff --git a/demo/plugins/resource.extendsall.php b/demo/plugins/resource.extendsall.php index a547d41d..b6e46393 100644 --- a/demo/plugins/resource.extendsall.php +++ b/demo/plugins/resource.extendsall.php @@ -8,7 +8,7 @@ * @package Resource-examples * @author Rodney Rehm */ -class Smarty_Resource_Extendsall extends Smarty_Internal_Resource_Extends +class Smarty_Resource_Extendsall extends \Smarty\Resource\ExtendsPlugin { /** * populate Source Object with meta data from Resource @@ -25,7 +25,7 @@ class Smarty_Resource_Extendsall extends Smarty_Internal_Resource_Extends $timestamp = 0; foreach ($source->smarty->getTemplateDir() as $key => $directory) { try { - $s = Smarty_Resource::source(null, $source->smarty, 'file:' . '[' . $key . ']' . $source->name); + $s = Smarty\Resource\BasePlugin::source(null, $source->smarty, 'file:' . '[' . $key . ']' . $source->name); if (!$s->exists) { continue; } diff --git a/demo/plugins/resource.mysql.php b/demo/plugins/resource.mysql.php index 95a3c2ba..e42b536d 100644 --- a/demo/plugins/resource.mysql.php +++ b/demo/plugins/resource.mysql.php @@ -1,5 +1,7 @@ template->smarty->default_resource_type; $name = !empty($match[5]) ? $match[5] : $match[6]; - $handler = Smarty_Resource::load($compiler->smarty, $type); + $handler = \Smarty\Resource\BasePlugin::load($compiler->smarty, $type); if ($handler->recompiled || $handler->uncompiled) { $variable_template = true; } diff --git a/src/Compile/Insert.php b/src/Compile/Insert.php index 5a36eb75..c639f755 100644 --- a/src/Compile/Insert.php +++ b/src/Compile/Insert.php @@ -25,7 +25,7 @@ class Insert extends Base { * Attribute definition: Overwrites base class. * * @var array - * @see Base + * @see BasePlugin */ protected $required_attributes = ['name']; @@ -33,7 +33,7 @@ class Insert extends Base { * Attribute definition: Overwrites base class. * * @var array - * @see Base + * @see BasePlugin */ protected $shorttag_order = ['name']; @@ -41,7 +41,7 @@ class Insert extends Base { * Attribute definition: Overwrites base class. * * @var array - * @see Base + * @see BasePlugin */ protected $optional_attributes = ['_any']; diff --git a/src/Compile/PrivateBlockPlugin.php b/src/Compile/PrivateBlockPlugin.php index bbb7cd82..ef8a77dc 100644 --- a/src/Compile/PrivateBlockPlugin.php +++ b/src/Compile/PrivateBlockPlugin.php @@ -24,7 +24,7 @@ class PrivateBlockPlugin extends Base { * Attribute definition: Overwrites base class. * * @var array - * @see Base + * @see BasePlugin */ protected $optional_attributes = ['_any']; diff --git a/src/Compile/PrivateObjectFunction.php b/src/Compile/PrivateObjectFunction.php index 4798f892..f2cf11c6 100644 --- a/src/Compile/PrivateObjectFunction.php +++ b/src/Compile/PrivateObjectFunction.php @@ -24,7 +24,7 @@ class PrivateObjectFunction extends Base { * Attribute definition: Overwrites base class. * * @var array - * @see Base + * @see BasePlugin */ protected $optional_attributes = ['_any']; diff --git a/src/Compile/PrivateRegisteredFunction.php b/src/Compile/PrivateRegisteredFunction.php index f62b7f77..dc87a23e 100644 --- a/src/Compile/PrivateRegisteredFunction.php +++ b/src/Compile/PrivateRegisteredFunction.php @@ -25,7 +25,7 @@ class PrivateRegisteredFunction extends Base { * Attribute definition: Overwrites base class. * * @var array - * @see Base + * @see BasePlugin */ public $optional_attributes = ['_any']; diff --git a/src/Compile/Section.php b/src/Compile/Section.php index 19bc89e4..077f6c87 100644 --- a/src/Compile/Section.php +++ b/src/Compile/Section.php @@ -16,7 +16,7 @@ class Section extends ForeachSection { * Attribute definition: Overwrites base class. * * @var array - * @see Base + * @see BasePlugin */ protected $required_attributes = ['name', 'loop']; @@ -24,7 +24,7 @@ class Section extends ForeachSection { * Attribute definition: Overwrites base class. * * @var array - * @see Base + * @see BasePlugin */ protected $shorttag_order = ['name', 'loop']; @@ -32,7 +32,7 @@ class Section extends ForeachSection { * Attribute definition: Overwrites base class. * * @var array - * @see Base + * @see BasePlugin */ protected $optional_attributes = ['start', 'step', 'max', 'show', 'properties']; diff --git a/src/Resource/Base.php b/src/Resource/BasePlugin.php similarity index 97% rename from src/Resource/Base.php rename to src/Resource/BasePlugin.php index 0278908c..13957f01 100644 --- a/src/Resource/Base.php +++ b/src/Resource/BasePlugin.php @@ -21,7 +21,7 @@ namespace Smarty\Resource; * @method populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template) * @method process(Smarty_Internal_Template $_smarty_tpl) */ -abstract class Base +abstract class BasePlugin { /** * resource types provided by the core @@ -31,7 +31,7 @@ abstract class Base public static $sysplugins = array( 'file' => File::class, 'string' => String::class, - 'extends' => Extending::class, + 'extends' => ExtendsPlugin::class, 'stream' => Stream::class, 'eval' => StringEval::class, 'php' => Php::class, @@ -65,7 +65,7 @@ abstract class Base * @param string $type name of the resource * * @throws \SmartyException - * @return Base Resource Handler + * @return BasePlugin Resource Handler */ public static function load(\Smarty $smarty, $type) { @@ -148,9 +148,9 @@ abstract class Base public static function getUniqueTemplateName($obj, $template_resource) { $smarty = $obj->_getSmartyObj(); - list($name, $type) = self::parseResourceName($template_resource, $smarty->default_resource_type); + [$name, $type] = self::parseResourceName($template_resource, $smarty->default_resource_type); // TODO: optimize for Smarty's internal resource types - $resource = Base::load($smarty, $type); + $resource = BasePlugin::load($smarty, $type); // go relative to a given template? $_file_is_dotted = $name[ 0 ] === '.' && ($name[ 1 ] === '.' || $name[ 1 ] === '/'); if ($obj->_isTplObj() && $_file_is_dotted diff --git a/src/Resource/CustomPlugin.php b/src/Resource/CustomPlugin.php new file mode 100644 index 00000000..52f8598f --- /dev/null +++ b/src/Resource/CustomPlugin.php @@ -0,0 +1,106 @@ +filepath = $source->type . ':' . $this->generateSafeName($source->name); + $source->uid = sha1($source->type . ':' . $source->name); + $mtime = $this->fetchTimestamp($source->name); + if ($mtime !== null) { + $source->timestamp = $mtime; + } else { + $this->fetch($source->name, $content, $timestamp); + $source->timestamp = isset($timestamp) ? $timestamp : false; + if (isset($content)) { + $source->content = $content; + } + } + $source->exists = !!$source->timestamp; + } + + /** + * Load template's source into current template object + * + * @param Smarty_Template_Source $source source object + * + * @return string template source + * @throws SmartyException if source cannot be loaded + */ + public function getContent(Smarty_Template_Source $source) { + $this->fetch($source->name, $content, $timestamp); + if (isset($content)) { + return $content; + } + throw new SmartyException("Unable to read template {$source->type} '{$source->name}'"); + } + + /** + * Determine basename for compiled filename + * + * @param Smarty_Template_Source $source source object + * + * @return string resource's basename + */ + public function getBasename(Smarty_Template_Source $source) { + return basename($this->generateSafeName($source->name)); + } + + /** + * Removes special characters from $name and limits its length to 127 characters. + * + * @param $name + * + * @return string + */ + private function generateSafeName($name): string { + return substr(preg_replace('/[^A-Za-z0-9._]/', '', (string)$name), 0, 127); + } +} diff --git a/src/Resource/Extending.php b/src/Resource/ExtendsPlugin.php similarity index 98% rename from src/Resource/Extending.php rename to src/Resource/ExtendsPlugin.php index ba7f38c4..2e166df9 100644 --- a/src/Resource/Extending.php +++ b/src/Resource/ExtendsPlugin.php @@ -18,7 +18,7 @@ namespace Smarty\Resource; * @package Smarty * @subpackage TemplateResources */ -class Extending extends Base +class ExtendsPlugin extends BasePlugin { /** diff --git a/src/Resource/FilePlugin.php b/src/Resource/FilePlugin.php new file mode 100644 index 00000000..af649d0f --- /dev/null +++ b/src/Resource/FilePlugin.php @@ -0,0 +1,179 @@ +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); + } + $source->exists = true; + $source->uid = sha1( + $source->filepath . ($source->isConfig ? $source->smarty->_joined_config_dir : + $source->smarty->_joined_template_dir) + ); + $source->timestamp = filemtime($source->filepath); + } else { + $source->timestamp = $source->exists = false; + } + } + + /** + * populate Source Object with timestamp and exists from Resource + * + * @param Smarty_Template_Source $source source object + */ + public function populateTimestamp(Smarty_Template_Source $source) { + if (!$source->exists) { + $source->timestamp = $source->exists = is_file($source->filepath); + } + if ($source->exists) { + $source->timestamp = filemtime($source->filepath); + } + } + + /** + * Load template's source from file into current template object + * + * @param Smarty_Template_Source $source source object + * + * @return string template source + * @throws SmartyException if source cannot be loaded + */ + public function getContent(Smarty_Template_Source $source) { + if ($source->exists) { + return file_get_contents($source->filepath); + } + throw new SmartyException( + 'Unable to read ' . ($source->isConfig ? 'config' : 'template') . + " {$source->type} '{$source->name}'" + ); + } + + /** + * Determine basename for compiled filename + * + * @param Smarty_Template_Source $source source object + * + * @return string resource's basename + */ + public function getBasename(Smarty_Template_Source $source) { + return basename($source->filepath); + } + + /** + * build template filepath by traversing the template_dir array + * + * @param Smarty_Template_Source $source source object + * @param Smarty_Internal_Template $_template template object + * + * @return string fully qualified filepath + * @throws SmartyException + */ + protected function buildFilepath(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) { + $file = $source->name; + // absolute file ? + if ($file[0] === '/' || $file[1] === ':') { + $file = $source->smarty->_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 SmartyException("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'"); + } + // normalize path + $path = + $source->smarty->_realpath(dirname($_template->parent->source->filepath) . DIRECTORY_SEPARATOR . $file); + // files relative to a template only get one shot + return is_file($path) ? $path : false; + } + // normalize DIRECTORY_SEPARATOR + if (strpos($file, DIRECTORY_SEPARATOR === '/' ? '\\' : '/') !== false) { + $file = str_replace(DIRECTORY_SEPARATOR === '/' ? '\\' : '/', DIRECTORY_SEPARATOR, $file); + } + $_directories = $source->smarty->getTemplateDir(null, $source->isConfig); + // template_dir index? + if ($file[0] === '[' && preg_match('#^\[([^\]]+)\](.+)$#', $file, $fileMatch)) { + $file = $fileMatch[2]; + $_indices = explode(',', $fileMatch[1]); + $_index_dirs = []; + foreach ($_indices as $index) { + $index = trim($index); + // try string indexes + if (isset($_directories[$index])) { + $_index_dirs[] = $_directories[$index]; + } elseif (is_numeric($index)) { + // try numeric index + $index = (int)$index; + if (isset($_directories[$index])) { + $_index_dirs[] = $_directories[$index]; + } else { + // try at location index + $keys = array_keys($_directories); + if (isset($_directories[$keys[$index]])) { + $_index_dirs[] = $_directories[$keys[$index]]; + } + } + } + } + if (empty($_index_dirs)) { + // index not found + return false; + } else { + $_directories = $_index_dirs; + } + } + // relative file name? + foreach ($_directories as $_directory) { + $path = $_directory . $file; + if (is_file($path)) { + return (strpos($path, '.' . DIRECTORY_SEPARATOR) !== false) ? $source->smarty->_realpath($path) : $path; + } + } + if (!isset($_index_dirs)) { + // Could be relative to cwd + $path = $source->smarty->_realpath($file, true); + if (is_file($path)) { + return $path; + } + } + // Use include path ? + if ($source->smarty->use_include_path) { + return $source->smarty->ext->_getIncludePath->getIncludePath($_directories, $file, $source->smarty); + } + return false; + } +} diff --git a/src/Resource/PhpPlugin.php b/src/Resource/PhpPlugin.php new file mode 100644 index 00000000..82abb4a7 --- /dev/null +++ b/src/Resource/PhpPlugin.php @@ -0,0 +1,119 @@ +short_open_tag = function_exists('ini_get') ? ini_get('short_open_tag') : 1; + } + + /** + * Load template's source from file into current template object + * + * @param Smarty_Template_Source $source source object + * + * @return string template source + * @throws SmartyException if source cannot be loaded + */ + public function getContent(Smarty_Template_Source $source) { + if ($source->exists) { + return ''; + } + throw new SmartyException("Unable to read template {$source->type} '{$source->name}'"); + } + + /** + * populate compiled object with compiled filepath + * + * @param Smarty_Template_Compiled $compiled compiled object + * @param Smarty_Internal_Template $_template template object (is ignored) + */ + public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template) { + $compiled->filepath = $_template->source->filepath; + $compiled->timestamp = $_template->source->timestamp; + $compiled->exists = $_template->source->exists; + $compiled->file_dependency[$_template->source->uid] = + [ + $compiled->filepath, + $compiled->timestamp, + $_template->source->type, + ]; + } + + /** + * Render and output the template (without using the compiler) + * + * @param Smarty_Template_Source $source source object + * @param Smarty_Internal_Template $_template template object + * + * @return void + * @throws SmartyException if template cannot be loaded or allow_php_templates is disabled + */ + public function renderUncompiled(Smarty_Template_Source $source, Smarty_Internal_Template $_template) { + if (!$source->smarty->allow_php_templates) { + throw new SmartyException('PHP templates are disabled'); + } + if (!$source->exists) { + throw new SmartyException( + "Unable to load template '{$source->type}:{$source->name}'" . + ($_template->_isSubTpl() ? " in '{$_template->parent->template_resource}'" : '') + ); + } + // prepare variables + extract($_template->getTemplateVars()); + // include PHP template with short open tags enabled + if (function_exists('ini_set')) { + ini_set('short_open_tag', '1'); + } + /** + * + * + * @var Smarty_Internal_Template $_smarty_template + * used in included file + */ + $_smarty_template = $_template; + include $source->filepath; + if (function_exists('ini_set')) { + ini_set('short_open_tag', $this->short_open_tag); + } + } +} diff --git a/src/Resource/RecompiledPlugin.php b/src/Resource/RecompiledPlugin.php new file mode 100644 index 00000000..bea22090 --- /dev/null +++ b/src/Resource/RecompiledPlugin.php @@ -0,0 +1,97 @@ +compiled; + $compiled->file_dependency = []; + $compiled->includes = []; + $compiled->nocache_hash = null; + $compiled->unifunc = null; + $level = ob_get_level(); + ob_start(); + $_smarty_tpl->loadCompiler(); + // call compiler + try { + eval('?>' . $_smarty_tpl->compiler->compileTemplate($_smarty_tpl)); + } catch (Exception $e) { + unset($_smarty_tpl->compiler); + while (ob_get_level() > $level) { + ob_end_clean(); + } + throw $e; + } + // release compiler object to free memory + unset($_smarty_tpl->compiler); + ob_get_clean(); + $compiled->timestamp = time(); + $compiled->exists = true; + } + + /** + * populate Compiled Object with compiled filepath + * + * @param Smarty_Template_Compiled $compiled compiled object + * @param Smarty_Internal_Template $_template template object + * + * @return void + */ + public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template) { + $compiled->filepath = false; + $compiled->timestamp = false; + $compiled->exists = false; + } + + /* + * Disable timestamp checks for recompiled resource. + * + * @return bool + */ + /** + * @return bool + */ + public function checkTimestamps() { + return false; + } +} diff --git a/src/Resource/StreamPlugin.php b/src/Resource/StreamPlugin.php new file mode 100644 index 00000000..ec089d13 --- /dev/null +++ b/src/Resource/StreamPlugin.php @@ -0,0 +1,81 @@ +resource, '://') !== false) { + $source->filepath = $source->resource; + } else { + $source->filepath = str_replace(':', '://', $source->resource); + } + $source->uid = false; + $source->content = $this->getContent($source); + $source->timestamp = $source->exists = !!$source->content; + } + + /** + * Load template's source from stream into current template object + * + * @param Smarty_Template_Source $source source object + * + * @return string template source + */ + public function getContent(Smarty_Template_Source $source) { + $t = ''; + // the availability of the stream has already been checked in Smarty\Resource\Base::fetch() + $fp = fopen($source->filepath, 'r+'); + if ($fp) { + while (!feof($fp) && ($current_line = fgets($fp)) !== false) { + $t .= $current_line; + } + fclose($fp); + return $t; + } else { + return false; + } + } + + /** + * modify resource_name according to resource handlers specifications + * + * @param Smarty $smarty Smarty instance + * @param string $resource_name resource_name to make unique + * @param boolean $isConfig flag for config resource + * + * @return string unique resource name + */ + public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false) { + return get_class($this) . '#' . $resource_name; + } +} diff --git a/src/Resource/StringPlugin.php b/src/Resource/StringPlugin.php new file mode 100644 index 00000000..2ae2f9fc --- /dev/null +++ b/src/Resource/StringPlugin.php @@ -0,0 +1,107 @@ +uid = $source->filepath = sha1($source->name . $source->smarty->_joined_template_dir); + $source->timestamp = $source->exists = true; + } + + /** + * Load template's source from $resource_name into current template object + * + * @param Smarty_Template_Source $source source object + * + * @return string template source + * @uses decode() to decode base64 and urlencoded template_resources + * + */ + public function getContent(Smarty_Template_Source $source) { + return $this->decode($source->name); + } + + /** + * decode base64 and urlencode + * + * @param string $string template_resource to decode + * + * @return string decoded template_resource + */ + protected function decode($string) { + // decode if specified + if (($pos = strpos($string, ':')) !== false) { + if (!strncmp($string, 'base64', 6)) { + return base64_decode(substr($string, 7)); + } elseif (!strncmp($string, 'urlencode', 9)) { + return urldecode(substr($string, 10)); + } + } + return $string; + } + + /** + * modify resource_name according to resource handlers specifications + * + * @param Smarty $smarty Smarty instance + * @param string $resource_name resource_name to make unique + * @param boolean $isConfig flag for config resource + * + * @return string unique resource name + */ + public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false) { + return get_class($this) . '#' . $this->decode($resource_name); + } + + /** + * Determine basename for compiled filename + * Always returns an empty string. + * + * @param Smarty_Template_Source $source source object + * + * @return string resource's basename + */ + public function getBasename(Smarty_Template_Source $source) { + return ''; + } + + /* + * Disable timestamp checks for string resource. + * + * @return bool + */ + /** + * @return bool + */ + public function checkTimestamps() { + return false; + } +} diff --git a/src/Resource/UncompiledPlugin.php b/src/Resource/UncompiledPlugin.php new file mode 100644 index 00000000..6404bc95 --- /dev/null +++ b/src/Resource/UncompiledPlugin.php @@ -0,0 +1,54 @@ +filepath = $_template->source->filepath; + $compiled->timestamp = $_template->source->timestamp; + $compiled->exists = $_template->source->exists; + if ($_template->smarty->merge_compiled_includes || $_template->source->handler->checkTimestamps()) { + $compiled->file_dependency[$_template->source->uid] = + [$compiled->filepath, $compiled->timestamp, $_template->source->type,]; + } + } +} diff --git a/src/Resource/smarty_internal_resource_file.php b/src/Resource/smarty_internal_resource_file.php deleted file mode 100644 index 46703781..00000000 --- a/src/Resource/smarty_internal_resource_file.php +++ /dev/null @@ -1,178 +0,0 @@ -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); - } - $source->exists = true; - $source->uid = sha1( - $source->filepath . ($source->isConfig ? $source->smarty->_joined_config_dir : - $source->smarty->_joined_template_dir) - ); - $source->timestamp = filemtime($source->filepath); - } else { - $source->timestamp = $source->exists = false; - } - } - - /** - * populate Source Object with timestamp and exists from Resource - * - * @param Smarty_Template_Source $source source object - */ - public function populateTimestamp(Smarty_Template_Source $source) - { - if (!$source->exists) { - $source->timestamp = $source->exists = is_file($source->filepath); - } - if ($source->exists) { - $source->timestamp = filemtime($source->filepath); - } - } - - /** - * Load template's source from file into current template object - * - * @param Smarty_Template_Source $source source object - * - * @return string template source - * @throws SmartyException if source cannot be loaded - */ - public function getContent(Smarty_Template_Source $source) - { - if ($source->exists) { - return file_get_contents($source->filepath); - } - throw new SmartyException( - 'Unable to read ' . ($source->isConfig ? 'config' : 'template') . - " {$source->type} '{$source->name}'" - ); - } - - /** - * Determine basename for compiled filename - * - * @param Smarty_Template_Source $source source object - * - * @return string resource's basename - */ - public function getBasename(Smarty_Template_Source $source) - { - return basename($source->filepath); - } - - /** - * build template filepath by traversing the template_dir array - * - * @param Smarty_Template_Source $source source object - * @param Smarty_Internal_Template $_template template object - * - * @return string fully qualified filepath - * @throws SmartyException - */ - protected function buildFilepath(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) - { - $file = $source->name; - // absolute file ? - if ($file[ 0 ] === '/' || $file[ 1 ] === ':') { - $file = $source->smarty->_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 SmartyException("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'"); - } - // normalize path - $path = - $source->smarty->_realpath(dirname($_template->parent->source->filepath) . DIRECTORY_SEPARATOR . $file); - // files relative to a template only get one shot - return is_file($path) ? $path : false; - } - // normalize DIRECTORY_SEPARATOR - if (strpos($file, DIRECTORY_SEPARATOR === '/' ? '\\' : '/') !== false) { - $file = str_replace(DIRECTORY_SEPARATOR === '/' ? '\\' : '/', DIRECTORY_SEPARATOR, $file); - } - $_directories = $source->smarty->getTemplateDir(null, $source->isConfig); - // template_dir index? - if ($file[ 0 ] === '[' && preg_match('#^\[([^\]]+)\](.+)$#', $file, $fileMatch)) { - $file = $fileMatch[ 2 ]; - $_indices = explode(',', $fileMatch[ 1 ]); - $_index_dirs = array(); - foreach ($_indices as $index) { - $index = trim($index); - // try string indexes - if (isset($_directories[ $index ])) { - $_index_dirs[] = $_directories[ $index ]; - } elseif (is_numeric($index)) { - // try numeric index - $index = (int)$index; - if (isset($_directories[ $index ])) { - $_index_dirs[] = $_directories[ $index ]; - } else { - // try at location index - $keys = array_keys($_directories); - if (isset($_directories[ $keys[ $index ] ])) { - $_index_dirs[] = $_directories[ $keys[ $index ] ]; - } - } - } - } - if (empty($_index_dirs)) { - // index not found - return false; - } else { - $_directories = $_index_dirs; - } - } - // relative file name? - foreach ($_directories as $_directory) { - $path = $_directory . $file; - if (is_file($path)) { - return (strpos($path, '.' . DIRECTORY_SEPARATOR) !== false) ? $source->smarty->_realpath($path) : $path; - } - } - if (!isset($_index_dirs)) { - // Could be relative to cwd - $path = $source->smarty->_realpath($file, true); - if (is_file($path)) { - return $path; - } - } - // Use include path ? - if ($source->smarty->use_include_path) { - return $source->smarty->ext->_getIncludePath->getIncludePath($_directories, $file, $source->smarty); - } - return false; - } -} diff --git a/src/Resource/smarty_internal_resource_php.php b/src/Resource/smarty_internal_resource_php.php deleted file mode 100644 index 9d98ae18..00000000 --- a/src/Resource/smarty_internal_resource_php.php +++ /dev/null @@ -1,116 +0,0 @@ -short_open_tag = function_exists('ini_get') ? ini_get('short_open_tag') : 1; - } - - /** - * Load template's source from file into current template object - * - * @param Smarty_Template_Source $source source object - * - * @return string template source - * @throws SmartyException if source cannot be loaded - */ - public function getContent(Smarty_Template_Source $source) - { - if ($source->exists) { - return ''; - } - throw new SmartyException("Unable to read template {$source->type} '{$source->name}'"); - } - - /** - * populate compiled object with compiled filepath - * - * @param Smarty_Template_Compiled $compiled compiled object - * @param Smarty_Internal_Template $_template template object (is ignored) - */ - public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template) - { - $compiled->filepath = $_template->source->filepath; - $compiled->timestamp = $_template->source->timestamp; - $compiled->exists = $_template->source->exists; - $compiled->file_dependency[ $_template->source->uid ] = - array( - $compiled->filepath, - $compiled->timestamp, - $_template->source->type, - ); - } - - /** - * Render and output the template (without using the compiler) - * - * @param Smarty_Template_Source $source source object - * @param Smarty_Internal_Template $_template template object - * - * @return void - * @throws SmartyException if template cannot be loaded or allow_php_templates is disabled - */ - public function renderUncompiled(Smarty_Template_Source $source, Smarty_Internal_Template $_template) - { - if (!$source->smarty->allow_php_templates) { - throw new SmartyException('PHP templates are disabled'); - } - if (!$source->exists) { - throw new SmartyException( - "Unable to load template '{$source->type}:{$source->name}'" . - ($_template->_isSubTpl() ? " in '{$_template->parent->template_resource}'" : '') - ); - } - // prepare variables - extract($_template->getTemplateVars()); - // include PHP template with short open tags enabled - if (function_exists('ini_set')) { - ini_set('short_open_tag', '1'); - } - /** - * - * - * @var Smarty_Internal_Template $_smarty_template - * used in included file - */ - $_smarty_template = $_template; - include $source->filepath; - if (function_exists('ini_set')) { - ini_set('short_open_tag', $this->short_open_tag); - } - } -} diff --git a/src/Resource/smarty_internal_resource_stream.php b/src/Resource/smarty_internal_resource_stream.php deleted file mode 100644 index 5f020349..00000000 --- a/src/Resource/smarty_internal_resource_stream.php +++ /dev/null @@ -1,78 +0,0 @@ -resource, '://') !== false) { - $source->filepath = $source->resource; - } else { - $source->filepath = str_replace(':', '://', $source->resource); - } - $source->uid = false; - $source->content = $this->getContent($source); - $source->timestamp = $source->exists = !!$source->content; - } - - /** - * Load template's source from stream into current template object - * - * @param Smarty_Template_Source $source source object - * - * @return string template source - */ - public function getContent(Smarty_Template_Source $source) - { - $t = ''; - // the availability of the stream has already been checked in Smarty_Resource::fetch() - $fp = fopen($source->filepath, 'r+'); - if ($fp) { - while (!feof($fp) && ($current_line = fgets($fp)) !== false) { - $t .= $current_line; - } - fclose($fp); - return $t; - } else { - return false; - } - } - - /** - * modify resource_name according to resource handlers specifications - * - * @param Smarty $smarty Smarty instance - * @param string $resource_name resource_name to make unique - * @param boolean $isConfig flag for config resource - * - * @return string unique resource name - */ - public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false) - { - return get_class($this) . '#' . $resource_name; - } -} diff --git a/src/Resource/smarty_internal_resource_string.php b/src/Resource/smarty_internal_resource_string.php deleted file mode 100644 index 3fecbb7e..00000000 --- a/src/Resource/smarty_internal_resource_string.php +++ /dev/null @@ -1,108 +0,0 @@ -uid = $source->filepath = sha1($source->name . $source->smarty->_joined_template_dir); - $source->timestamp = $source->exists = true; - } - - /** - * Load template's source from $resource_name into current template object - * - * @uses decode() to decode base64 and urlencoded template_resources - * - * @param Smarty_Template_Source $source source object - * - * @return string template source - */ - public function getContent(Smarty_Template_Source $source) - { - return $this->decode($source->name); - } - - /** - * decode base64 and urlencode - * - * @param string $string template_resource to decode - * - * @return string decoded template_resource - */ - protected function decode($string) - { - // decode if specified - if (($pos = strpos($string, ':')) !== false) { - if (!strncmp($string, 'base64', 6)) { - return base64_decode(substr($string, 7)); - } elseif (!strncmp($string, 'urlencode', 9)) { - return urldecode(substr($string, 10)); - } - } - return $string; - } - - /** - * modify resource_name according to resource handlers specifications - * - * @param Smarty $smarty Smarty instance - * @param string $resource_name resource_name to make unique - * @param boolean $isConfig flag for config resource - * - * @return string unique resource name - */ - public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false) - { - return get_class($this) . '#' . $this->decode($resource_name); - } - - /** - * Determine basename for compiled filename - * Always returns an empty string. - * - * @param Smarty_Template_Source $source source object - * - * @return string resource's basename - */ - public function getBasename(Smarty_Template_Source $source) - { - return ''; - } - - /* - * Disable timestamp checks for string resource. - * - * @return bool - */ - /** - * @return bool - */ - public function checkTimestamps() - { - return false; - } -} diff --git a/src/Resource/smarty_resource_custom.php b/src/Resource/smarty_resource_custom.php deleted file mode 100644 index 191fa7c9..00000000 --- a/src/Resource/smarty_resource_custom.php +++ /dev/null @@ -1,104 +0,0 @@ -filepath = $source->type . ':' . $this->generateSafeName($source->name); - $source->uid = sha1($source->type . ':' . $source->name); - $mtime = $this->fetchTimestamp($source->name); - if ($mtime !== null) { - $source->timestamp = $mtime; - } else { - $this->fetch($source->name, $content, $timestamp); - $source->timestamp = isset($timestamp) ? $timestamp : false; - if (isset($content)) { - $source->content = $content; - } - } - $source->exists = !!$source->timestamp; - } - - /** - * Load template's source into current template object - * - * @param Smarty_Template_Source $source source object - * - * @return string template source - * @throws SmartyException if source cannot be loaded - */ - public function getContent(Smarty_Template_Source $source) - { - $this->fetch($source->name, $content, $timestamp); - if (isset($content)) { - return $content; - } - throw new SmartyException("Unable to read template {$source->type} '{$source->name}'"); - } - - /** - * Determine basename for compiled filename - * - * @param Smarty_Template_Source $source source object - * - * @return string resource's basename - */ - public function getBasename(Smarty_Template_Source $source) - { - return basename($this->generateSafeName($source->name)); - } - - /** - * Removes special characters from $name and limits its length to 127 characters. - * - * @param $name - * - * @return string - */ - private function generateSafeName($name): string { - return substr(preg_replace('/[^A-Za-z0-9._]/', '', (string) $name), 0, 127); - } -} diff --git a/src/Resource/smarty_resource_recompiled.php b/src/Resource/smarty_resource_recompiled.php deleted file mode 100644 index 760c4dd3..00000000 --- a/src/Resource/smarty_resource_recompiled.php +++ /dev/null @@ -1,94 +0,0 @@ -compiled; - $compiled->file_dependency = array(); - $compiled->includes = array(); - $compiled->nocache_hash = null; - $compiled->unifunc = null; - $level = ob_get_level(); - ob_start(); - $_smarty_tpl->loadCompiler(); - // call compiler - try { - eval('?>' . $_smarty_tpl->compiler->compileTemplate($_smarty_tpl)); - } catch (Exception $e) { - unset($_smarty_tpl->compiler); - while (ob_get_level() > $level) { - ob_end_clean(); - } - throw $e; - } - // release compiler object to free memory - unset($_smarty_tpl->compiler); - ob_get_clean(); - $compiled->timestamp = time(); - $compiled->exists = true; - } - - /** - * populate Compiled Object with compiled filepath - * - * @param Smarty_Template_Compiled $compiled compiled object - * @param Smarty_Internal_Template $_template template object - * - * @return void - */ - public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template) - { - $compiled->filepath = false; - $compiled->timestamp = false; - $compiled->exists = false; - } - - /* - * Disable timestamp checks for recompiled resource. - * - * @return bool - */ - /** - * @return bool - */ - public function checkTimestamps() - { - return false; - } -} diff --git a/src/Resource/smarty_resource_uncompiled.php b/src/Resource/smarty_resource_uncompiled.php deleted file mode 100644 index a11e2c14..00000000 --- a/src/Resource/smarty_resource_uncompiled.php +++ /dev/null @@ -1,49 +0,0 @@ -filepath = $_template->source->filepath; - $compiled->timestamp = $_template->source->timestamp; - $compiled->exists = $_template->source->exists; - if ($_template->smarty->merge_compiled_includes || $_template->source->handler->checkTimestamps()) { - $compiled->file_dependency[ $_template->source->uid ] = - array($compiled->filepath, $compiled->timestamp, $_template->source->type,); - } - } -} diff --git a/src/Smarty.php b/src/Smarty.php index 8d5e08fc..398143e3 100644 --- a/src/Smarty.php +++ b/src/Smarty.php @@ -919,7 +919,7 @@ class Smarty extends \Smarty_Internal_TemplateBase $caching = (int)($caching === null ? $this->caching : $caching); if ((isset($template) && strpos($template_name, ':.') !== false) || $this->allow_ambiguous_resources) { $_templateId = - \Smarty_Resource::getUniqueTemplateName((isset($template) ? $template : $this), $template_name) . + \Smarty\Resource\BasePlugin::getUniqueTemplateName((isset($template) ? $template : $this), $template_name) . "#{$cache_id}#{$compile_id}#{$caching}"; } else { $_templateId = $this->_joined_template_dir . "#{$template_name}#{$cache_id}#{$compile_id}#{$caching}"; diff --git a/src/Template/smarty_template_config.php b/src/Template/smarty_template_config.php index b81e73dd..966a80e0 100644 --- a/src/Template/smarty_template_config.php +++ b/src/Template/smarty_template_config.php @@ -84,7 +84,7 @@ class Smarty_Template_Config extends Smarty_Template_Source throw new SmartyException('Source: Missing name'); } // parse resource_name, load resource handler - list($name, $type) = Smarty_Resource::parseResourceName($template_resource, $smarty->default_config_type); + list($name, $type) = Smarty\Resource\BasePlugin::parseResourceName($template_resource, $smarty->default_config_type); // make sure configs are not loaded via anything smarty can't handle if (isset($_incompatible_resources[ $type ])) { throw new SmartyException("Unable to use resource '{$type}' for config"); diff --git a/src/Template/smarty_template_source.php b/src/Template/smarty_template_source.php index e2e432be..a409d322 100644 --- a/src/Template/smarty_template_source.php +++ b/src/Template/smarty_template_source.php @@ -76,7 +76,7 @@ class Smarty_Template_Source /** * Resource Handler * - * @var \Smarty_Resource + * @var \Smarty\Resource\BasePlugin */ public $handler = null; @@ -131,11 +131,11 @@ class Smarty_Template_Source * @param string $name resource name * * @throws \SmartyException - * @internal param \Smarty_Resource $handler Resource Handler this source object communicates with + * @internal param \Smarty\Resource\Base $handler Resource Handler this source object communicates with */ public function __construct(Smarty $smarty, $resource, $type, $name) { - $this->handler = Smarty_Resource::load($smarty, $type); + $this->handler = Smarty\Resource\BasePlugin::load($smarty, $type); $this->smarty = $smarty; $this->resource = $resource; @@ -239,7 +239,7 @@ class Smarty_Template_Source $this->content = $_content; $this->exists = true; $this->uid = $this->name = sha1($_content); - $this->handler = Smarty_Resource::load($this->smarty, 'eval'); + $this->handler = Smarty\Resource\BasePlugin::load($this->smarty, 'eval'); } else { $this->exists = false; throw new SmartyException( diff --git a/src/smarty_internal_template.php b/src/smarty_internal_template.php index 70c0fda4..0b1b5c2a 100644 --- a/src/smarty_internal_template.php +++ b/src/smarty_internal_template.php @@ -463,7 +463,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase $mtime = is_file($_file_to_check[ 0 ]) ? filemtime($_file_to_check[ 0 ]) : false; } } else { - $handler = Smarty_Resource::load($tpl->smarty, $_file_to_check[ 2 ]); + $handler = Smarty\Resource\BasePlugin::load($tpl->smarty, $_file_to_check[ 2 ]); if ($handler->checkTimestamps()) { $source = Smarty_Template_Source::load($tpl, $tpl->smarty, $_file_to_check[ 0 ]); $mtime = $source->getTimeStamp(); diff --git a/src/smarty_internal_templatebase.php b/src/smarty_internal_templatebase.php index 0c17f92b..f19791f3 100644 --- a/src/smarty_internal_templatebase.php +++ b/src/smarty_internal_templatebase.php @@ -857,11 +857,11 @@ abstract class Smarty_Internal_TemplateBase extends Data * @link https://www.smarty.net/docs/en/api.register.resource.tpl * * @param string $name name of resource type - * @param Smarty_Resource $resource_handler instance of Smarty_Resource + * @param Smarty\Resource\Base $resource_handler instance of Smarty\Resource\Base * * @return \Smarty|\Smarty_Internal_Template */ - public function registerResource($name, Smarty_Resource $resource_handler) + public function registerResource($name, Smarty\Resource\Base $resource_handler) { $smarty = $this->_getSmartyObj(); $smarty->registered_resources[ $name ] = $resource_handler; diff --git a/tests/UnitTests/CacheResourceTests/_shared/PHPunitplugins/resource.filetest.php b/tests/UnitTests/CacheResourceTests/_shared/PHPunitplugins/resource.filetest.php index d5676d61..26da8f5a 100644 --- a/tests/UnitTests/CacheResourceTests/_shared/PHPunitplugins/resource.filetest.php +++ b/tests/UnitTests/CacheResourceTests/_shared/PHPunitplugins/resource.filetest.php @@ -1,6 +1,8 @@ smarty->registerResource('ambiguous', $resource_handler); $this->smarty->setDefaultResourceType('ambiguous'); $this->smarty->setAllowAmbiguousResources(true); @@ -63,7 +63,7 @@ class CustomResourceAmbiguousTest extends PHPUnit_Smarty */ public function testCase1() { - $resource_handler = new Smarty_Resource_Ambiguous(__DIR__ . '/templates/ambiguous/'); + $resource_handler = new Smarty_Resource_AmbiguousPlugin(__DIR__ . '/templates/ambiguous/'); $this->smarty->registerResource('ambiguous', $resource_handler); $this->smarty->setDefaultResourceType('ambiguous'); $this->smarty->setAllowAmbiguousResources(true); @@ -83,7 +83,7 @@ class CustomResourceAmbiguousTest extends PHPUnit_Smarty */ public function testCase2() { - $resource_handler = new Smarty_Resource_Ambiguous(__DIR__ . '/templates/ambiguous/'); + $resource_handler = new Smarty_Resource_AmbiguousPlugin(__DIR__ . '/templates/ambiguous/'); $this->smarty->registerResource('ambiguous', $resource_handler); $this->smarty->setDefaultResourceType('ambiguous'); $this->smarty->setAllowAmbiguousResources(true); @@ -103,7 +103,7 @@ class CustomResourceAmbiguousTest extends PHPUnit_Smarty */ public function testCaseSwitching() { - $resource_handler = new Smarty_Resource_Ambiguous(__DIR__ . '/templates/ambiguous/'); + $resource_handler = new Smarty_Resource_AmbiguousPlugin(__DIR__ . '/templates/ambiguous/'); $this->smarty->registerResource('ambiguous', $resource_handler); $this->smarty->setDefaultResourceType('ambiguous'); $this->smarty->setAllowAmbiguousResources(true); diff --git a/tests/UnitTests/ResourceTests/Custom/Ambiguous/PHPunitplugins/resource.ambiguous.php b/tests/UnitTests/ResourceTests/Custom/Ambiguous/PHPunitplugins/resource.ambiguous.php index 934b8aa0..cb4b31de 100644 --- a/tests/UnitTests/ResourceTests/Custom/Ambiguous/PHPunitplugins/resource.ambiguous.php +++ b/tests/UnitTests/ResourceTests/Custom/Ambiguous/PHPunitplugins/resource.ambiguous.php @@ -1,12 +1,14 @@ resource tests * @@ -20,7 +22,7 @@ class RegisteredResourceTest extends PHPUnit_Smarty { $this->setUpSmarty(__DIR__); - $this->smarty->registerResource("rr", new RegisteredResourceTest_Resource1()); + $this->smarty->registerResource("rr", new RegisteredResourceTest_Resource1Plugin()); } @@ -56,7 +58,7 @@ class RegisteredResourceTest extends PHPUnit_Smarty */ public function testResourceCompileIdChange() { - $this->smarty->registerResource('myresource', new RegisteredResourceTest_Resource2()); + $this->smarty->registerResource('myresource', new RegisteredResourceTest_Resource2Plugin()); $this->smarty->compile_id = 'a'; $this->assertEquals('this is template 1', $this->smarty->fetch('myresource:some')); $this->assertEquals('this is template 1', $this->smarty->fetch('myresource:some')); @@ -69,7 +71,7 @@ class RegisteredResourceTest extends PHPUnit_Smarty * */ public function testSmartyTemplate() { - $this->smarty->registerResource('mytpl', new RegisteredResourceTest_Resource3()); + $this->smarty->registerResource('mytpl', new RegisteredResourceTest_Resource3Plugin()); $this->assertEquals('template = mytpl:foo', $this->smarty->fetch('mytpl:foo')); } /** @@ -77,12 +79,12 @@ class RegisteredResourceTest extends PHPUnit_Smarty * */ public function testSmartyCurrentDir() { - $this->smarty->registerResource('mytpl', new RegisteredResourceTest_Resource4()); + $this->smarty->registerResource('mytpl', new RegisteredResourceTest_Resource4Plugin()); $this->assertEquals('current_dir = .', $this->smarty->fetch('mytpl:bar')); } } -class RegisteredResourceTest_Resource1 extends Smarty_Resource_Custom { +class RegisteredResourceTest_Resource1Plugin extends CustomPlugin { protected function fetch($name, &$source, &$mtime) { $source = '{$x="hello world"}{$x}'; @@ -91,7 +93,7 @@ class RegisteredResourceTest_Resource1 extends Smarty_Resource_Custom { } -class RegisteredResourceTest_Resource2 extends Smarty_Resource_Custom { +class RegisteredResourceTest_Resource2Plugin extends CustomPlugin { protected function fetch($name, &$source, &$mtime) { @@ -112,7 +114,7 @@ class RegisteredResourceTest_Resource2 extends Smarty_Resource_Custom { } -class RegisteredResourceTest_Resource3 extends Smarty_Resource_Custom { +class RegisteredResourceTest_Resource3Plugin extends CustomPlugin { protected function fetch($name, &$source, &$mtime) { $source = 'template = {$smarty.template}'; @@ -121,7 +123,7 @@ class RegisteredResourceTest_Resource3 extends Smarty_Resource_Custom { } -class RegisteredResourceTest_Resource4 extends Smarty_Resource_Custom { +class RegisteredResourceTest_Resource4Plugin extends CustomPlugin { protected function fetch($name, &$source, &$mtime) { $source = 'current_dir = {$smarty.current_dir}'; diff --git a/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db.php b/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db.php index 668b83da..6f047c0c 100644 --- a/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db.php +++ b/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db.php @@ -10,7 +10,9 @@ * ------------------------------------------------------------- */ -class Smarty_Resource_Db extends Smarty_Resource_Recompiled { +use Smarty\Resource\RecompiledPlugin; + +class _DbPlugin extends RecompiledPlugin { public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) { $source->filepath = 'db:'; diff --git a/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db2.php b/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db2.php index 3eefce7c..978e9cc9 100644 --- a/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db2.php +++ b/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db2.php @@ -10,7 +10,9 @@ * ------------------------------------------------------------- */ -class Smarty_Resource_Db2 extends Smarty_Resource_Recompiled +use Smarty\Resource\RecompiledPlugin; + +class _Db2Plugin extends RecompiledPlugin { public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) { diff --git a/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db3.php b/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db3.php index 0b07233b..cf492d9c 100644 --- a/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db3.php +++ b/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db3.php @@ -10,7 +10,7 @@ * ------------------------------------------------------------- */ -class Smarty_Resource_Db3 extends Smarty_Resource +class Smarty_Resource_Db3 extends Smarty\Resource\BasePlugin { public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) { diff --git a/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db4.php b/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db4.php index 611d3e43..3c0fd3fd 100644 --- a/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db4.php +++ b/tests/UnitTests/ResourceTests/ResourcePlugins/PHPunitplugins/resource.db4.php @@ -10,7 +10,7 @@ * ------------------------------------------------------------- */ -class Smarty_Resource_Db4 extends Smarty_Resource +class Smarty_Resource_Db4 extends Smarty\Resource\BasePlugin { public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) { diff --git a/tests/UnitTests/ResourceTests/ResourcePlugins/ResourcePluginTest.php b/tests/UnitTests/ResourceTests/ResourcePlugins/ResourcePluginTest.php index 9aa46718..5e3ea53b 100644 --- a/tests/UnitTests/ResourceTests/ResourcePlugins/ResourcePluginTest.php +++ b/tests/UnitTests/ResourceTests/ResourcePlugins/ResourcePluginTest.php @@ -49,8 +49,8 @@ class ResourcePluginTest extends PHPUnit_Smarty public function testResourcePluginRegisteredInstance() { $this->smarty->addPluginsDir("./PHPunitplugins/"); - $this->smarty->loadPlugin('Smarty_Resource_Db2'); - $this->smarty->registerResource('db2a', new Smarty_Resource_Db2('db2a')); + $this->smarty->loadPlugin('_Db2Plugin'); + $this->smarty->registerResource('db2a', new _Db2Plugin('db2a')); $this->assertEquals('hello world', $this->smarty->fetch('db2a:test')); }