From 3c2957abfb1ad26173c11d923d827b662371472b Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 23 Sep 2007 11:28:53 -0400 Subject: [PATCH] Cleaing up error reporting and error triggering in Api.php * Api.php: Removed the APIError() system and we now use exceptions instead of trigger_error() --- Api.php | 48 ++++++++++++++---------------------------------- 1 file changed, 14 insertions(+), 34 deletions(-) diff --git a/Api.php b/Api.php index 59b0ef7..44a647b 100644 --- a/Api.php +++ b/Api.php @@ -77,6 +77,12 @@ if (!defined('REQ_AUTO')) */ abstract class BSApi { + /** + * The callback function for the error handler + * @var string + */ + public static $errorHandler; + /** * Fields: used for verification and sanitization * NAME => array(TYPE, REQUIRED, VERIFY METHOD (:self for self-named method), RELATION => array(FILE, CLASS IN FILE, ALTERNATE FIELD NAME)) @@ -153,19 +159,19 @@ abstract class BSApi private function _processErrorQueue() { // we want to explicitly specify silence - if (APIError() == 'silent') + if (self::$errorHandler == 'silent') { return; } - if (!is_callable(APIError())) + if (!is_callable(self::$errorHandler)) { - trigger_error('No APIError() handler has been set'); + throw new Exception('No BSApi::$errorHandler handler has been set'); } foreach ($this->errors AS $e) { - call_user_func(APIError(), $e); + call_user_func(BSApi::$errorHandler, $e); } } @@ -200,7 +206,7 @@ abstract class BSApi { if (!isset($this->fields["$field"])) { - trigger_error('Field "' . $field . '" is not valid'); + throw new Exception('Field "' . $field . '" is not valid'); return; } @@ -250,7 +256,7 @@ abstract class BSApi { if (!$this->values["$field"]) { - trigger_error('The specified field "' . $field . '" for the condition could not be found as it is not set'); + throw new Exception('The specified field "' . $field . '" for the condition could not be found as it is not set'); continue; } @@ -270,7 +276,7 @@ abstract class BSApi { if (!$this->values["$name"]) { - trigger_error('Cannot determine condition from the REQ_AUTO field because it is not set'); + throw new Exception('Cannot determine condition from the REQ_AUTO field because it is not set'); continue; } @@ -280,7 +286,7 @@ abstract class BSApi if ($this->condition == '') { - trigger_error('No REQ_AUTO fields are present and therefore the condition cannot be created'); + throw new Exception('No REQ_AUTO fields are present and therefore the condition cannot be created'); } } } @@ -553,30 +559,4 @@ abstract class BSApi } } -// ################################################################### -/** -* Setter and getter method for the API error reporting system. Passing -* a name will cause the set, no arguments will cause the get. -* -* @param mixed Method name in callable form -* -* @return mixed Method name in callable form -*/ -function APIError($new = null) -{ - static $caller, $prev; - - if ($new === -1) - { - $caller = $prev; - } - else if ($new !== null) - { - $prev = $caller; - $caller = $new; - } - - return $caller; -} - ?> \ No newline at end of file -- 2.22.5