2
2
/**
3
3
* @package at.exceptable
4
4
* @author Adrian <adrian@enspi.red>
5
- * @copyright 2014 - 2016
5
+ * @copyright 2014 - 2018
6
6
* @license GPL-3.0 (only)
7
7
*
8
8
* This program is free software: you can redistribute it and/or modify it
22
22
23
23
use Throwable ;
24
24
25
+ use at \exceptable \ExceptableException ;
26
+
25
27
/**
26
28
* augmented interface for exceptions.
27
29
*
32
34
* exceptable::getSeverity() will need to be aliased when the trait is used.
33
35
* - implementations cannot extend from PDOException,
34
36
* because it breaks the Throwable interface (its getCode() returns a string).
35
- *
36
- * @method string Throwable::__toString( void )
37
- * @method int Throwable::getCode( void )
38
- * @method string Throwable::getFile( void )
39
- * @method int Throwable::getLine( void )
40
- * @method string Throwable::getMessage( void )
41
- * @method Throwable Throwable::getPrevious( void )
42
- * @method array Throwable::getTrace( void )
43
- * @method string Throwable::getTraceAsString( void )
44
37
*/
45
- interface Exceptable extends \ Throwable {
38
+ interface Exceptable extends Throwable {
46
39
47
40
/**
48
41
* exception severity levels.
@@ -51,57 +44,34 @@ interface Exceptable extends \Throwable {
51
44
* @type int WARNING warning
52
45
* @type int NOTICE notice
53
46
*/
54
- const ERROR = E_ERROR ;
55
- const WARNING = E_WARNING ;
56
- const NOTICE = E_NOTICE ;
57
-
58
- /**
59
- * default info for unknown/generic exception cases.
60
- *
61
- * @type int DEFAULT_CODE
62
- * @type int DEFAULT_MESSAGE
63
- * @type int DEFAULT_SEVERITY
64
- */
65
- const DEFAULT_CODE = 0 ;
66
- const DEFAULT_MESSAGE = '' ;
67
- const DEFAULT_SEVERITY = self ::ERROR ;
47
+ public const ERROR = E_ERROR ;
48
+ public const WARNING = E_WARNING ;
49
+ public const NOTICE = E_NOTICE ;
68
50
69
51
/**
70
52
* gets information about a code known to the implementing class.
71
53
*
72
54
* @param int $code the exception code to look up
73
55
* @throws ExceptableException if the code is not known to the implementation
74
- * @return array a map of info about the code,
75
- * including (at a minimum) its "code", "severity", and "message".
56
+ * @return array a map of info about the error condition
76
57
*/
77
- public static function get_info (int $ code ) : array ;
58
+ public static function getInfo (int $ code ) : array ;
78
59
79
60
/**
80
61
* checks whether the implementation has info about the given code.
81
62
*
82
63
* @param int $code the code to check
83
64
* @return bool true if the code is known; false otherwise
84
65
*/
85
- public static function has_info (int $ code ) : bool ;
66
+ public static function hasInfo (int $ code ) : bool ;
86
67
87
68
/**
88
- * @param string $0 exception message
89
- * if omitted, a message must be set based on the exception code
90
- * @param int $1 exception code
91
- * if omitted, a default code must be set
92
- * @param Throwable $2 previous exception
93
- * @param array $3 additional exception context
94
- * @throws ExceptableException if argument(s) are invalid
69
+ * @param int $code exception code
70
+ * @param array $context additional exception context
71
+ * @param Throwable|null $previous previous exception
72
+ * @throws ExceptableException if code is invalid
95
73
*/
96
- public function __construct (...$ args );
97
-
98
- /**
99
- * adds contextual info to this exception.
100
- *
101
- * @param array $context map of info to add
102
- * @return $this
103
- */
104
- public function addContext (array $ context ) : Exceptable ;
74
+ public function __construct (int $ code , array $ context = [], Throwable $ previous = null );
105
75
106
76
/**
107
77
* gets contextual info about this exception.
@@ -115,42 +85,12 @@ public function getContext() : array;
115
85
*
116
86
* @return Throwable the root exception
117
87
*/
118
- public function getRoot () : \ Throwable ;
88
+ public function getRoot () : Throwable ;
119
89
120
90
/**
121
91
* gets exception severity.
122
92
*
123
93
* @return int the exception severity
124
94
*/
125
95
public function getSeverity () : int ;
126
-
127
- /**
128
- * checks the exception severity.
129
- *
130
- * @return bool true if exception severity is "Error"; false otherwise
131
- */
132
- public function isError () : bool ;
133
-
134
- /**
135
- * checks the exception severity.
136
- *
137
- * @return bool true if exception severity is "Warning"; false otherwise
138
- */
139
- public function isWarning () : bool ;
140
-
141
- /**
142
- * checks the exception severity.
143
- *
144
- * @return bool true if exception severity is "Notice"; false otherwise
145
- */
146
- public function isNotice () : bool ;
147
-
148
- /**
149
- * adds contextual info to this exception.
150
- *
151
- * @param int $severity one of Exceptable::ERROR|WARNING|NOTICE
152
- * @throws ExceptableException if severity is invalid
153
- * @return $this
154
- */
155
- public function setSeverity (int $ severity ) : Exceptable ;
156
96
}
0 commit comments