Xataface 2.0
Xataface Application Framework
Dataface/Error.php
Go to the documentation of this file.
00001 <?php
00002 /*-------------------------------------------------------------------------------
00003  * Xataface Web Application Framework
00004  * Copyright (C) 2005-2008 Web Lite Solutions Corp (shannah@sfu.ca)
00005  * 
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  * 
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019  *-------------------------------------------------------------------------------
00020  */
00021 require_once 'PEAR.php';
00022 
00023 define('DATAFACE_ERROR_PERMISSION_DENIED', 10101010);
00024 define('DATAFACE_ERROR_NO_IMPORT_FILTERS_FOUND', 10101011);
00025 define('DATAFACE_ERROR_DUPLICATE_ENTRY', 10101100);
00026 
00027 define('DATAFACE_E_NOTICE', 200);
00028 define('DATAFACE_E_PERMMISSIONS', 210);
00029 define('DATAFACE_E_PERMISSION_DENIED', 211);
00030 define('DATAFACE_E_LOGIN_FAILURE', 212);
00031 define('DATAFACE_E_NO_RESULTS', 250);
00032 
00033 
00034 define('DATAFACE_E_WARNING', 100);
00035 define('DATAFACE_E_NO_IMPORT_FILTERS_FOUND', 111);
00036 define('DATAFACE_E_DUPLICATE_ENTRY', 112);
00037 
00038 define('DATAFACE_E_ERROR', 300);
00039 define('DATAFACE_E_IO_ERROR', 320);
00040 define('DATAFACE_E_DELETE_FAILED', 321);
00041 define('DATAFACE_E_WRITE_FAILED', 322);
00042 define('DATAFACE_E_READ_FAILED', 323);
00043 define('DATAFACE_E_NO_TABLE_SPECIFIED', 350);
00044 define('DATAFACE_E_MISSING_KEY', 351);
00045 define('DATAFACE_E_REQUEST_NOT_HANDLED', 201);
00046 
00047 
00048 
00049 
00050 
00051 class Dataface_Error extends PEAR_Error {
00052 
00053         
00054         public static function stringRepresentation($arg){
00055                 if ( is_object($arg) ) return get_class($arg).' Object';
00056                 if ( is_array($arg) ) return 'array('.implode(',', array_map(array('Dataface_Error','stringRepresentation'), $arg)).')';
00057                 return strval($arg);
00058         }
00059         
00060         public static function printStackTrace(){
00061                 $debug = debug_backtrace();
00062                 $out = "";
00063                 foreach ($debug as $line){
00064                         $args = '';
00065                         if ( isset($line['args']) ){
00066                                 foreach ($line['args'] as $arg){
00067                                         $args .= substr(Dataface_Error::stringRepresentation($arg), 0, 100).',';
00068                                 }
00069                         }
00070                         $args = substr($args,0,strlen($args)-1);
00071                         $out .= "On line ".@$line['line']." of file ".@$line['file']." in function ".@$line['function']."($args)\n<br>";
00072                 }
00073                 return $out;
00074         }
00075         
00076         public static function permissionDenied($msg="Permission Denied", $userInfo=''){
00077                 if ( !$userInfo ) $userInfo = Dataface_Error::printStackTrace();
00078                 $err = PEAR::raiseError($msg, DATAFACE_E_PERMISSION_DENIED, E_USER_WARNING, null, $userInfo);
00079                 return $err;
00080         }
00081         
00082         public static function isPermissionDenied($obj){
00083                 if ( PEAR::isError($obj) and $obj->getCode() == DATAFACE_E_PERMISSION_DENIED ) return true;
00084                 return false;
00085         }
00086         
00087         public static function noImportFiltersFound($msg="No Import filters found", $userInfo=''){
00088                 if ( !$userInfo ) $userInfo = Dataface_Error::printStackTrace();
00089                 $err = PEAR::raiseError($msg, DATAFACE_E_NO_IMPORT_FILTERS_FOUND, E_USER_WARNING, null, $userInfo);
00090                 return $err;
00091         
00092         }
00093         
00094         public static function isNoImportFiltersFound($obj){
00095                 if ( PEAR::isError($obj) and $obj->getCode() == DATAFACE_E_NO_IMPORT_FILTERS_FOUND ) return true;
00096                 return false;
00097         
00098         }
00099         
00100         public static function duplicateEntry($msg="This record already exists", $userInfo=''){
00101                 if ( !$userInfo ) $userInfo = Dataface_Error::printStackTrace();
00102                 $err = PEAR::raiseError($msg, DATAFACE_E_DUPLICATE_ENTRY, E_USER_WARNING, null, $userInfo);
00103                 return $err;
00104         }
00105         
00106         public static function isDuplicateEntry($obj){
00107                 if ( PEAR::isError($obj) and $obj->getCode() == DATAFACE_E_DUPLICATE_ENTRY ) return true;
00108                 return false;
00109         }
00110         
00111         public static function isError($obj){
00112                 if ( !PEAR::isError($obj) ) return false;
00113                 return ($obj->getCode() >= DATAFACE_E_ERROR);
00114         }
00115         
00116         public static function isWarning($obj){
00117                 if ( !PEAR::isError($obj) ) return false;
00118                 return ( $obj->getCode() >= DATAFACE_E_WARNING && $obj->getCode() < DATAFACE_E_NOTICE);
00119         }
00120         
00121         public static function isNotice(&$obj){
00122                 if ( !PEAR::isError($obj) ) return false;
00123                 return ( $obj->getCode() >= DATAFACE_E_NOTICE and $obj->getCode() < DATAFACE_E_ERROR);
00124                 
00125         }
00126 }
 All Data Structures Namespaces Files Functions Variables Enumerations