- improvement move often used code snippets into methods

This commit is contained in:
uwetews
2016-09-11 04:35:52 +02:00
parent e62b40c421
commit 0a8e47ecb2
47 changed files with 124 additions and 77 deletions

View File

@@ -1,7 +1,8 @@
===== 3.1.31-dev ===== (xx.xx.xx)
11.09.2016
- improvement {math} misleading E_USER_WARNING messages when parameter value = null https://github.com/smarty-php/smarty/issues/288
- improvement move often used code snippets into methods
09.09.2016
- bugfix/optimization {foreach} did not execute the {foreachelse} when iterating empty objects https://github.com/smarty-php/smarty/pull/287
- bugfix {foreach} must keep the @properties when restoring a saved $item variable as the properties might be used outside {foreach} https://github.com/smarty-php/smarty/issues/267

View File

@@ -114,7 +114,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* smarty version
*/
const SMARTY_VERSION = '3.1.31-dev/16';
const SMARTY_VERSION = '3.1.31-dev/17';
/**
* define variable scopes
@@ -1243,6 +1243,16 @@ class Smarty extends Smarty_Internal_TemplateBase
$this->_cache[ 'tplObjects' ] = array();
}
/**
* Get Smarty object
*
* @return Smarty
*/
public function _getSmartyObj()
{
return $this;
}
/**
* @param boolean $compile_check
*/

View File

