0.3.0 inital import
[mailer.git] / inc / classes / exceptions / class_FrameworkException.php
1 <?php
2 /**
3  * A general abstract exception. You should not throw this even when you
4  * remove the "abstract" key-word. Better you make your own exception and
5  * attach a dedicated message to it.
6  *
7  * @author      Roland Haeder <roland __NOSPAM__ [at] __REMOVE_ME__ mxchange [dot] org>
8  * @version     1.0
9  */
10 abstract class FrameworkException extends ReflectionException {
11         /**
12          * Array for the backtrace
13          */
14         private $backTrace = array();
15
16         /**
17          * The super constructor for all exceptions
18          *
19          * @param               $message                The non-optional message for the exception
20          * @param               $code           An optional code for better debugging
21          * @return      void
22          */
23         public function __construct($message, $code = 0) {
24                 // Extract backtrace
25                 $this->saveBackTrace();
26
27                 // Cast all data
28                 $message = (string) $message;
29                 $code    = (int)    $code;
30
31                 // make sure everything is assigned properly
32                 parent::__construct($message, $code);
33         }
34
35         /**
36          * Save the current backtrace
37          *
38          * @return      void
39          */
40         private final function saveBackTrace () {
41                 $this->backTrace = debug_backtrace();
42         }
43
44         /**
45          * Get saved backtrace
46          *
47          * @return      $backTrace      The full backtrace in an array
48          */
49         public final function getBackTrace () {
50                 return $this->backTrace;
51         }
52
53         /**
54          * Returns the name of the thrown exception
55          *
56          * @return      $toString               The name of the thrown exception
57          */
58         public function __toString() {
59                 return get_class($this);
60         }
61
62         /**
63          * Getter for hex-decimal code
64          *
65          * @return      $hexCode        The exception code in hex-decimal format
66          */
67         public final function getHexCode () {
68                 // Get the decimal code
69                 $code = $this->getCode();
70
71                 // Format it to hex-decimal, 0x as prefix and 3 chars
72                 $hexCode = sprintf("0x%03s", dechex($code));
73
74                 // Return it
75                 return $hexCode;
76         }
77 }
78
79 // [EOF]
80 ?>