mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-06 03:14:27 +02:00
- 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 error muting is now a global thing. this was done because of the overhead set_error_handler imposes and the fact, that only a few people really "need" this. The decision was made by uwe.tews and rodneyrehm. (just in case anyone asks…)
This commit is contained in:
@@ -1,4 +1,8 @@
|
|||||||
===== trunk =====
|
===== 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
|
23.09.2011
|
||||||
- remove unused properties
|
- remove unused properties
|
||||||
- optimization use real function instead anonymous function for preg_replace_callback
|
- 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 {foreachelse} does fail if {section} was nested inside {foreach}
|
||||||
- bugfix debug.tpl did not display correctly when it was compiled with escape_html = true
|
- bugfix debug.tpl did not display correctly when it was compiled with escape_html = true
|
||||||
|
|
||||||
|
|
||||||
21.09.2011
|
21.09.2011
|
||||||
- bugfix look for mixed case plugin file names as in 3.0 if not found try all lowercase
|
- 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
|
- added $error_muting to suppress error messages even for badly implemented error_handlers
|
||||||
|
@@ -157,11 +157,11 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
|||||||
* assigned global tpl vars
|
* assigned global tpl vars
|
||||||
*/
|
*/
|
||||||
public static $global_tpl_vars = array();
|
public static $global_tpl_vars = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable error_handler suppression to outsmart badly implemented external error_handlers
|
* error handler returned by set_error_hanlder() in Smarty::muteExpctedErrors()
|
||||||
* @var boolean
|
|
||||||
*/
|
*/
|
||||||
public static $error_muting = true;
|
public static $_previous_error_handler = null;
|
||||||
|
|
||||||
/**#@+
|
/**#@+
|
||||||
* variables
|
* variables
|
||||||
@@ -689,13 +689,10 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
|||||||
*/
|
*/
|
||||||
function clearAllCache($exp_time = null, $type = null)
|
function clearAllCache($exp_time = null, $type = null)
|
||||||
{
|
{
|
||||||
Smarty::muteExpectedErrors();
|
|
||||||
// load cache resource and call clearAll
|
// load cache resource and call clearAll
|
||||||
$_cache_resource = Smarty_CacheResource::load($this, $type);
|
$_cache_resource = Smarty_CacheResource::load($this, $type);
|
||||||
Smarty_CacheResource::invalidLoadedCache($this);
|
Smarty_CacheResource::invalidLoadedCache($this);
|
||||||
$t = $_cache_resource->clearAll($this, $exp_time);
|
return $_cache_resource->clearAll($this, $exp_time);
|
||||||
Smarty::unmuteExpectedErrors();
|
|
||||||
return $t;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -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)
|
public function clearCache($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null)
|
||||||
{
|
{
|
||||||
Smarty::muteExpectedErrors();
|
|
||||||
// load cache resource and call clear
|
// load cache resource and call clear
|
||||||
$_cache_resource = Smarty_CacheResource::load($this, $type);
|
$_cache_resource = Smarty_CacheResource::load($this, $type);
|
||||||
Smarty_CacheResource::invalidLoadedCache($this);
|
Smarty_CacheResource::invalidLoadedCache($this);
|
||||||
$t = $_cache_resource->clear($this, $template_name, $cache_id, $compile_id, $exp_time);
|
return $_cache_resource->clear($this, $template_name, $cache_id, $compile_id, $exp_time);
|
||||||
Smarty::unmuteExpectedErrors();
|
|
||||||
return $t;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1301,10 +1295,25 @@ class Smarty extends Smarty_Internal_TemplateBase {
|
|||||||
* @param integer $errno Error level
|
* @param integer $errno Error level
|
||||||
* @return boolean
|
* @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
|
static $directory = null;
|
||||||
return (bool)($errno && $errno & error_reporting());
|
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,
|
- between file_exists() and filemtime() a possible race condition is opened,
|
||||||
which does not exist using the simple @filemtime() approach.
|
which does not exist using the simple @filemtime() approach.
|
||||||
*/
|
*/
|
||||||
if (self::$error_muting) {
|
$error_handler = array('Smarty', 'mutingErrorHandler');
|
||||||
set_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()
|
public static function unmuteExpectedErrors()
|
||||||
{
|
{
|
||||||
if (self::$error_muting) {
|
restore_error_handler();
|
||||||
restore_error_handler();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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->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';
|
$cached->filepath = $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($_source_file_path) . '.php';
|
||||||
Smarty::muteExpectedErrors();
|
|
||||||
$cached->timestamp = @filemtime($cached->filepath);
|
$cached->timestamp = @filemtime($cached->filepath);
|
||||||
Smarty::unmuteExpectedErrors();
|
|
||||||
$cached->exists = !!$cached->timestamp;
|
$cached->exists = !!$cached->timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,9 +73,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource {
|
|||||||
*/
|
*/
|
||||||
public function populateTimestamp(Smarty_Template_Cached $cached)
|
public function populateTimestamp(Smarty_Template_Cached $cached)
|
||||||
{
|
{
|
||||||
Smarty::muteExpectedErrors();
|
|
||||||
$cached->timestamp = @filemtime($cached->filepath);
|
$cached->timestamp = @filemtime($cached->filepath);
|
||||||
Smarty::unmuteExpectedErrors();
|
|
||||||
$cached->exists = !!$cached->timestamp;
|
$cached->exists = !!$cached->timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,9 +223,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource {
|
|||||||
} else {
|
} else {
|
||||||
clearstatcache();
|
clearstatcache();
|
||||||
}
|
}
|
||||||
Smarty::muteExpectedErrors();
|
|
||||||
$t = @filemtime($cached->lock_id);
|
$t = @filemtime($cached->lock_id);
|
||||||
Smarty::unmuteExpectedErrors();
|
|
||||||
return $t && (time() - $t < $smarty->locking_timeout);
|
return $t && (time() - $t < $smarty->locking_timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -26,7 +26,6 @@ class Smarty_Internal_Resource_File extends Smarty_Resource {
|
|||||||
*/
|
*/
|
||||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null)
|
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null)
|
||||||
{
|
{
|
||||||
Smarty::muteExpectedErrors();
|
|
||||||
$source->filepath = $this->buildFilepath($source, $_template);
|
$source->filepath = $this->buildFilepath($source, $_template);
|
||||||
|
|
||||||
if ($source->filepath !== false) {
|
if ($source->filepath !== false) {
|
||||||
@@ -40,7 +39,6 @@ class Smarty_Internal_Resource_File extends Smarty_Resource {
|
|||||||
$source->exists = !!$source->timestamp;
|
$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)
|
public function populateTimestamp(Smarty_Template_Source $source)
|
||||||
{
|
{
|
||||||
Smarty::muteExpectedErrors();
|
|
||||||
$source->timestamp = @filemtime($source->filepath);
|
$source->timestamp = @filemtime($source->filepath);
|
||||||
Smarty::unmuteExpectedErrors();
|
|
||||||
$source->exists = !!$source->timestamp;
|
$source->exists = !!$source->timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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)
|
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null)
|
||||||
{
|
{
|
||||||
Smarty::muteExpectedErrors();
|
|
||||||
$source->filepath = $this->buildFilepath($source, $_template);
|
$source->filepath = $this->buildFilepath($source, $_template);
|
||||||
|
|
||||||
if ($source->filepath !== false) {
|
if ($source->filepath !== false) {
|
||||||
@@ -49,7 +48,6 @@ class Smarty_Internal_Resource_PHP extends Smarty_Resource_Uncompiled {
|
|||||||
$source->exists = !!$source->timestamp;
|
$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)
|
public function populateTimestamp(Smarty_Template_Source $source)
|
||||||
{
|
{
|
||||||
Smarty::muteExpectedErrors();
|
|
||||||
$source->timestamp = @filemtime($source->filepath);
|
$source->timestamp = @filemtime($source->filepath);
|
||||||
Smarty::unmuteExpectedErrors();
|
|
||||||
$source->exists = !!$source->timestamp;
|
$source->exists = !!$source->timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -25,7 +25,6 @@ class Smarty_Internal_Write_File {
|
|||||||
*/
|
*/
|
||||||
public static function writeFile($_filepath, $_contents, Smarty $smarty)
|
public static function writeFile($_filepath, $_contents, Smarty $smarty)
|
||||||
{
|
{
|
||||||
Smarty::muteExpectedErrors();
|
|
||||||
$_error_reporting = error_reporting();
|
$_error_reporting = error_reporting();
|
||||||
error_reporting($_error_reporting & ~E_NOTICE & ~E_WARNING);
|
error_reporting($_error_reporting & ~E_NOTICE & ~E_WARNING);
|
||||||
if ($smarty->_file_perms !== null) {
|
if ($smarty->_file_perms !== null) {
|
||||||
@@ -42,7 +41,6 @@ class Smarty_Internal_Write_File {
|
|||||||
$_tmp_file = $_dirpath . DS . uniqid('wrt');
|
$_tmp_file = $_dirpath . DS . uniqid('wrt');
|
||||||
if (!file_put_contents($_tmp_file, $_contents)) {
|
if (!file_put_contents($_tmp_file, $_contents)) {
|
||||||
error_reporting($_error_reporting);
|
error_reporting($_error_reporting);
|
||||||
Smarty::unmuteExpectedErrors();
|
|
||||||
throw new SmartyException("unable to write file {$_tmp_file}");
|
throw new SmartyException("unable to write file {$_tmp_file}");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -54,7 +52,6 @@ class Smarty_Internal_Write_File {
|
|||||||
$success = rename($_tmp_file, $_filepath);
|
$success = rename($_tmp_file, $_filepath);
|
||||||
if (!$success) {
|
if (!$success) {
|
||||||
error_reporting($_error_reporting);
|
error_reporting($_error_reporting);
|
||||||
Smarty::unmuteExpectedErrors();
|
|
||||||
throw new SmartyException("unable to write file {$_filepath}");
|
throw new SmartyException("unable to write file {$_filepath}");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -65,7 +62,6 @@ class Smarty_Internal_Write_File {
|
|||||||
umask($old_umask);
|
umask($old_umask);
|
||||||
}
|
}
|
||||||
error_reporting($_error_reporting);
|
error_reporting($_error_reporting);
|
||||||
Smarty::unmuteExpectedErrors();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -609,9 +609,7 @@ class Smarty_Template_Source {
|
|||||||
|
|
||||||
$compiled = new Smarty_Template_Compiled($this);
|
$compiled = new Smarty_Template_Compiled($this);
|
||||||
$this->handler->populateCompiledFilepath($compiled, $_template);
|
$this->handler->populateCompiledFilepath($compiled, $_template);
|
||||||
Smarty::muteExpectedErrors();
|
|
||||||
$compiled->timestamp = @filemtime($compiled->filepath);
|
$compiled->timestamp = @filemtime($compiled->filepath);
|
||||||
Smarty::unmuteExpectedErrors();
|
|
||||||
$compiled->exists = !!$compiled->timestamp;
|
$compiled->exists = !!$compiled->timestamp;
|
||||||
|
|
||||||
// runtime cache
|
// runtime cache
|
||||||
|
Reference in New Issue
Block a user