@@ -14,7 +14,8 @@
* @package Smarty
* @subpackage Template
*
* @property int $scope
* @property int $scope
* @property Smarty $smarty
* The following methods will be dynamically loaded by the extension handler when they are called.
* They are located in a corresponding Smarty_Internal_Method_xxxx class
*
@@ -100,7 +101,7 @@ class Smarty_Internal_Data
}
} else {
if ($tpl_var != '') {
if ($this->_objType == 2) {
if ($this->_objType === 2) {
/** @var Smarty_Internal_Template $this */
$this->_assignInScope($tpl_var, $value, $nocache);
} else {
@@ -228,6 +229,46 @@ class Smarty_Internal_Data
}
}
/**
* Return true if this instance is a Data obj
*
* @return bool
*/
public function _isDataObj()
{
return $this->_objType === 4;
}
/**
* Return true if this instance is a template obj
*
* @return bool
*/
public function _isTplObj()
{
return $this->_objType === 2;
}
/**
* Return true if this instance is a Smarty obj
*
* @return bool
*/
public function _isSmartyObj()
{
return $this->_objType === 1;
}
/**
* Get Smarty object
*
* @return Smarty
*/
public function _getSmartyObj()
{
return $this->smarty;
}
/**
* Handle unknown class methods
*

View File

@@ -52,7 +52,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
*/
public function start_template(Smarty_Internal_Template $template, $mode = null)
{
if (isset($mode) && (!isset($template->parent) || $template->parent->_objType !== 2)) {
if (isset($mode) && !$template->_isSubTpl()) {
$this->index ++;
$this->offset ++;
$this->template_data[ $this->index ] = null;
@@ -201,11 +201,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
$savedIndex = $this->index;
$this->index = 9999;
}
if ($obj->_objType == 1) {
$smarty = $obj;
} else {
$smarty = $obj->smarty;
}
$smarty = $obj->_getSmartyObj();
// create fresh instance of smarty for displaying the debug console
// to avoid problems if the application did overload the Smarty class
$debObj = new Smarty();
@@ -240,7 +236,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
$debugging = $smarty->debugging;
$_template = new Smarty_Internal_Template($debObj->debug_tpl, $debObj);
if ($obj->_objType == 2) {
if ($obj->_isTplObj()) {
$_template->assign('template_name', $obj->source->type . ':' . $obj->source->name);
}
if ($obj->_objType == 1 || $full) {
@@ -274,9 +270,9 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
$config_vars = array();
foreach ($obj->config_vars as $key => $var) {
$config_vars[ $key ][ 'value' ] = $var;
if ($obj->_objType == 2) {
if ($obj->_isTplObj()) {
$config_vars[ $key ][ 'scope' ] = $obj->source->type . ':' . $obj->source->name;
} elseif ($obj->_objType == 4) {
} elseif ($obj->_isDataObj()) {
$tpl_vars[ $key ][ 'scope' ] = $obj->dataObjectName;
} else {
$config_vars[ $key ][ 'scope' ] = 'Smarty object';
@@ -299,9 +295,9 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
}
}
}
if ($obj->_objType == 2) {
if ($obj->_isTplObj()) {
$tpl_vars[ $key ][ 'scope' ] = $obj->source->type . ':' . $obj->source->name;
} elseif ($obj->_objType == 4) {
} elseif ($obj->_isDataObj()) {
$tpl_vars[ $key ][ 'scope' ] = $obj->dataObjectName;
} else {
$tpl_vars[ $key ][ 'scope' ] = 'Smarty object';

View File

@@ -77,7 +77,7 @@ class Smarty_Internal_Extension_Handler
- 1, PREG_SPLIT_NO_EMPTY |
PREG_SPLIT_DELIM_CAPTURE)));
$this->_property_info[ $prop ] = property_exists($data, $pn) ? 1 :
($data->_objType == 2 && property_exists($smarty, $pn) ? 2 : 0);
($data->_isTplObj() && property_exists($smarty, $pn) ? 2 : 0);
}
if ($this->_property_info[ $prop ]) {
$pn = $this->resolvedProperties[ $prop ];

View File

@@ -28,7 +28,7 @@ class Smarty_Internal_Method_AddAutoloadFilters extends Smarty_Internal_Method_S
*/
public function addAutoloadFilters(Smarty_Internal_TemplateBase $obj, $filters, $type = null)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty = $obj->_getSmartyObj();
if ($type !== null) {
$this->_checkFilterType($type);
if (!empty($smarty->autoload_filters[ $type ])) {

View File

@@ -31,7 +31,7 @@ class Smarty_Internal_Method_AddDefaultModifiers
*/
public function addDefaultModifiers(Smarty_Internal_TemplateBase $obj, $modifiers)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty = $obj->_getSmartyObj();
if (is_array($modifiers)) {
$smarty->default_modifiers = array_merge($smarty->default_modifiers, $modifiers);
} else {

View File

@@ -65,7 +65,7 @@ class Smarty_Internal_Method_Append
$data->tpl_vars[ $tpl_var ]->value[] = $value;
}
}
if ($data->_objType == 2 && $data->scope) {
if ($data->_isTplObj() && $data->scope) {
$data->ext->_updateScope->_updateScope($data, $tpl_var);
}
}

View File

@@ -41,7 +41,7 @@ class Smarty_Internal_Method_AppendByRef
} else {
$data->tpl_vars[ $tpl_var ]->value[] = &$value;
}
if ($data->_objType == 2 && $data->scope) {
if ($data->_isTplObj() && $data->scope) {
$data->ext->_updateScope->_updateScope($data, $tpl_var);
}
}

View File

@@ -27,7 +27,7 @@ class Smarty_Internal_Method_AssignByRef
if ($tpl_var != '') {
$data->tpl_vars[ $tpl_var ] = new Smarty_Variable(null, $nocache);
$data->tpl_vars[ $tpl_var ]->value = &$value;
if ($data->_objType == 2 && $data->scope) {
if ($data->_isTplObj() && $data->scope) {
$data->ext->_updateScope->_updateScope($data, $tpl_var);
}
}

View File

@@ -33,7 +33,7 @@ class Smarty_Internal_Method_AssignGlobal
if ($varName != '') {
Smarty::$global_tpl_vars[ $varName ] = new Smarty_Variable($value, $nocache);
$ptr = $data;
while ($ptr->_objType == 2) {
while ($ptr->_isTplObj()) {
$ptr->tpl_vars[ $varName ] = clone Smarty::$global_tpl_vars[ $varName ];
$ptr = $ptr->parent;
}

View File

@@ -66,7 +66,7 @@ class Smarty_Internal_Method_ConfigLoad
$confObj->source->scope = $scope;
$confObj->compiled = Smarty_Template_Compiled::load($confObj);
$confObj->compiled->render($confObj);
if ($data->_objType == 2) {
if ($data->_isTplObj()) {
$data->compiled->file_dependency[ $confObj->source->uid ] =
array($confObj->source->filepath, $confObj->source->getTimeStamp(), $confObj->source->type);
}
@@ -91,13 +91,13 @@ class Smarty_Internal_Method_ConfigLoad
return;
}
}
if ($tpl->parent->_objType == 2 && ($tagScope || $tpl->parent->scope)) {
if ($tpl->parent->_isTplObj() && ($tagScope || $tpl->parent->scope)) {
$mergedScope = $tagScope | $tpl->scope;
if ($mergedScope) {
// update scopes
foreach ($tpl->smarty->ext->_updateScope->_getAffectedScopes($tpl->parent, $mergedScope) as $ptr) {
$this->_assignConfigVars($ptr->config_vars, $tpl, $new_config_vars);
if ($tagScope && $ptr->_objType == 2 && isset($tpl->_cache[ 'varStack' ])) {
if ($tagScope && $ptr->_isTplObj() && isset($tpl->_cache[ 'varStack' ])) {
$this->_updateVarStack($tpl, $new_config_vars);
}
}

View File

@@ -34,7 +34,7 @@ class Smarty_Internal_Method_CreateData
public function createData(Smarty_Internal_TemplateBase $obj, Smarty_Internal_Data $parent = null, $name = null)
{
/* @var Smarty $smarty */
$smarty = isset($this->smarty) ? $this->smarty : $obj;
$smarty = $obj->_getSmartyObj();
$dataObj = new Smarty_Data($parent, $smarty, $name);
if ($smarty->debugging) {
Smarty_Internal_Debug::register_data($dataObj);

View File

@@ -27,7 +27,7 @@ class Smarty_Internal_Method_GetAutoloadFilters extends Smarty_Internal_Method_S
*/
public function getAutoloadFilters(Smarty_Internal_TemplateBase $obj, $type = null)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty = $obj->_getSmartyObj();
if ($type !== null) {
$this->_checkFilterType($type);
return isset($smarty->autoload_filters[ $type ]) ? $smarty->autoload_filters[ $type ] : array();

View File

@@ -29,7 +29,7 @@ class Smarty_Internal_Method_GetDebugTemplate
*/
public function getDebugTemplate(Smarty_Internal_TemplateBase $obj)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty = $obj->_getSmartyObj();
return $smarty->debug_tpl;
}
}

View File

@@ -29,7 +29,7 @@ class Smarty_Internal_Method_GetDefaultModifiers
*/
public function getDefaultModifiers(Smarty_Internal_TemplateBase $obj)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty = $obj->_getSmartyObj();
return $smarty->default_modifiers;
}
}

View File

@@ -32,7 +32,7 @@ class Smarty_Internal_Method_GetRegisteredObject
*/
public function getRegisteredObject(Smarty_Internal_TemplateBase $obj, $object_name)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty = $obj->_getSmartyObj();
if (!isset($smarty->registered_objects[ $object_name ])) {
throw new SmartyException("'$object_name' is not a registered object");
}

View File

@@ -33,10 +33,10 @@ class Smarty_Internal_Method_GetTags
public function getTags(Smarty_Internal_TemplateBase $obj, $template = null)
{
/* @var Smarty $smarty */
$smarty = isset($this->smarty) ? $this->smarty : $obj;
if ($obj->_objType == 2 && !isset($template)) {
$smarty = $obj->_getSmartyObj();
if ($obj->_isTplObj() && !isset($template)) {
$tpl = clone $obj;
} elseif (isset($template) && $template->_objType == 2) {
} elseif (isset($template) && $template->_isTplObj()) {
$tpl = clone $template;
} elseif (isset($template) && is_string($template)) {
/* @var Smarty_Internal_Template $tpl */

View File

@@ -41,7 +41,7 @@ class Smarty_Internal_Method_LoadFilter
*/
public function loadFilter(Smarty_Internal_TemplateBase $obj, $type, $name)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty = $obj->_getSmartyObj();
$this->_checkFilterType($type);
$_plugin = "smarty_{$type}filter_{$name}";
$_filter_name = $_plugin;

View File

@@ -31,7 +31,7 @@ class Smarty_Internal_Method_MustCompile
public function mustCompile(Smarty_Internal_Template $_template)
{
if (!$_template->source->exists) {
if (isset($_template->parent) && $_template->parent->_objType == 2) {
if ($_template->_isSubTpl()) {
$parent_resource = " in '$_template->parent->template_resource}'";
} else {
$parent_resource = '';

View File

@@ -33,7 +33,7 @@ class Smarty_Internal_Method_RegisterCacheResource
public function registerCacheResource(Smarty_Internal_TemplateBase $obj, $name,
Smarty_CacheResource $resource_handler)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty = $obj->_getSmartyObj();
$smarty->registered_cache_resources[ $name ] = $resource_handler;
return $obj;
}

View File

@@ -34,7 +34,7 @@ class Smarty_Internal_Method_RegisterClass
*/
public function registerClass(Smarty_Internal_TemplateBase $obj, $class_name, $class_impl)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty = $obj->_getSmartyObj();
// test if exists
if (!class_exists($class_impl)) {
throw new SmartyException("Undefined class '$class_impl' in register template class");

View File

@@ -31,7 +31,7 @@ class Smarty_Internal_Method_RegisterDefaultConfigHandler
*/
public function registerDefaultConfigHandler(Smarty_Internal_TemplateBase $obj, $callback)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty = $obj->_getSmartyObj();
if (is_callable($callback)) {
$smarty->default_config_handler_func = $callback;
} else {

View File

@@ -32,7 +32,7 @@ class Smarty_Internal_Method_RegisterDefaultPluginHandler
*/
public function registerDefaultPluginHandler(Smarty_Internal_TemplateBase $obj, $callback)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty = $obj->_getSmartyObj();
if (is_callable($callback)) {
$smarty->default_plugin_handler_func = $callback;
} else {

View File

@@ -31,7 +31,7 @@ class Smarty_Internal_Method_RegisterDefaultTemplateHandler
*/
public function registerDefaultTemplateHandler(Smarty_Internal_TemplateBase $obj, $callback)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty = $obj->_getSmartyObj();
if (is_callable($callback)) {
$smarty->default_template_handler_func = $callback;
} else {

View File

@@ -42,7 +42,7 @@ class Smarty_Internal_Method_RegisterFilter
*/
public function registerFilter(Smarty_Internal_TemplateBase $obj, $type, $callback, $name = null)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty = $obj->_getSmartyObj();
$this->_checkFilterType($type);
$name = isset($name) ? $name : $this->_getFilterName($callback);
if (!is_callable($callback)) {

View File

@@ -47,7 +47,7 @@ class Smarty_Internal_Method_RegisterObject
public function registerObject(Smarty_Internal_TemplateBase $obj, $object_name, $object,
$allowed_methods_properties = array(), $format = true, $block_methods = array())
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty = $obj->_getSmartyObj();
// test if allowed methods callable
if (!empty($allowed_methods_properties)) {
foreach ((array) $allowed_methods_properties as $method) {

View File

@@ -38,7 +38,7 @@ class Smarty_Internal_Method_RegisterPlugin
public function registerPlugin(Smarty_Internal_TemplateBase $obj, $type, $name, $callback, $cacheable = true,
$cache_attr = null)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty = $obj->_getSmartyObj();
if (isset($smarty->registered_plugins[ $type ][ $name ])) {
throw new SmartyException("Plugin tag \"{$name}\" already registered");
} elseif (!is_callable($callback)) {

View File

@@ -36,7 +36,7 @@ class Smarty_Internal_Method_RegisterResource
*/
public function registerResource(Smarty_Internal_TemplateBase $obj, $name, $resource_handler)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty = $obj->_getSmartyObj();
$smarty->registered_resources[ $name ] =
$resource_handler instanceof Smarty_Resource ? $resource_handler : array($resource_handler, false);
return $obj;

View File

@@ -41,7 +41,7 @@ class Smarty_Internal_Method_SetAutoloadFilters
*/
public function setAutoloadFilters(Smarty_Internal_TemplateBase $obj, $filters, $type = null)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty = $obj->_getSmartyObj();
if ($type !== null) {
$this->_checkFilterType($type);
$smarty->autoload_filters[ $type ] = (array) $filters;

View File

@@ -31,7 +31,7 @@ class Smarty_Internal_Method_SetDebugTemplate
*/
public function setDebugTemplate(Smarty_Internal_TemplateBase $obj, $tpl_name)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty = $obj->_getSmartyObj();
if (!is_readable($tpl_name)) {
throw new SmartyException("Unknown file '{$tpl_name}'");
}

View File

@@ -31,7 +31,7 @@ class Smarty_Internal_Method_SetDefaultModifiers
*/
public function setDefaultModifiers(Smarty_Internal_TemplateBase $obj, $modifiers)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty = $obj->_getSmartyObj();
$smarty->default_modifiers = (array) $modifiers;
return $obj;
}

View File

@@ -26,7 +26,7 @@ class Smarty_Internal_Method_UnloadFilter extends Smarty_Internal_Method_LoadFil
*/
public function unloadFilter(Smarty_Internal_TemplateBase $obj, $type, $name)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty = $obj->_getSmartyObj();
$this->_checkFilterType($type);
if (isset($smarty->registered_filters[ $type ])) {
$_filter_name = "smarty_{$type}filter_{$name}";

View File

@@ -31,7 +31,7 @@ class Smarty_Internal_Method_UnregisterCacheResource
*/
public function unregisterCacheResource(Smarty_Internal_TemplateBase $obj, $name)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty = $obj->_getSmartyObj();
if (isset($smarty->registered_cache_resources[ $name ])) {
unset($smarty->registered_cache_resources[ $name ]);
}

View File

@@ -26,7 +26,7 @@ class Smarty_Internal_Method_UnregisterFilter extends Smarty_Internal_Method_Reg
*/
public function unregisterFilter(Smarty_Internal_TemplateBase $obj, $type, $callback)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty = $obj->_getSmartyObj();
$this->_checkFilterType($type);
if (isset($smarty->registered_filters[ $type ])) {
$name = is_string($callback) ? $callback : $this->_getFilterName($callback);

View File

@@ -31,7 +31,7 @@ class Smarty_Internal_Method_UnregisterObject
*/
public function unregisterObject(Smarty_Internal_TemplateBase $obj, $object_name)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty = $obj->_getSmartyObj();
if (isset($smarty->registered_objects[ $object_name ])) {
unset($smarty->registered_objects[ $object_name ]);
}

View File

@@ -32,7 +32,7 @@ class Smarty_Internal_Method_UnregisterPlugin
*/
public function unregisterPlugin(Smarty_Internal_TemplateBase $obj, $type, $name)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty = $obj->_getSmartyObj();
if (isset($smarty->registered_plugins[ $type ][ $name ])) {
unset($smarty->registered_plugins[ $type ][ $name ]);
}

View File

@@ -31,7 +31,7 @@ class Smarty_Internal_Method_UnregisterResource
*/
public function unregisterResource(Smarty_Internal_TemplateBase $obj, $type)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$smarty = $obj->_getSmartyObj();
if (isset($smarty->registered_resources[ $type ])) {
unset($smarty->registered_resources[ $type ]);
}

View File

@@ -43,7 +43,7 @@ class Smarty_Internal_Nocache_Insert
$_output .= "echo {$_function}(" . var_export($_attr, true) . ",\$_smarty_tpl);?>";
}
$_tpl = $_template;
while (isset($_tpl->parent) && $_tpl->parent->_objType == 2) {
while ($_tpl->_isSubTpl()) {
$_tpl = $_tpl->parent;
}

View File

@@ -35,7 +35,7 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
return is_file($file) ? $file : false;
}
// go relative to a given template?
if ($file[ 0 ] == '.' && $_template && isset($_template->parent) && $_template->parent->_objType == 2 &&
if ($file[ 0 ] == '.' && $_template && $_template->_isSubTpl() &&
preg_match('#^[.]{1,2}[\\\/]#', $file)
) {
if ($_template->parent->source->type != 'file' && $_template->parent->source->type != 'extends' &&

View File

@@ -71,9 +71,8 @@ class Smarty_Internal_Resource_Php extends Smarty_Internal_Resource_File
throw new SmartyException("PHP templates are disabled");
}
if (!$source->exists) {
$parentIsTpl = isset($this->parent) && $this->parent->_objType == 2;
throw new SmartyException("Unable to load template {$source->type} '{$source->name}'" .
($parentIsTpl ? " in '{$this->parent->template_resource}'" : ''));
($_template->_isSubTpl() ? " in '{$_template->parent->template_resource}'" : ''));
}
// prepare variables

View File

@@ -67,7 +67,7 @@ class Smarty_Internal_Runtime_TplFunction
$this->tplFunctions = array_merge($this->tplFunctions, $tplFunctions);
$ptr = $tpl;
// make sure that the template functions are known in parent templates
while (isset($ptr->parent) && $ptr->parent->_objType === 2 && !isset($ptr->ext->_tplFunction)) {
while ($ptr->_isTplObj() && !isset($ptr->ext->_tplFunction)) {
$ptr->ext->_tplFunction = $this;
$ptr = $ptr->parent;
}

View File

@@ -93,7 +93,7 @@ class Smarty_Internal_Runtime_UpdateCache
$this->removeNoCacheHash($cached, $_template, $no_output_filter);
$compile_check = $_template->smarty->compile_check;
$_template->smarty->compile_check = false;
if (isset($_template->parent) && $_template->parent->_objType == 2) {
if ($_template->_isSubTpl()) {
$_template->compiled->unifunc = $_template->parent->compiled->unifunc;
}
if (!$_template->cached->processed) {

View File

@@ -34,7 +34,7 @@ class Smarty_Internal_Runtime_UpdateScope
// update scopes
foreach ($this->_getAffectedScopes($tpl, $mergedScope) as $ptr) {
$this->_updateVariableInOtherScope($ptr->tpl_vars, $tpl, $varName);
if($tagScope && $ptr->_objType == 2 && isset($tpl->_cache[ 'varStack' ])) {
if($tagScope && $ptr->_isTplObj() && isset($tpl->_cache[ 'varStack' ])) {
$this->_updateVarStack($ptr, $varName); }
}
}
@@ -52,7 +52,7 @@ class Smarty_Internal_Runtime_UpdateScope
{
$_stack = array();
$ptr = $tpl->parent;
if ($mergedScope && isset($ptr) && $ptr->_objType == 2) {
if ($mergedScope && isset($ptr) && $ptr->_isTplObj()) {
$_stack[] = $ptr;
$mergedScope = $mergedScope & ~Smarty::SCOPE_PARENT;
if (!$mergedScope) {
@@ -61,7 +61,7 @@ class Smarty_Internal_Runtime_UpdateScope
}
$ptr = $ptr->parent;
}
while (isset($ptr) && $ptr->_objType == 2) {
while (isset($ptr) && $ptr->_isTplObj()) {
$_stack[] = $ptr;
$ptr = $ptr->parent;
}
@@ -71,7 +71,7 @@ class Smarty_Internal_Runtime_UpdateScope
}
} elseif ($mergedScope & Smarty::SCOPE_ROOT) {
while (isset($ptr)) {
if ($ptr->_objType != 2) {
if (!$ptr->_isTplObj()) {
$_stack[] = $ptr;
break;
}

View File

@@ -151,7 +151,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
*/
public function render($no_output_filter = true, $display = null)
{
$parentIsTpl = isset($this->parent) && $this->parent->_objType == 2;
if ($this->smarty->debugging) {
if (!isset($this->smarty->_debug)) {
$this->smarty->_debug = new Smarty_Internal_Debug();
@@ -161,7 +160,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
// checks if template exists
if (!$this->source->exists) {
throw new SmartyException("Unable to load template '{$this->source->type}:{$this->source->name}'" .
($parentIsTpl ? " in '{$this->parent->template_resource}'" : ''));
($this->_isSubTpl() ? " in '{$this->parent->template_resource}'" : ''));
}
// disable caching for evaluated code
if ($this->source->handler->recompiled) {
@@ -212,7 +211,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
$this->smarty->_debug->display_debug($this, true);
}
}
if ($parentIsTpl) {
if ($this->_isSubTpl()) {
foreach ($this->compiled->required_plugins as $code => $tmp1) {
foreach ($tmp1 as $name => $tmp) {
foreach ($tmp as $type => $data) {
@@ -309,7 +308,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
// check if template object should be cached
if ($forceTplCache || (isset($smarty->_cache[ 'subTplInfo' ][ $tpl->template_resource ]) &&
$smarty->_cache[ 'subTplInfo' ][ $tpl->template_resource ] > 1) ||
($tpl->_isParentTemplate() && isset($smarty->_cache[ 'tplObjects' ][ $tpl->parent->templateId ]))
($tpl->_isSubTpl() && isset($smarty->_cache[ 'tplObjects' ][ $tpl->parent->templateId ]))
) {
$smarty->_cache[ 'tplObjects' ][ $tpl->templateId ] = $tpl;
}
@@ -368,13 +367,13 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
}
/**
* Check if parent is template object
* Check if this is a sub template
*
* @return bool true if parent is template
* @return bool true is sub template
*/
public function _isParentTemplate()
public function _isSubTpl()
{
return isset($this->parent) && $this->parent->_objType == 2;
return isset($this->parent) && $this->parent->_isTplObj();
}
/**

View File

@@ -14,7 +14,7 @@
* @package Smarty
* @subpackage Template
*
* @property Smarty $smarty
* @property int $_objType
*
* The following methods will be dynamically loaded by the extension handler when they are called.
* They are located in a corresponding Smarty_Internal_Method_xxxx class
@@ -42,6 +42,7 @@
* @method Smarty_Internal_TemplateBase unregisterPlugin(string $type, string $name)
* @method Smarty_Internal_TemplateBase unregisterFilter(string $type, mixed $callback)
* @method Smarty_Internal_TemplateBase unregisterResource(string $name)
* @method Smarty _getSmartyObj()
*/
abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
{
@@ -147,16 +148,16 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
*/
private function _execute($template, $cache_id, $compile_id, $parent, $function)
{
$smarty = $this->_objType == 1 ? $this : $this->smarty;
$smarty = $this->_getSmartyObj();
$saveVars = true;
if ($template === null) {
if ($this->_objType != 2) {
if (!$this->_isTplObj()) {
throw new SmartyException($function . '():Missing \'$template\' parameter');
} else {
$template = $this;
}
} elseif (is_object($template)) {
if (!isset($template->_objType) || $template->_objType != 2) {
if (!isset($template->_objType) || !$template->_isTplObj()) {
throw new SmartyException($function . '():Template object expected');
}
} else {

View File

@@ -209,13 +209,13 @@ abstract class Smarty_Resource
*/
public static function getUniqueTemplateName($obj, $template_resource)
{
$smarty = $obj->_objType == 2 ? $obj->smarty : $obj;
$smarty = $obj->_getSmartyObj();
list($name, $type) = self::parseResourceName($template_resource, $smarty->default_resource_type);
// TODO: optimize for Smarty's internal resource types
$resource = Smarty_Resource::load($smarty, $type);
// go relative to a given template?
$_file_is_dotted = $name[ 0 ] == '.' && ($name[ 1 ] == '.' || $name[ 1 ] == '/');
if ($obj->_objType == 2 && $_file_is_dotted &&
if ($obj->_isTplObj() && $_file_is_dotted &&
($obj->source->type == 'file' || $obj->parent->source->type == 'extends')
) {
$name = $smarty->_realpath(dirname($obj->parent->source->filepath) . $smarty->ds . $name);