-
Notifications
You must be signed in to change notification settings - Fork 0
/
Exceptions.php
executable file
·81 lines (68 loc) · 2.97 KB
/
Exceptions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
namespace ProcessWire;
use \Exception;
class TwackException extends WireException {
public function __construct($messageAddition = '', $message = 'A Twack-Error occurred. ', $code = 0, Exception $previous = null) {
parent::__construct($message . ' ' . $messageAddition, $code, $previous);
}
public function __toString() {
// In development mode, a path to the trigger of the exception should also be output.
if (wire('config')->debug == true || wire('user')->isSuperuser()) {
$message = __CLASS__ . ": [Code {$this->getCode()}]: {$this->getMessage()}";
$message .= "\r\Location: '{$this->getFile()}', \r\Line {$this->getLine()}";
return $message;
}
// Without development mode: Output only the error description:
return "{$this->getMessage()}";
}
}
class ComponentNotFoundException extends TwackException {
public function __construct($messageAddition = '', $message = 'Component not found. ', Exception $previous = null) {
parent::__construct($messageAddition, $message, 404, $previous);
}
}
class ViewNotFoundException extends TwackException {
public function __construct($messageAddition = '', $message = 'View not found. We cannot render the component. ', Exception $previous = null) {
parent::__construct($messageAddition, $message, 404, $previous);
}
}
class ParameterNotFoundException extends TwackException {
public function __construct($messageAddition = '', $message = 'Parameter not found. ', Exception $previous = null) {
parent::__construct($messageAddition, $message, 404, $previous);
}
}
class ComponentNotInitializedException extends TwackException {
public function __construct($componentname, $messageAddition = '', $message = false, Exception $previous = null) {
if (empty($componentname) || !is_string($componentname)) {
$componentname = 'Unknown';
}
if ($message === false) {
$message = 'The component "' . $componentname . '" could not be initialized. ';
}
parent::__construct($messageAddition, $message, 404, $previous);
}
}
class ComponentParameterException extends ComponentNotInitializedException {
public function __construct($componentname, $messageAddition = '', $message = false, Exception $previous = null) {
if (empty($componentname) || !is_string($componentname)) {
$componentname = 'Unknown';
}
if ($message === false) {
$message = 'Wrong or incomplete parameters were committed. The component "' . $componentname . '" could not be initialized. ';
}
parent::__construct($componentname, $messageAddition, $message, $previous);
}
}
class TwackAjaxException extends TwackException {
public $additionalData;
public function __construct($message = false, $additionalData = [], $code = 400, Exception $previous = null) {
$messageString = 'An Ajax-Error occurred.';
if ($message && !empty($message)) {
$messageString = 'An Ajax-Error occurred: ' . $message;
}
if (is_array($additionalData)) {
$this->additionalData = $additionalData;
}
parent::__construct('', $messageString, $code, $previous);
}
}