-
Notifications
You must be signed in to change notification settings - Fork 0
/
Alert.php
109 lines (85 loc) · 1.84 KB
/
Alert.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/**
* @file Alert.php
* @author Gabriele Tozzi <[email protected]>
* @package DoPhp
* @brief Classes for handling Alerts
*/
namespace dophp;
/**
* Interface for implementing an alert.
* Alerts are special classes that may be set when session is active and then
* are kept during the session
*/
interface Alert {
// Alert type consts
const TYPE_SUCCESS = 'success';
const TYPE_INFO = 'info';
const TYPE_WARNING = 'warning';
const TYPE_DANGER = 'danger';
/**
* Returns alert type, usually one of the TYPE_ constants
*/
public function getType();
/**
* Returns alert creation date and time
*/
public function getTime();
/**
* Returns alert message
*/
public function getMessage();
}
/**
* Base class for implementing an Alert
*/
abstract class AlertBase implements Alert {
protected $_time;
protected $_type;
/**
* Constructs the alert
*
* @param $type string: The alert type
*/
public function __construct($type) {
$this->_type = $type;
$this->_time = new \DateTime();
}
public function getType() {
return $this->_type;
}
public function getTime() {
return $this->_time;
}
abstract public function getMessage();
public function __toString() {
return $this->getMessage();
}
}
/**
* Alert stored when a login error occurs
*/
class LoginErrorAlert extends AlertBase {
protected $_exception;
/**
* Constructs the alert from the exception
*
* @param $exception PageDenied The original exception
*/
public function __construct(PageDenied $exception) {
$this->_exception = $exception;
parent::__construct(self::TYPE_WARNING);
}
public function getMessage() {
$mex = $this->_exception->getMessage();
return $mex ? $mex : _('Access denied');
}
/**
* Returns the original exception
*
* @return PageDenied
*/
public function getException() {
return $this->_exception;
}
}