Skip to content

Commit

Permalink
Merge pull request #1487 from mambax7/feature/trigger_error
Browse files Browse the repository at this point in the history
replace trigger_error with \Exception
  • Loading branch information
mambax7 authored Dec 2, 2024
2 parents 8b3b37b + 3a212d4 commit 489e562
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion htdocs/Frameworks/art/functions.ini.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

if (substr(XOOPS_VERSION, 0, 9) < 'XOOPS 2.3') {
trigger_error('The package only works for XOOPS 2.3+', E_USER_ERROR);
throw new \Exception('The package only works for XOOPS 2.3+');
}

if (!defined('FRAMEWORKS_ART_FUNCTIONS_INI')):
Expand Down
2 changes: 1 addition & 1 deletion htdocs/class/database/databasefactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static function getDatabaseConnection()
$instance->setLogger(XoopsLogger::getInstance());
$instance->setPrefix(XOOPS_DB_PREFIX);
if (!$instance->connect()) {
trigger_error('notrace:Unable to connect to database', E_USER_ERROR);
throw new \Exception('notrace:Unable to connect to database');
}
} else {
trigger_error('notrace:Failed to load database of type: ' . XOOPS_DB_TYPE . ' in file: ' . __FILE__ . ' at line ' . __LINE__, E_USER_WARNING);
Expand Down
2 changes: 1 addition & 1 deletion htdocs/class/database/mysqldatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ abstract class XoopsMySQLDatabase extends XoopsDatabase
public function connect($selectdb = true)
{
if (!extension_loaded('mysqli')) {
trigger_error('notrace:mysqli extension not loaded', E_USER_ERROR);
throw new \Exception('notrace:mysqli extension not loaded');

return false;
}
Expand Down
3 changes: 2 additions & 1 deletion htdocs/class/textsanitizer/censor/censor.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public function load($myts, $text)
continue;
}
if (!empty($censorConf['censor_terminate'])) {
trigger_error('Censor words found', E_USER_ERROR);
throw new \Exception('Censor words found');
// The below lines are now redundant and won't be executed.
$text = '';

return $text;
Expand Down
9 changes: 7 additions & 2 deletions htdocs/include/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function xoops_getModuleHandler($name = null, $module_dir = null, $optional = fa
if (isset($GLOBALS['xoopsModule']) && is_object($GLOBALS['xoopsModule'])) {
$module_dir = $GLOBALS['xoopsModule']->getVar('dirname', 'n');
} else {
trigger_error('No Module is loaded', E_USER_ERROR);
throw new \Exception('No Module is loaded');
}
} else {
$module_dir = trim($module_dir);
Expand All @@ -87,8 +87,13 @@ function xoops_getModuleHandler($name = null, $module_dir = null, $optional = fa
}
}
if (!isset($handlers[$module_dir][$name])) {
trigger_error('Handler does not exist<br>Module: ' . $module_dir . '<br>Name: ' . $name, $optional ? E_USER_WARNING : E_USER_ERROR);
$message = 'Handler does not exist<br>Module: ' . $module_dir . '<br>Name: ' . $name;
if ($optional) {
trigger_error($message, E_USER_WARNING);
} else {
throw new \Exception($message);
}
}
if (isset($handlers[$module_dir][$name])) {
return $handlers[$module_dir][$name];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ public function &get($name, $ignore_error = false)
public function destroy($name)
{
if (!array_key_exists($name, $this->_storage)) {
trigger_error(
"Attempted to destroy non-existent variable $name",
E_USER_ERROR
);
throw new \Exception("Attempted to destroy non-existent variable $name");
return;
}
unset($this->_storage[$name]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ public static function convertFromUTF8($str, $config, $context)
$str = mb_convert_encoding($str, 'ISO-8859-1', 'UTF-8');
return $str;
}
trigger_error('Encoding not supported', E_USER_ERROR);
throw new \Exception('Encoding not supported');
// You might be tempted to assume that the ASCII representation
// might be OK, however, this is *not* universally true over all
// encodings. So we take the conservative route here, rather
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ public function doValidate(&$uri, $config, $context)
}
$image_code = $info[2];
} else {
trigger_error("could not find exif_imagetype or getimagesize functions", E_USER_ERROR);
}
throw new \Exception("could not find exif_imagetype or getimagesize functions");}
$real_content_type = image_type_to_mime_type($image_code);
if ($real_content_type != $content_type) {
// we're nice guys; if the content type is something else we
Expand Down

0 comments on commit 489e562

Please sign in to comment.