Cleaing up error reporting and error triggering in Api.php
authorRobert Sesek <rsesek@bluestatic.org>
Sun, 23 Sep 2007 15:28:53 +0000 (11:28 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Sun, 23 Sep 2007 15:28:53 +0000 (11:28 -0400)
* Api.php: Removed the APIError() system and we now use exceptions instead of trigger_error()

Api.php

diff --git a/Api.php b/Api.php
index 59b0ef7a2bd0e9a4b155dd5277f101dc530ec4d4..44a647b17947850335390fb11aed0ee2ac897aae 100644 (file)
--- 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