X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=api%2FException.php;h=8ec7eb3ae6a8212a13e790b1b6fa02d247dae97f;hb=2e66abf8190dde0439f825a12234323404ea49ef;hp=48d89e7572e38097ac56c65b6ac64a6ffee3ddbc;hpb=8906b92a00b4907e620e80624fb6ac6baa368bed;p=civicrm-core.git diff --git a/api/Exception.php b/api/Exception.php index 48d89e7572..8ec7eb3ae6 100644 --- a/api/Exception.php +++ b/api/Exception.php @@ -1,5 +1,6 @@ extraParams = $extraParams + array('error_code' => $error_code); } - // custom string representation of object + /** + * custom string representation of object + * @return string + */ public function __toString() { return __CLASS__ . ": [{$this->code}]: {$this->message}\n"; } + /** + * @return array + */ public function getExtraParams() { return $this->extraParams; } - public function getErrorCodes(){ + /** + * @return array + */ + public function getErrorCodes() { return array( - 2000 => '$params was not an array', - 2001 => 'Invalid Value for Date field', - 2100 => 'String value is longer than permitted length', - self::UNAUTHORIZED => 'Unauthorized', - self::NOT_IMPLEMENTED => 'Entity or method is not implemented', - ); + 2000 => '$params was not an array', + 2001 => 'Invalid Value for Date field', + 2100 => 'String value is longer than permitted length', + self::UNAUTHORIZED => 'Unauthorized', + self::NOT_IMPLEMENTED => 'Entity or method is not implemented', + ); } + } + /** * This api exception returns more information than the default one. We are using it rather than * API_Exception from the api wrapper as the namespace is more generic - * @param string $message the human friendly error message - * @param string $error_code a computer friendly error code. By convention, no space (but underscore allowed) - * ex: mandatory_missing, duplicate, invalid_format - * @param array $data extra params to return. eg an extra array of ids. It is not mandatory, but can help the computer using the api. Keep in mind the api consumer isn't to be trusted. eg. the database password is NOT a good extra data */ -class CiviCRM_API3_Exception extends Exception -{ +class CiviCRM_API3_Exception extends Exception { private $extraParams = array(); - public function __construct($message, $error_code, $extraParams = array(),Exception $previous = null) { + + /** + * @param string $message + * The human friendly error message. + * @param mixed $error_code + * A computer friendly error code. By convention, no space (but underscore + * allowed) (ex: mandatory_missing, duplicate, invalid_format). + * @param array $extraParams + * Extra params to return. eg an extra array of ids. It is not mandatory, + * but can help the computer using the api. Keep in mind the api consumer + * isn't to be trusted. eg. the database password is NOT a good extra data. + * @param Exception|NULL $previous + * A previous exception which caused this new exception. + */ + public function __construct($message, $error_code, $extraParams = array(), Exception $previous = NULL) { parent::__construct(ts($message)); $this->extraParams = $extraParams + array('error_code' => $error_code); } - // custom string representation of object + /** + * custom string representation of object + * @return string + */ public function __toString() { return __CLASS__ . ": [{$this->extraParams['error_code']}: {$this->message}\n"; } + /** + * @return mixed + */ public function getErrorCode() { return $this->extraParams['error_code']; } + + /** + * @return array + */ public function getExtraParams() { return $this->extraParams; } + }