- remove unused properties

- optimization use real function instead anonymous function for preg_replace_callback
- bugfix a relative {include} in child template blocks failed
- bugfix direct setting of $template_dir, $config_dir, $plugins_dir in __construct() of an 
  extended Smarty class created problems
This commit is contained in:
uwe.tews@googlemail.com
2011-09-23 20:21:16 +00:00
parent 1d9f527c1e
commit 50a8f805dd
6 changed files with 45 additions and 38 deletions

View File

@@ -1,4 +1,11 @@
===== trunk ===== ===== trunk =====
23.09.2011
- remove unused properties
- optimization use real function instead anonymous function for preg_replace_callback
- bugfix a relative {include} in child template blocks failed
- bugfix direct setting of $template_dir, $config_dir, $plugins_dir in __construct() of an
extended Smarty class created problems
===== Smarty 3.1.1 ===== ===== Smarty 3.1.1 =====
22.09.2011 22.09.2011
- bugfix {foreachelse} does fail if {section} was nested inside {foreach} - bugfix {foreachelse} does fail if {section} was nested inside {foreach}

View File

@@ -821,7 +821,7 @@ class Smarty extends Smarty_Internal_TemplateBase {
return isset($this->template_dir[$index]) ? $this->template_dir[$index] : null; return isset($this->template_dir[$index]) ? $this->template_dir[$index] : null;
} }
return $this->template_dir; return (array)$this->template_dir;
} }
/** /**
@@ -885,7 +885,7 @@ class Smarty extends Smarty_Internal_TemplateBase {
return isset($this->config_dir[$index]) ? $this->config_dir[$index] : null; return isset($this->config_dir[$index]) ? $this->config_dir[$index] : null;
} }
return $this->config_dir; return (array)$this->config_dir;
} }
/** /**
@@ -942,7 +942,7 @@ class Smarty extends Smarty_Internal_TemplateBase {
*/ */
public function getPluginsDir() public function getPluginsDir()
{ {
return $this->plugins_dir; return (array)$this->plugins_dir;
} }
/** /**

View File

@@ -152,6 +152,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
$_tpl->variable_filters = $compiler->template->variable_filters; $_tpl->variable_filters = $compiler->template->variable_filters;
$_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash']; $_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash'];
$_tpl->source->filepath = $compiler->template->block_data[$_name]['file']; $_tpl->source->filepath = $compiler->template->block_data[$_name]['file'];
$_tpl->allow_relative_path = true;
if ($compiler->nocache) { if ($compiler->nocache) {
$_tpl->compiler->forceNocache = 2; $_tpl->compiler->forceNocache = 2;
} else { } else {

View File

@@ -41,19 +41,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
* @var integer * @var integer
*/ */
public $cache_lifetime = null; public $cache_lifetime = null;
/**
* Class name
* @var string
*/
public $cacher_class = null;
/**
* caching type
*
* Must be an element of $cache_resource_types.
*
* @var string
*/
public $caching_type = null;
/** /**
* Template resource * Template resource
* @var string * @var string
@@ -101,6 +88,11 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
* @var array * @var array
*/ */
public $used_tags = array(); public $used_tags = array();
/**
* internal flag to allow relative path in child template blocks
* @var bool
*/
public $allow_relative_path = false;
/** /**
* Create template data object * Create template data object

View File

@@ -653,6 +653,16 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
return false; return false;
} }
/**
* preg_replace callback to convert camelcase getter/setter to underscore property names
*
* @param string $match match string
* @return string replacemant
*/
private function replaceCamelcase($match) {
return "_" . strtolower($match[1]);
}
/** /**
* Handle unknown class methods * Handle unknown class methods
* *
@@ -661,13 +671,10 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
*/ */
public function __call($name, $args) public function __call($name, $args)
{ {
static $camel_func;
// methode of Smarty object? // methode of Smarty object?
if (method_exists($this->smarty, $name)) { if (method_exists($this->smarty, $name)) {
return call_user_func_array(array($this->smarty, $name), $args); return call_user_func_array(array($this->smarty, $name), $args);
} }
if (!isset($camel_func))
$camel_func = create_function('$c', 'return "_" . strtolower($c[1]);');
// see if this is a set/get for a property // see if this is a set/get for a property
$first3 = strtolower(substr($name, 0, 3)); $first3 = strtolower(substr($name, 0, 3));
if (in_array($first3, array('set', 'get')) && substr($name, 3, 1) !== '_') { if (in_array($first3, array('set', 'get')) && substr($name, 3, 1) !== '_') {
@@ -675,7 +682,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
// lcfirst() not available < PHP 5.3.0, so improvise // lcfirst() not available < PHP 5.3.0, so improvise
$property_name = strtolower(substr($name, 3, 1)) . substr($name, 4); $property_name = strtolower(substr($name, 3, 1)) . substr($name, 4);
// convert camel case to underscored name // convert camel case to underscored name
$property_name = preg_replace_callback('/([A-Z])/', $camel_func, $property_name); $property_name = preg_replace_callback('/([A-Z])/', array($this,'replaceCamelcase'), $property_name);
if (property_exists($this, $property_name)) { if (property_exists($this, $property_name)) {
if ($first3 == 'get') if ($first3 == 'get')
return $this->$property_name; return $this->$property_name;
@@ -692,7 +699,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
} }
} }
// must be unknown // must be unknown
throw new SmartyException("Call of unknown function '$name'."); throw new SmartyException("Call of unknown method '$name'.");
} }
} }

View File

@@ -154,7 +154,7 @@ abstract class Smarty_Resource {
// go relative to a given template? // go relative to a given template?
$_file_is_dotted = $file[0] == '.' && ($file[1] == '.' || $file[1] == '/' || $file[1] == "\\"); $_file_is_dotted = $file[0] == '.' && ($file[1] == '.' || $file[1] == '/' || $file[1] == "\\");
if ($_template && $_template->parent instanceof Smarty_Internal_Template && $_file_is_dotted) { if ($_template && $_template->parent instanceof Smarty_Internal_Template && $_file_is_dotted) {
if ($_template->parent->source->type != 'file' && $_template->parent->source->type != 'extends') { if ($_template->parent->source->type != 'file' && $_template->parent->source->type != 'extends' && !$_template->parent->allow_relative_path) {
throw new SmartyException("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'"); throw new SmartyException("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'");
} }
$file = dirname($_template->parent->source->filepath) . DS . $file; $file = dirname($_template->parent->source->filepath) . DS . $file;