-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathMessage.php
80 lines (60 loc) · 1.41 KB
/
Message.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
<?php
namespace AC;
use Exception;
use LogicException;
abstract class Message
{
public const SUCCESS = 'updated'; // green
public const ERROR = 'notice-error'; // red
public const WARNING = 'notice-warning'; // yellow
public const INFO = 'notice-info'; // blue
protected $message;
protected $type;
protected $id = '';
public function __construct(string $message, string $type = null)
{
if (null === $type) {
$type = self::SUCCESS;
}
$this->type = $type;
$this->message = trim($message);
$this->validate();
}
protected function validate(): void
{
if (empty($this->message)) {
throw new LogicException('Message cannot be empty');
}
}
abstract public function render(): string;
/**
* Display self::render to the screen
* @throws Exception
*/
public function display(): void
{
echo $this->render();
}
public function get_message(): string
{
return $this->message;
}
public function get_type(): string
{
return $this->type;
}
public function set_type(string $type): self
{
$this->type = $type;
return $this;
}
public function get_id(): string
{
return $this->id;
}
public function set_id(string $id): self
{
$this->id = $id;
return $this;
}
}