summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--change_log.txt5
-rw-r--r--libs/Smarty.class.php49
-rw-r--r--libs/sysplugins/smarty_internal_cacheresource_file.php6
-rw-r--r--libs/sysplugins/smarty_internal_resource_file.php4
-rw-r--r--libs/sysplugins/smarty_internal_resource_php.php4
-rw-r--r--libs/sysplugins/smarty_internal_write_file.php4
-rw-r--r--libs/sysplugins/smarty_resource.php2
7 files changed, 34 insertions, 40 deletions
diff --git a/change_log.txt b/change_log.txt
index fe71d9ab..0855fcd6 100644
--- a/change_log.txt
+++ b/change_log.txt
@@ -1,4 +1,8 @@
===== trunk =====
+24.09.2011
+- removed internal muteExpectedErrors() calls in favor of having the implementor call this once from his application
+- optimized muteExpectedErrors() to pass errors to the latest registered error handler, if appliccable
+
23.09.2011
- remove unused properties
- optimization use real function instead anonymous function for preg_replace_callback
@@ -12,7 +16,6 @@
- bugfix {foreachelse} does fail if {section} was nested inside {foreach}
- bugfix debug.tpl did not display correctly when it was compiled with escape_html = true
-
21.09.2011
- bugfix look for mixed case plugin file names as in 3.0 if not found try all lowercase
- added $error_muting to suppress error messages even for badly implemented error_handlers
diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php
index 54a92277..a44e4d71 100644
--- a/libs/Smarty.class.php
+++ b/libs/Smarty.class.php
@@ -157,11 +157,11 @@ class Smarty extends Smarty_Internal_TemplateBase {
* assigned global tpl vars
*/
public static $global_tpl_vars = array();
+
/**
- * Enable error_handler suppression to outsmart badly implemented external error_handlers
- * @var boolean
+ * error handler returned by set_error_hanlder() in Smarty::muteExpctedErrors()
*/
- public static $error_muting = true;
+ public static $_previous_error_handler = null;
/**#@+
* variables
@@ -689,13 +689,10 @@ class Smarty extends Smarty_Internal_TemplateBase {
*/
function clearAllCache($exp_time = null, $type = null)
{
- Smarty::muteExpectedErrors();
// load cache resource and call clearAll
$_cache_resource = Smarty_CacheResource::load($this, $type);
Smarty_CacheResource::invalidLoadedCache($this);
- $t = $_cache_resource->clearAll($this, $exp_time);
- Smarty::unmuteExpectedErrors();
- return $t;
+ return $_cache_resource->clearAll($this, $exp_time);
}
/**
@@ -710,13 +707,10 @@ class Smarty extends Smarty_Internal_TemplateBase {
*/
public function clearCache($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null)
{
- Smarty::muteExpectedErrors();
// load cache resource and call clear
$_cache_resource = Smarty_CacheResource::load($this, $type);
Smarty_CacheResource::invalidLoadedCache($this);
- $t = $_cache_resource->clear($this, $template_name, $cache_id, $compile_id, $exp_time);
- Smarty::unmuteExpectedErrors();
- return $t;
+ return $_cache_resource->clear($this, $template_name, $cache_id, $compile_id, $exp_time);
}
/**
@@ -1301,10 +1295,25 @@ class Smarty extends Smarty_Internal_TemplateBase {
* @param integer $errno Error level
* @return boolean
*/
- public static function mutingErrorHandler($errno)
+ public static function mutingErrorHandler($errno, $errstr, $errfile, $errline, $errcontext)
{
- // return false if $errno is not 0 and included in current error level
- return (bool)($errno && $errno & error_reporting());
+ static $directory = null;
+ static $lenght = null;
+
+ if ($base === null) {
+ $base = realpath(SMARTY_DIR);
+ $length = strlen($base);
+ }
+
+ // pass to next error handler if this error did not occur inside SMARTY_DIR
+ // or the error was within smarty but masked to be ignored
+ if (strncmp($errfile, $base, $length) || ($errno && $errno & error_reporting())) {
+ if (Smarty::$_previous_error_handler) {
+ return call_user_func(Smarty::$_previous_error_handler, $errno, $errstr, $errfile, $errline, $errcontext);
+ } else {
+ return false;
+ }
+ }
}
/**
@@ -1330,8 +1339,12 @@ class Smarty extends Smarty_Internal_TemplateBase {
- between file_exists() and filemtime() a possible race condition is opened,
which does not exist using the simple @filemtime() approach.
*/
- if (self::$error_muting) {
- set_error_handler(array('Smarty', 'mutingErrorHandler'));
+ $error_handler = array('Smarty', 'mutingErrorHandler');
+ $previous = set_error_handler($error_handler);
+
+ // avoid dead loops
+ if ($previous !== $error_handler) {
+ Smarty::$_previous_error_handler = $previous;
}
}
@@ -1342,9 +1355,7 @@ class Smarty extends Smarty_Internal_TemplateBase {
*/
public static function unmuteExpectedErrors()
{
- if (self::$error_muting) {
- restore_error_handler();
- }
+ restore_error_handler();
}
}
diff --git a/libs/sysplugins/smarty_internal_cacheresource_file.php b/libs/sysplugins/smarty_internal_cacheresource_file.php
index 896c7a41..a5cd9f8b 100644
--- a/libs/sysplugins/smarty_internal_cacheresource_file.php
+++ b/libs/sysplugins/smarty_internal_cacheresource_file.php
@@ -61,9 +61,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource {
$cached->lock_id = $_lock_dir.sha1($_cache_id.$_compile_id.$_template->source->uid).'.lock';
}
$cached->filepath = $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($_source_file_path) . '.php';
- Smarty::muteExpectedErrors();
$cached->timestamp = @filemtime($cached->filepath);
- Smarty::unmuteExpectedErrors();
$cached->exists = !!$cached->timestamp;
}
@@ -75,9 +73,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource {
*/
public function populateTimestamp(Smarty_Template_Cached $cached)
{
- Smarty::muteExpectedErrors();
$cached->timestamp = @filemtime($cached->filepath);
- Smarty::unmuteExpectedErrors();
$cached->exists = !!$cached->timestamp;
}
@@ -227,9 +223,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource {
} else {
clearstatcache();
}
- Smarty::muteExpectedErrors();
$t = @filemtime($cached->lock_id);
- Smarty::unmuteExpectedErrors();
return $t && (time() - $t < $smarty->locking_timeout);
}
diff --git a/libs/sysplugins/smarty_internal_resource_file.php b/libs/sysplugins/smarty_internal_resource_file.php
index 66370381..48b391d2 100644
--- a/libs/sysplugins/smarty_internal_resource_file.php
+++ b/libs/sysplugins/smarty_internal_resource_file.php
@@ -26,7 +26,6 @@ class Smarty_Internal_Resource_File extends Smarty_Resource {
*/
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null)
{
- Smarty::muteExpectedErrors();
$source->filepath = $this->buildFilepath($source, $_template);
if ($source->filepath !== false) {
@@ -40,7 +39,6 @@ class Smarty_Internal_Resource_File extends Smarty_Resource {
$source->exists = !!$source->timestamp;
}
}
- Smarty::unmuteExpectedErrors();
}
/**
@@ -50,9 +48,7 @@ class Smarty_Internal_Resource_File extends Smarty_Resource {
*/
public function populateTimestamp(Smarty_Template_Source $source)
{
- Smarty::muteExpectedErrors();
$source->timestamp = @filemtime($source->filepath);
- Smarty::unmuteExpectedErrors();
$source->exists = !!$source->timestamp;
}
diff --git a/libs/sysplugins/smarty_internal_resource_php.php b/libs/sysplugins/smarty_internal_resource_php.php
index 9c79e28d..bfa74d05 100644
--- a/libs/sysplugins/smarty_internal_resource_php.php
+++ b/libs/sysplugins/smarty_internal_resource_php.php
@@ -35,7 +35,6 @@ class Smarty_Internal_Resource_PHP extends Smarty_Resource_Uncompiled {
*/
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null)
{
- Smarty::muteExpectedErrors();
$source->filepath = $this->buildFilepath($source, $_template);
if ($source->filepath !== false) {
@@ -49,7 +48,6 @@ class Smarty_Internal_Resource_PHP extends Smarty_Resource_Uncompiled {
$source->exists = !!$source->timestamp;
}
}
- Smarty::unmuteExpectedErrors();
}
/**
@@ -60,9 +58,7 @@ class Smarty_Internal_Resource_PHP extends Smarty_Resource_Uncompiled {
*/
public function populateTimestamp(Smarty_Template_Source $source)
{
- Smarty::muteExpectedErrors();
$source->timestamp = @filemtime($source->filepath);
- Smarty::unmuteExpectedErrors();
$source->exists = !!$source->timestamp;
}
diff --git a/libs/sysplugins/smarty_internal_write_file.php b/libs/sysplugins/smarty_internal_write_file.php
index 76715e4c..aae600ee 100644
--- a/libs/sysplugins/smarty_internal_write_file.php
+++ b/libs/sysplugins/smarty_internal_write_file.php
@@ -25,7 +25,6 @@ class Smarty_Internal_Write_File {
*/
public static function writeFile($_filepath, $_contents, Smarty $smarty)
{
- Smarty::muteExpectedErrors();
$_error_reporting = error_reporting();
error_reporting($_error_reporting & ~E_NOTICE & ~E_WARNING);
if ($smarty->_file_perms !== null) {
@@ -42,7 +41,6 @@ class Smarty_Internal_Write_File {
$_tmp_file = $_dirpath . DS . uniqid('wrt');
if (!file_put_contents($_tmp_file, $_contents)) {
error_reporting($_error_reporting);
- Smarty::unmuteExpectedErrors();
throw new SmartyException("unable to write file {$_tmp_file}");
return false;
}
@@ -54,7 +52,6 @@ class Smarty_Internal_Write_File {
$success = rename($_tmp_file, $_filepath);
if (!$success) {
error_reporting($_error_reporting);
- Smarty::unmuteExpectedErrors();
throw new SmartyException("unable to write file {$_filepath}");
return false;
}
@@ -65,7 +62,6 @@ class Smarty_Internal_Write_File {
umask($old_umask);
}
error_reporting($_error_reporting);
- Smarty::unmuteExpectedErrors();
return true;
}
diff --git a/libs/sysplugins/smarty_resource.php b/libs/sysplugins/smarty_resource.php
index d0523621..009133cf 100644
--- a/libs/sysplugins/smarty_resource.php
+++ b/libs/sysplugins/smarty_resource.php
@@ -609,9 +609,7 @@ class Smarty_Template_Source {
$compiled = new Smarty_Template_Compiled($this);
$this->handler->populateCompiledFilepath($compiled, $_template);
- Smarty::muteExpectedErrors();
$compiled->timestamp = @filemtime($compiled->filepath);
- Smarty::unmuteExpectedErrors();
$compiled->exists = !!$compiled->timestamp;
// runtime cache