Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
Error.php
Go to the documentation of this file.
1 <?php
2 /*-------------------------------------------------------------------------------
3  * Xataface Web Application Framework
4  * Copyright (C) 2005-2008 Web Lite Solutions Corp (shannah@sfu.ca)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *-------------------------------------------------------------------------------
20  */
21 require_once 'PEAR.php';
22 
23 define('DATAFACE_ERROR_PERMISSION_DENIED', 10101010);
24 define('DATAFACE_ERROR_NO_IMPORT_FILTERS_FOUND', 10101011);
25 define('DATAFACE_ERROR_DUPLICATE_ENTRY', 10101100);
26 
27 define('DATAFACE_E_NOTICE', 200);
28 define('DATAFACE_E_PERMMISSIONS', 210);
29 define('DATAFACE_E_PERMISSION_DENIED', 211);
30 define('DATAFACE_E_LOGIN_FAILURE', 212);
31 define('DATAFACE_E_NO_RESULTS', 250);
32 
33 
34 define('DATAFACE_E_WARNING', 100);
35 define('DATAFACE_E_NO_IMPORT_FILTERS_FOUND', 111);
36 define('DATAFACE_E_DUPLICATE_ENTRY', 112);
37 define('DATAFACE_E_VERSION_MISMATCH', 113);
38 
39 define('DATAFACE_E_ERROR', 300);
40 define('DATAFACE_E_IO_ERROR', 320);
41 define('DATAFACE_E_DELETE_FAILED', 321);
42 define('DATAFACE_E_WRITE_FAILED', 322);
43 define('DATAFACE_E_READ_FAILED', 323);
44 define('DATAFACE_E_NO_TABLE_SPECIFIED', 350);
45 define('DATAFACE_E_MISSING_KEY', 351);
46 define('DATAFACE_E_REQUEST_NOT_HANDLED', 201);
47 
48 
49 
50 
51 
52 class Dataface_Error extends PEAR_Error {
53 
54 
55  public static function stringRepresentation($arg){
56  if ( is_object($arg) ) return get_class($arg).' Object';
57  if ( is_array($arg) ) return 'array('.implode(',', array_map(array('Dataface_Error','stringRepresentation'), $arg)).')';
58  return strval($arg);
59  }
60 
61  public static function printStackTrace(){
62  $debug = debug_backtrace();
63  $out = "";
64  foreach ($debug as $line){
65  $args = '';
66  if ( isset($line['args']) ){
67  foreach ($line['args'] as $arg){
68  $args .= substr(Dataface_Error::stringRepresentation($arg), 0, 100).',';
69  }
70  }
71  $args = substr($args,0,strlen($args)-1);
72  $out .= "On line ".@$line['line']." of file ".@$line['file']." in function ".@$line['function']."($args)\n<br>";
73  }
74  return $out;
75  }
76 
77  public static function permissionDenied($msg="Permission Denied", $userInfo=''){
78  if ( !$userInfo ) $userInfo = Dataface_Error::printStackTrace();
79  $err = PEAR::raiseError($msg, DATAFACE_E_PERMISSION_DENIED, E_USER_WARNING, null, $userInfo);
80  return $err;
81  }
82 
83  public static function isPermissionDenied($obj){
84  if ( PEAR::isError($obj) and $obj->getCode() == DATAFACE_E_PERMISSION_DENIED ) return true;
85  return false;
86  }
87 
88  public static function noImportFiltersFound($msg="No Import filters found", $userInfo=''){
89  if ( !$userInfo ) $userInfo = Dataface_Error::printStackTrace();
90  $err = PEAR::raiseError($msg, DATAFACE_E_NO_IMPORT_FILTERS_FOUND, E_USER_WARNING, null, $userInfo);
91  return $err;
92 
93  }
94 
95  public static function isNoImportFiltersFound($obj){
96  if ( PEAR::isError($obj) and $obj->getCode() == DATAFACE_E_NO_IMPORT_FILTERS_FOUND ) return true;
97  return false;
98 
99  }
100 
101  public static function duplicateEntry($msg="This record already exists", $userInfo=''){
102  if ( !$userInfo ) $userInfo = Dataface_Error::printStackTrace();
103  $err = PEAR::raiseError($msg, DATAFACE_E_DUPLICATE_ENTRY, E_USER_WARNING, null, $userInfo);
104  return $err;
105  }
106 
107  public static function isDuplicateEntry($obj){
108  if ( PEAR::isError($obj) and $obj->getCode() == DATAFACE_E_DUPLICATE_ENTRY ) return true;
109  return false;
110  }
111 
112  public static function isError($obj){
113  if ( !PEAR::isError($obj) ) return false;
114  return ($obj->getCode() >= DATAFACE_E_ERROR);
115  }
116 
117  public static function isWarning($obj){
118  if ( !PEAR::isError($obj) ) return false;
119  return ( $obj->getCode() >= DATAFACE_E_WARNING && $obj->getCode() < DATAFACE_E_NOTICE);
120  }
121 
122  public static function isNotice(&$obj){
123  if ( !PEAR::isError($obj) ) return false;
124  return ( $obj->getCode() >= DATAFACE_E_NOTICE and $obj->getCode() < DATAFACE_E_ERROR);
125 
126  }
127 }