1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* ~~summary~~ |
5
|
|
|
* |
6
|
|
|
* ~~description~~ |
7
|
|
|
* |
8
|
|
|
* PHP version 5 |
9
|
|
|
* |
10
|
|
|
* @category Net |
11
|
|
|
* @package PEAR2_Net_RouterOS |
12
|
|
|
* @author Vasil Rangelov <[email protected]> |
13
|
|
|
* @copyright 2011 Vasil Rangelov |
14
|
|
|
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 |
15
|
|
|
* @version GIT: $Id$ |
16
|
|
|
* @link http://pear2.php.net/PEAR2_Net_RouterOS |
17
|
|
|
*/ |
18
|
|
|
/** |
19
|
|
|
* The namespace declaration. |
20
|
|
|
*/ |
21
|
|
|
namespace PEAR2\Net\RouterOS; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Base of this class. |
25
|
|
|
*/ |
26
|
|
|
use RuntimeException; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Refered to in the constructor. |
30
|
|
|
*/ |
31
|
|
|
use Exception as E; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Exception thrown by higher level classes (Util, etc.) when the router |
35
|
|
|
* returns an error. |
36
|
|
|
* |
37
|
|
|
* @category Net |
38
|
|
|
* @package PEAR2_Net_RouterOS |
39
|
|
|
* @author Vasil Rangelov <[email protected]> |
40
|
|
|
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 |
41
|
|
|
* @link http://pear2.php.net/PEAR2_Net_RouterOS |
42
|
|
|
*/ |
43
|
|
|
class RouterErrorException extends RuntimeException implements Exception |
44
|
|
|
{ |
45
|
|
|
const CODE_ITEM_ERROR = 0x100000; |
46
|
|
|
const CODE_SCRIPT_ERROR = 0x200000; |
47
|
|
|
const CODE_READ_ERROR = 0x010000; |
48
|
|
|
const CODE_WRITE_ERROR = 0x020000; |
49
|
|
|
const CODE_EXEC_ERROR = 0x040000; |
50
|
|
|
|
51
|
|
|
const CODE_CACHE_ERROR = 0x100001; |
52
|
|
|
const CODE_GET_ERROR = 0x110001; |
53
|
|
|
const CODE_GET_LOOKUP_ERROR = 0x130001; |
54
|
|
|
const CODE_GETALL_ERROR = 0x110002; |
55
|
|
|
const CODE_ADD_ERROR = 0x120001; |
56
|
|
|
const CODE_SET_ERROR = 0x120002; |
57
|
|
|
const CODE_REMOVE_ERROR = 0x120004; |
58
|
|
|
const CODE_ENABLE_ERROR = 0x120012; |
59
|
|
|
const CODE_DISABLE_ERROR = 0x120022; |
60
|
|
|
const CODE_COMMENT_ERROR = 0x120042; |
61
|
|
|
const CODE_UNSET_ERROR = 0x120082; |
62
|
|
|
const CODE_MOVE_ERROR = 0x120107; |
63
|
|
|
const CODE_SCRIPT_ADD_ERROR = 0x220001; |
64
|
|
|
const CODE_SCRIPT_REMOVE_ERROR = 0x220004; |
65
|
|
|
const CODE_SCRIPT_RUN_ERROR = 0x240001; |
66
|
|
|
const CODE_SCRIPT_FILE_ERROR = 0x240003; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* The complete response returned by the router. |
70
|
|
|
* |
71
|
|
|
* NULL when the router was not contacted at all. |
72
|
|
|
* |
73
|
|
|
* @var ResponseCollection|null |
74
|
|
|
*/ |
75
|
|
|
private $_responses = null; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Creates a new RouterErrorException. |
79
|
|
|
* |
80
|
|
|
* @param string $message The Exception message to throw. |
81
|
|
|
* @param int $code The Exception code. |
82
|
|
|
* @param E|null $previous The previous exception used for |
83
|
|
|
* the exception chaining. |
84
|
|
|
* @param ResponseCollection|null $responses The complete set responses |
85
|
|
|
* returned by the router. |
86
|
|
|
*/ |
87
|
|
|
public function __construct( |
88
|
|
|
$message, |
89
|
|
|
$code = 0, |
90
|
|
|
E $previous = null, |
91
|
|
|
ResponseCollection $responses = null |
92
|
|
|
) { |
93
|
|
|
parent::__construct($message, $code, $previous); |
94
|
|
|
$this->_responses = $responses; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Gets the complete set responses returned by the router. |
99
|
|
|
* |
100
|
|
|
* @return ResponseCollection|null The complete set responses |
101
|
|
|
* returned by the router. |
102
|
|
|
*/ |
103
|
|
|
public function getResponses() |
104
|
|
|
{ |
105
|
|
|
return $this->_responses; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
// @codeCoverageIgnoreStart |
109
|
|
|
// String representation is not reliable in testing |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Returns a string representation of the exception. |
113
|
|
|
* |
114
|
|
|
* @return string The exception as a string. |
115
|
|
|
*/ |
116
|
|
|
public function __toString() |
117
|
|
|
{ |
118
|
|
|
$result = parent::__toString(); |
119
|
|
|
if ($this->_responses instanceof ResponseCollection) { |
120
|
|
|
$result .= "\nResponse collection:\n" . |
121
|
|
|
print_r($this->_responses->toArray(), true); |
|
|
|
|
122
|
|
|
} |
123
|
|
|
return $result; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
// @codeCoverageIgnoreEnd |
127
|
|
|
} |
128
|
|
|
|