X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FError.php;h=dce8a2e01d6b5dc8803779422505d3d48a6c2b54;hb=077670fbc9f9e7caf11a62b5cb97e690d18e4794;hp=ee1f1037261c5c519b4b591976de8068dc9d5e0e;hpb=e100ac07be991fa09fc460871e4bd39ee45355f0;p=civicrm-core.git diff --git a/CRM/Core/Error.php b/CRM/Core/Error.php index ee1f103726..dce8a2e01d 100644 --- a/CRM/Core/Error.php +++ b/CRM/Core/Error.php @@ -41,13 +41,38 @@ require_once 'PEAR/Exception.php'; require_once 'CRM/Core/Exception.php'; require_once 'Log.php'; + +/** + * Class CRM_Exception + */ class CRM_Exception extends PEAR_Exception { // Redefine the exception so message isn't optional + /** + * Supported signatures: + * - PEAR_Exception(string $message); + * - PEAR_Exception(string $message, int $code); + * - PEAR_Exception(string $message, Exception $cause); + * - PEAR_Exception(string $message, Exception $cause, int $code); + * - PEAR_Exception(string $message, PEAR_Error $cause); + * - PEAR_Exception(string $message, PEAR_Error $cause, int $code); + * - PEAR_Exception(string $message, array $causes); + * - PEAR_Exception(string $message, array $causes, int $code); + * + * @param string exception message + * @param int $code + * @param Exception $previous + * + * @internal param array|\Exception|int|null|\PEAR_Error $exception cause + * @internal param int|null $exception code or null + */ public function __construct($message = NULL, $code = 0, Exception$previous = NULL) { parent::__construct($message, $code, $previous); } } +/** + * Class CRM_Core_Error + */ class CRM_Core_Error extends PEAR_ErrorStack { /** @@ -83,6 +108,12 @@ class CRM_Core_Error extends PEAR_ErrorStack { /** * singleton function used to manage this object. * + * @param null $package + * @param bool $msgCallback + * @param bool $contextCallback + * @param bool $throwPEAR_Error + * @param string $stackClass + * * @return object * @static */ @@ -94,7 +125,7 @@ class CRM_Core_Error extends PEAR_ErrorStack { } /** - * construcor + * constructor */ function __construct() { parent::__construct('CiviCRM'); @@ -106,6 +137,12 @@ class CRM_Core_Error extends PEAR_ErrorStack { $this->setDefaultCallback(array($this, 'handlePES')); } + /** + * @param $error + * @param string $separator + * + * @return array|null|string + */ static public function getMessages(&$error, $separator = '
') { if (is_a($error, 'CRM_Core_Error')) { $errors = $error->getErrors(); @@ -119,7 +156,12 @@ class CRM_Core_Error extends PEAR_ErrorStack { return NULL; } - function displaySessionError(&$error, $separator = '
') { + /** + * Status display function specific to payment processor errors + * @param $error + * @param string $separator + */ + static function displaySessionError(&$error, $separator = '
') { $message = self::getMessages($error, $separator); if ($message) { $status = ts("Payment Processor Error message") . "{$separator} $message"; @@ -215,6 +257,9 @@ class CRM_Core_Error extends PEAR_ErrorStack { // this function is used to trap and print errors // during system initialization time. Hence the error // message is quite ugly + /** + * @param $pearError + */ public static function simpleHandler($pearError) { // create the error array @@ -258,9 +303,14 @@ class CRM_Core_Error extends PEAR_ErrorStack { /** * display an error page with an error message describing what happened * - * @param string message the error message - * @param string code the error code if any - * @param string email the email address to notify of this situation + * @param null $message + * @param null $code + * @param null $email + * + * @throws Exception + * @internal param \message $string the error message + * @internal param \code $string the error code if any + * @internal param \email $string the email address to notify of this situation * * @return void * @static @@ -335,19 +385,7 @@ class CRM_Core_Error extends PEAR_ErrorStack { CRM_Core_Error::debug_var('Fatal Error Details', $vars); CRM_Core_Error::backtrace('backTrace', TRUE); - $content = $template->fetch($config->fatalErrorTemplate); - // JErrorPage exists only in 3.x and not 2.x - // CRM-13714 - if ($config->userFramework == 'Joomla' && class_exists('JErrorPage')) { - $error = new Exception($content); - JErrorPage::render($error); - } - else if ($config->userFramework == 'Joomla' && class_exists('JError')) { - JError::raiseError('CiviCRM-001', $content); - } - else { - echo CRM_Utils_System::theme($content); - } + $config->userSystem->outputError($template->fetch($config->fatalErrorTemplate)); self::abend(CRM_Core_Error::FATAL_ERROR); } @@ -478,10 +516,15 @@ class CRM_Core_Error extends PEAR_ErrorStack { * Similar to the function debug. Only difference is * in the formatting of the output. * - * @param string variable name - * @param mixed reference to variables that we need a trace of - * @param bool should we use print_r ? (else we use var_dump) - * @param bool should we log or return the output + * @param $variable_name + * @param $variable + * @param bool $print + * @param bool $log + * @param string $comp variable name + * + * @internal param \reference $mixed to variables that we need a trace of + * @internal param \should $bool we use print_r ? (else we use var_dump) + * @internal param \should $bool we log or return the output * * @return string the generated output * @@ -526,9 +569,10 @@ class CRM_Core_Error extends PEAR_ErrorStack { /** * display the error message on terminal * - * @param string message to be output - * @param bool should we log or return the output + * @param $message + * @param bool $out should we log or return the output * + * @param string $comp message to be output * @return string format of the backtrace * * @access public @@ -547,6 +591,7 @@ class CRM_Core_Error extends PEAR_ErrorStack { $file_log->close(); if ($config->userFrameworkLogging) { + // should call $config->userSystem->logger($message) here - but I got a situation where userSystem was not an object - not sure why if ($config->userSystem->is_drupal and function_exists('watchdog')) { watchdog('civicrm', $message, NULL, WATCHDOG_DEBUG); } @@ -571,6 +616,8 @@ class CRM_Core_Error extends PEAR_ErrorStack { /** * Obtain a reference to the error log * + * @param string $comp + * * @return Log */ static function createDebugLogger($comp = '') { @@ -601,6 +648,10 @@ class CRM_Core_Error extends PEAR_ErrorStack { return Log::singleton('file', $fileName); } + /** + * @param string $msg + * @param bool $log + */ static function backtrace($msg = 'backTrace', $log = FALSE) { $backTrace = debug_backtrace(); $message = self::formatBacktrace($backTrace); @@ -751,6 +802,14 @@ class CRM_Core_Error extends PEAR_ErrorStack { return $msg; } + /** + * @param $message + * @param int $code + * @param string $level + * @param null $params + * + * @return object + */ static function createError($message, $code = 8000, $level = 'Fatal', $params = NULL) { $error = CRM_Core_Error::singleton(); $error->push($code, $level, array($params), $message); @@ -760,8 +819,10 @@ class CRM_Core_Error extends PEAR_ErrorStack { /** * Set a status message in the session, then bounce back to the referrer. * - * @param string $status The status message to set + * @param string $status The status message to set * + * @param null $redirect + * @param string $title * @return void * @access public * @static @@ -820,6 +881,13 @@ class CRM_Core_Error extends PEAR_ErrorStack { * This function is no longer used by v3 api. * @fixme Some core files call it but it should be re-thought & renamed or removed */ + /** + * @param $msg + * @param null $data + * + * @return array + * @throws Exception + */ public static function &createAPIError($msg, $data = NULL) { if (self::$modeException) { throw new Exception($msg, $data); @@ -835,6 +903,9 @@ class CRM_Core_Error extends PEAR_ErrorStack { return $values; } + /** + * @param $file + */ public static function movedSiteError($file) { $url = CRM_Utils_System::url('civicrm/admin/setting/updateConfigBackend', 'reset=1', @@ -855,6 +926,12 @@ class CRM_Core_Error extends PEAR_ErrorStack { CRM_Utils_System::civiExit($code); } + /** + * @param $error + * @param const $type + * + * @return bool + */ public static function isAPIError($error, $type = CRM_Core_Error::FATAL_ERROR) { if (is_array($error) && !empty($error['is_error'])) { $code = $error['error_message']['code'];