Message.php
1.42 KB
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
<?php
namespace AC;
use Exception;
use LogicException;
abstract class Message {
const SUCCESS = 'updated';
const ERROR = 'notice-error';
const WARNING = 'notice-warning';
const INFO = 'notice-info';
/**
* @var string
*/
protected $message;
/**
* @var string
*/
protected $type;
/**
* @var string
*/
protected $id;
/**
* @param string $message
*/
public function __construct( $message, $type = null ) {
if ( null === $type ) {
$type = self::SUCCESS;
}
$this->type = $type;
$this->message = trim( $message );
$this->validate();
}
protected function validate() {
if ( empty( $this->message ) ) {
throw new LogicException( 'Message cannot be empty' );
}
}
/**
* Render an View
* @return string
*/
abstract public function render();
/**
* Display self::render to the screen
* @throws Exception
*/
public function display() {
echo $this->render();
}
/**
* @return string
*/
public function get_message() {
return $this->message;
}
/**
* @return string
*/
public function get_type() {
return $this->type;
}
/**
* @param string $type
*
* @return $this
*/
public function set_type( $type ) {
$this->type = $type;
return $this;
}
/**
* @return string
*/
public function get_id() {
return $this->id;
}
/**
* @param string $id
*
* @return $this
*/
public function set_id( $id ) {
$this->id = $id;
return $this;
}
}