root/trunk/patError.php

Revision 45 (checked in by schst, 4 months ago)

Got rid of E_STRICT messages, adjusted code to PEAR standards

  • Property 0 set to
  • Property 1 set to
Line 
1 <?php
2 /**
3  * patError error object used by the patFormsError manager as error messages
4  * container for precise error management.
5  *
6  *    $Id$
7  *
8  * @access        public
9  * @package       patError
10  */
11
12 /**
13  * patError error object used by the patFormsError manager as error messages
14  * container for precise error management.
15  *
16  * $Id$
17  *
18  * @access        public
19  * @package       patError
20  * @version       0.3
21  * @author        gERD Schaufelberger <gerd@php-tools.net>
22  * @author        Sebastian Mordziol <argh@php-tools.net>
23  * @author        Stephan Schmidt <schst@php-tools.net>
24  * @license       LGPL
25  * @link          http://www.php-tools.net
26  */
27 class patError {
28    /**
29     * stores the error level for this error
30     *
31     * @access    private
32     * @var        string
33     */
34     protected $level  =   null;
35     
36    /**
37     * stores the code of the error
38     *
39     * @access    private
40     * @var        string
41     */
42     protected $code  =   null;
43
44    /**
45     * stores the error message - this is the message that can also be shown the
46     * user if need be.
47     *
48     * @access    private
49     * @protected        string
50     */
51     protected $message  =   null;
52
53    /**
54     * additional info that is relevant for the developer of the script (e.g. if
55     * a database connect fails, the dsn used) and that the end-user should not
56     * see.
57     *
58     * @access    private
59     * @protected        string
60     */
61     protected $info  =   '';
62     
63    /**
64     * stores the filename of the file the error occurred in.
65     *
66     * @access    private
67     * @protected        string
68     */
69     protected $file  =   '';
70     
71    /**
72     * stores the line number the error occurred in.
73     *
74     * @access    private
75     * @protected        integer
76     */
77     protected $line  =   0;
78
79    /**
80     * stores the name of the method the error occurred in
81     *
82     * @access    private
83     * @protected        string
84     */
85     protected $function  =   '';
86
87    /**
88     * stores the name of the class (if any) the error occurred in.
89     *
90     * @access    private
91     * @protected        string
92     */
93     protected $class  =   '';
94     
95    /**
96     * stores the type of error, as it is listed in the error backtrace
97     *
98     * @access    private
99     * @protected        string
100     */
101     protected $type  =   '';
102
103    /**
104     * stores the arguments the method that the error occurred in had received.
105     *
106     * @access    private
107     * @protected        array
108     */
109     protected $args  =   array();
110     
111    /**
112     * stores the complete debug backtrace (if your PHP version has the
113     * debug_backtrace function)
114     *
115     * @access    private
116     * @protected        mixed
117     */
118     protected $backtrace  =   false;
119     
120    /**
121     * constructor - used to set up the error with all needed error details.
122     *
123     * @access   public
124     * @param    int       $level    The error level (use the PHP constants E_ALL, E_NOTICE etc.).
125     * @param    string    $code    The error code from the application
126     * @param    string    $msg    The error message
127     * @param    string    $info    Optional: The additional error information.
128     */
129     public function __construct($level, $code, $msg, $info = null) {
130         static $raise = array('raise',
131                               'raiseerror',
132                               'raisewarning',
133                               'raisenotice'
134                              );
135                                         
136         $this->level   = $level;
137         $this->code    = $code;
138         $this->message =$msg;
139         
140         if ($info != null) {
141             $this->info = $info;
142         }
143     
144         $this->backtrace = debug_backtrace();
145         
146         for ($i = count( $this->backtrace ) - 1; $i >= 0; --$i) {
147             if (in_array($this->backtrace[$i]['function'], $raise)) {
148                 ++$i;
149                 if (isset($this->backtrace[$i]['file'])) {
150                     $this->file = $this->backtrace[$i]['file'];
151                 }
152                 if (isset( $this->backtrace[$i]['line'])) {
153                     $this->line = $this->backtrace[$i]['line'];
154                 }
155                 if (isset($this->backtrace[$i]['class'])) {
156                     $this->class    =    $this->backtrace[$i]['class'];
157                 }
158                 if (isset($this->backtrace[$i]['function'])) {
159                     $this->function = $this->backtrace[$i]['function'];
160                 }
161                 if (isset($this->backtrace[$i]['type'])) {
162                     $this->type = $this->backtrace[$i]['type'];
163                 }
164                 $this->args = false;
165                 if (isset($this->backtrace[$i]['args'])) {
166                     $this->args =$this->backtrace[$i]['args'];
167                 }
168                 break;
169             }
170         }
171     }
172     
173    /**
174     * returns the error level of the error - corresponds to the PHP
175     * error levels (E_ALL, E_NOTICE...)
176     *
177     * @access    public
178     * @return    int $level    The error level
179     * @see        $level
180     */
181     public function getLevel() {
182         return $this->level;
183     }
184
185
186    /**
187     * retrieves the error message
188     *
189     * @access    public
190     * @return    string     $msg    The stored error message
191     * @see        $message
192     */
193     public function getMessage() {
194         return $this->message;
195     }
196
197    /**
198     * retrieves the additional error information (information usually
199     * only relevant for developers)
200     *
201     * @access    public
202     * @return    mixed $info    The additional information
203     * @see        $info
204     */
205     public function getInfo() {
206         return $this->info;
207     }
208     
209    /**
210     * recieve error code
211     *
212     * @access    public
213     * @return    string|integer        error code (may be a string or an integer)
214     * @see        $code
215     */
216     public function getCode() {
217         return $this->code;
218     }
219
220    /**
221     * get the backtrace
222     *
223     * This is only possible, if debug_backtrace() is available.
224     *
225     * @access    public
226     * @return    array backtrace
227     * @see       $backtrace
228     */
229     public function getBacktrace() {
230         return $this->backtrace;
231     }
232
233    /**
234     * get the filename in which the error occured
235     *
236     * This is only possible, if debug_backtrace() is available.
237     *
238     * @access    public
239     * @return    string filename
240     * @see       $file
241     */
242     public function getFile() {
243         return $this->file;
244     }
245
246    /**
247     * get the line number in which the error occured
248     *
249     * This is only possible, if debug_backtrace() is available.
250     *
251     * @access    public
252     * @return    integer line number
253     * @see        $line
254     */
255     public function getLine() {
256         return $this->line;
257     }
258 }
259 ?>
Note: See TracBrowser for help on using the browser.