initial setup of framework code
[cacert-mgr.git] / manager / library / exception / exception.Base.php
1 <?php
2 /**
3 * @package SLS
4 * @subpackage EXCEPTION
5 */
6
7 /**
8 * extend PHPs standard exception by some details
9 *
10 * @package SLS
11 * @subpackage EXCEPTION
12 * @author Markus Warg <mw@it-sls.de>
13 * @since 2009-02-23 16:10
14 * @version $Id: exception.Base.php 90 2010-03-09 09:48:27Z markus $
15 */
16 class BaseException extends Exception {
17 /**
18 * additional data / string
19 * @var string
20 */
21 protected $extra = '';
22
23 /**
24 * location of thrower
25 * @var string
26 */
27 protected $exception_location = '';
28
29 /**
30 * make new object
31 *
32 * @access public
33 * @param string $message
34 * @param int $code
35 */
36 public function __construct($message, $code = 0, $extra = '') {
37 $bt = debug_backtrace();
38
39 $remove_exception = 0;
40 while( $remove_exception < count($bt) && isset($bt[$remove_exception]['class']) && eregi('exception', $bt[$remove_exception]['class']) ) {
41 $remove_exception++;
42 }
43
44 if ($remove_exception > 0)
45 $remove_exception--;
46
47 if ($remove_exception < count($bt)) {
48 $this->exception_location = $bt[$remove_exception]['file'].':'.$bt[$remove_exception]['line'];
49 }
50
51 $this->extra = $extra;
52
53 parent::__construct($message,$code);
54 }
55
56 /**
57 * Make a string out of this exception
58 *
59 * @access public
60 * @return string
61 */
62 public function __toString() {
63 $out = __CLASS__ . '['.$this->code.']:';
64
65 if ($this->exception_location != '')
66 $out.= $this->exception_location;
67 $out .= ':';
68
69 $out .= " {$this->message}";
70
71 if (isset($this->extra) && strlen($this->extra) > 0)
72 $out .= " ({$this->extra})\n";
73
74 return $out;
75 }
76
77 /**
78 * get the extra info string
79 *
80 * @access public
81 * @return string
82 */
83 public function getExtraInfo() {
84 return $this->extra;
85 }
86
87 /**
88 * get the exception location string
89 *
90 * @access public
91 * @return string
92 */
93 public function getExceptionLocation() {
94 return $this->exception_location;
95 }
96
97 }
98 ?>