- bugfix use catch Exception instead UnexpectedValueException in

clearCompiledTemplate to be PHP 5.2 compatible

- fixed PHPunit ClearCompiledTests to run also under Windows
This commit is contained in:
uwe.tews@googlemail.com
2011-10-22 16:47:35 +00:00
parent 1edb2220c7
commit 20a14579ce
2 changed files with 27 additions and 22 deletions

View File

@@ -1,6 +1,10 @@
===== trunk ===== ===== trunk =====
22.10.2011 22.10.2011
- bugfix smarty_mb_from_unicode() would not decode unicode-points properly - bugfix use catch Exception instead UnexpectedValueException in
clearCompiledTemplate to be PHP 5.2 compatible
- bugfix use catch Exception instead UnexpectedValueException in
clearCompiledTemplate to be PHP 5.2 compatible
21.10.2011 21.10.2011
- bugfix apostrophe in plugins_dir path name failed (forum topic 20199) - bugfix apostrophe in plugins_dir path name failed (forum topic 20199)

View File

@@ -189,7 +189,7 @@ class Smarty_Internal_Utility {
$smarty->caching = false; $smarty->caching = false;
$tpl = new $smarty->template_class($resource_name, $smarty); $tpl = new $smarty->template_class($resource_name, $smarty);
$smarty->caching = $_save_stat; $smarty->caching = $_save_stat;
// remove from template cache // remove from template cache
$tpl->source; // have the template registered before unset() $tpl->source; // have the template registered before unset()
if ($smarty->allow_ambiguous_resources) { if ($smarty->allow_ambiguous_resources) {
@@ -201,14 +201,14 @@ class Smarty_Internal_Utility {
$_templateId = sha1($_templateId); $_templateId = sha1($_templateId);
} }
unset($smarty->template_objects[$_templateId]); unset($smarty->template_objects[$_templateId]);
if ($tpl->source->exists) { if ($tpl->source->exists) {
$_resource_part_1 = basename(str_replace('^', '/', $tpl->compiled->filepath)); $_resource_part_1 = basename(str_replace('^', '/', $tpl->compiled->filepath));
$_resource_part_1_length = strlen($_resource_part_1); $_resource_part_1_length = strlen($_resource_part_1);
} else { } else {
return 0; return 0;
} }
$_resource_part_2 = str_replace('.php','.cache.php',$_resource_part_1); $_resource_part_2 = str_replace('.php','.cache.php',$_resource_part_1);
$_resource_part_2_length = strlen($_resource_part_2); $_resource_part_2_length = strlen($_resource_part_2);
} else { } else {
@@ -225,16 +225,17 @@ class Smarty_Internal_Utility {
$_count = 0; $_count = 0;
try { try {
$_compileDirs = new RecursiveDirectoryIterator($_dir); $_compileDirs = new RecursiveDirectoryIterator($_dir);
} catch (UnexpectedValueException $e) { // NOTE: UnexpectedValueException thrown for PHP >= 5.3
} catch (Exception $e) {
return 0; return 0;
} }
$_compile = new RecursiveIteratorIterator($_compileDirs, RecursiveIteratorIterator::CHILD_FIRST); $_compile = new RecursiveIteratorIterator($_compileDirs, RecursiveIteratorIterator::CHILD_FIRST);
foreach ($_compile as $_file) { foreach ($_compile as $_file) {
if (substr($_file->getBasename(), 0, 1) == '.' || strpos($_file, '.svn') !== false) if (substr($_file->getBasename(), 0, 1) == '.' || strpos($_file, '.svn') !== false)
continue; continue;
$_filepath = (string) $_file; $_filepath = (string) $_file;
if ($_file->isDir()) { if ($_file->isDir()) {
if (!$_compile->isDot()) { if (!$_compile->isDot()) {
// delete folder if empty // delete folder if empty
@@ -243,10 +244,10 @@ class Smarty_Internal_Utility {
} else { } else {
$unlink = false; $unlink = false;
if ((!isset($_compile_id) || (isset($_filepath[$_compile_id_part_length]) && !strncmp($_filepath, $_compile_id_part, $_compile_id_part_length))) if ((!isset($_compile_id) || (isset($_filepath[$_compile_id_part_length]) && !strncmp($_filepath, $_compile_id_part, $_compile_id_part_length)))
&& (!isset($resource_name) && (!isset($resource_name)
|| (isset($_filepath[$_resource_part_1_length]) || (isset($_filepath[$_resource_part_1_length])
&& substr_compare($_filepath, $_resource_part_1, -$_resource_part_1_length, $_resource_part_1_length) == 0) && substr_compare($_filepath, $_resource_part_1, -$_resource_part_1_length, $_resource_part_1_length) == 0)
|| (isset($_filepath[$_resource_part_2_length]) || (isset($_filepath[$_resource_part_2_length])
&& substr_compare($_filepath, $_resource_part_2, -$_resource_part_2_length, $_resource_part_2_length) == 0))) { && substr_compare($_filepath, $_resource_part_2, -$_resource_part_2_length, $_resource_part_2_length) == 0))) {
if (isset($exp_time)) { if (isset($exp_time)) {
if (time() - @filemtime($_filepath) >= $exp_time) { if (time() - @filemtime($_filepath) >= $exp_time) {
@@ -256,7 +257,7 @@ class Smarty_Internal_Utility {
$unlink = true; $unlink = true;
} }
} }
if ($unlink && @unlink($_filepath)) { if ($unlink && @unlink($_filepath)) {
$_count++; $_count++;
} }
@@ -313,7 +314,7 @@ class Smarty_Internal_Utility {
if ($errors === null) { if ($errors === null) {
echo "$template_dir is OK.\n"; echo "$template_dir is OK.\n";
} }
continue; continue;
} else { } else {
$status = false; $status = false;
@@ -334,11 +335,11 @@ class Smarty_Internal_Utility {
} else { } else {
$errors['template_dir'] = $message; $errors['template_dir'] = $message;
} }
continue; continue;
} }
} }
if (!is_dir($template_dir)) { if (!is_dir($template_dir)) {
$status = false; $status = false;
$message = "FAILED: $template_dir is not a directory"; $message = "FAILED: $template_dir is not a directory";
@@ -428,7 +429,7 @@ class Smarty_Internal_Utility {
if ($errors === null) { if ($errors === null) {
echo "$plugin_dir is OK.\n"; echo "$plugin_dir is OK.\n";
} }
continue; continue;
} else { } else {
$status = false; $status = false;
@@ -449,11 +450,11 @@ class Smarty_Internal_Utility {
} else { } else {
$errors['plugins_dir'] = $message; $errors['plugins_dir'] = $message;
} }
continue; continue;
} }
} }
if (!is_dir($plugin_dir)) { if (!is_dir($plugin_dir)) {
$status = false; $status = false;
$message = "FAILED: $plugin_dir is not a directory"; $message = "FAILED: $plugin_dir is not a directory";
@@ -495,7 +496,7 @@ class Smarty_Internal_Utility {
echo "Testing cache directory...\n"; echo "Testing cache directory...\n";
} }
// test if all registered cache_dir is accessible // test if all registered cache_dir is accessible
$__cache_dir = $smarty->getCacheDir(); $__cache_dir = $smarty->getCacheDir();
$_cache_dir = realpath($__cache_dir); $_cache_dir = realpath($__cache_dir);
@@ -554,7 +555,7 @@ class Smarty_Internal_Utility {
if ($errors === null) { if ($errors === null) {
echo "$config_dir is OK.\n"; echo "$config_dir is OK.\n";
} }
continue; continue;
} else { } else {
$status = false; $status = false;
@@ -575,11 +576,11 @@ class Smarty_Internal_Utility {
} else { } else {
$errors['config_dir'] = $message; $errors['config_dir'] = $message;
} }
continue; continue;
} }
} }
if (!is_dir($config_dir)) { if (!is_dir($config_dir)) {
$status = false; $status = false;
$message = "FAILED: $config_dir is not a directory"; $message = "FAILED: $config_dir is not a directory";