Pass PEAR errors to rcube::raise_error(), small CS improvements

pull/6043/merge
Aleksander Machniak 8 years ago
parent 12b1b54792
commit 3d0b2cd3ce

@ -329,7 +329,6 @@ class rcube_sieve
public function get_scripts()
{
if (!$this->list) {
if (!$this->sieve) {
return $this->_set_error(self::ERROR_INTERNAL);
}

@ -177,10 +177,7 @@ class rcube_sieve_engine
}
if (empty($port)) {
$port = getservbyname('sieve', 'tcp');
if (empty($port)) {
$port = self::PORT;
}
$port = getservbyname('sieve', 'tcp') ?: self::PORT;
}
$plugin = $this->rc->plugins->exec_hook('managesieve_connect', array(

@ -98,7 +98,7 @@ if (!preg_match($regexp, $path)) {
spl_autoload_register('rcube_autoload');
// set PEAR error handling (will also load the PEAR main class)
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'rcube_pear_error');
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, function($err) { rcube::raise_error($err, true); });
/**
@ -170,7 +170,7 @@ function parse_bytes($str)
*/
function slashify($str)
{
return unslashify($str).'/';
return unslashify($str) . '/';
}
/**
@ -178,7 +178,7 @@ function slashify($str)
*/
function unslashify($str)
{
return preg_replace('/\/+$/', '', $str);
return rtrim($str, '/');
}
/**
@ -454,17 +454,3 @@ function rcube_autoload($classname)
return false;
}
/**
* Local callback function for PEAR errors
*/
function rcube_pear_error($err)
{
$msg = sprintf("ERROR: %s (%s)", $err->getMessage(), $err->getCode());
if ($info = $err->getUserinfo()) {
$msg .= ': ' . $info;
}
error_log($msg, 0);
}

@ -1303,8 +1303,7 @@ class rcube
*/
public static function raise_error($arg = array(), $log = false, $terminate = false)
{
// handle PHP exceptions
if (is_object($arg) && is_a($arg, 'Exception')) {
if ($arg instanceof Exception) {
$arg = array(
'code' => $arg->getCode(),
'line' => $arg->getLine(),
@ -1312,6 +1311,13 @@ class rcube
'message' => $arg->getMessage(),
);
}
else if ($arg instanceof PEAR_Error) {
$info = $arg->getUserInfo();
$arg = array(
'code' => $arg->getCode(),
'message' => $arg->getMessage() . ($info ? ': ' . $info : ''),
);
}
else if (is_string($arg)) {
$arg = array('message' => $arg);
}

@ -83,6 +83,7 @@ class Framework_Bootstrap extends PHPUnit_Framework_TestCase
"\\/" => "\\",
'test/test' => 'test/test',
'test//' => 'test',
'/test//' => '/test',
);
foreach ($data as $value => $expected) {

Loading…
Cancel
Save