- 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
@@ -152,6 +152,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
$_tpl->variable_filters = $compiler->template->variable_filters;
$_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash'];
$_tpl->source->filepath = $compiler->template->block_data[$_name]['file'];
$_tpl->allow_relative_path = true;
if ($compiler->nocache) {
$_tpl->compiler->forceNocache = 2;
} else {
+5 -13
View File
@@ -41,19 +41,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
* @var integer
*/
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
* @var string
@@ -101,6 +88,11 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
* @var 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
@@ -653,6 +653,16 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
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
*
@@ -661,13 +671,10 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
*/
public function __call($name, $args)
{
static $camel_func;
// methode of Smarty object?
if (method_exists($this->smarty, $name)) {
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
$first3 = strtolower(substr($name, 0, 3));
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
$property_name = strtolower(substr($name, 3, 1)) . substr($name, 4);
// 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 ($first3 == 'get')
return $this->$property_name;
@@ -692,7 +699,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
}
}
// must be unknown
throw new SmartyException("Call of unknown function '$name'.");
throw new SmartyException("Call of unknown method '$name'.");
}
}
+3 -3
View File
@@ -154,7 +154,7 @@ abstract class Smarty_Resource {
// go relative to a given template?
$_file_is_dotted = $file[0] == '.' && ($file[1] == '.' || $file[1] == '/' || $file[1] == "\\");
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}'");
}
$file = dirname($_template->parent->source->filepath) . DS . $file;
@@ -164,7 +164,7 @@ abstract class Smarty_Resource {
// as expansions (like include_path) have already been done
$file = getcwd() . DS . $file;
}
}
}
// resolve relative path
if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $file)) {
@@ -422,7 +422,7 @@ abstract class Smarty_Resource {
$resource_name = $template_resource;
}
}
$resource = Smarty_Resource::load($smarty, $resource_type);
$source = new Smarty_Template_Source($resource, $smarty, $template_resource, $resource_type, $resource_name);
$resource->populate($source, $_template);