|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Illuminate\Notifications\Messages; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Notifications\Action; |
|
6
|
|
|
|
|
7
|
|
|
class SimpleMessage |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* The "level" of the notification (info, success, error). |
|
11
|
|
|
* |
|
12
|
|
|
* @var string |
|
13
|
|
|
*/ |
|
14
|
|
|
public $level = 'info'; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* The subject of the notification. |
|
18
|
|
|
* |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
public $subject; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The "intro" lines of the notification. |
|
25
|
|
|
* |
|
26
|
|
|
* @var array |
|
27
|
|
|
*/ |
|
28
|
|
|
public $introLines = []; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* The "outro" lines of the notification. |
|
32
|
|
|
* |
|
33
|
|
|
* @var array |
|
34
|
|
|
*/ |
|
35
|
|
|
public $outroLines = []; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* The text / label for the action. |
|
39
|
|
|
* |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
public $actionText; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* The action URL. |
|
46
|
|
|
* |
|
47
|
|
|
* @var string |
|
48
|
|
|
*/ |
|
49
|
|
|
public $actionUrl; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Indicate that the notification gives information about a successful operation. |
|
53
|
|
|
* |
|
54
|
|
|
* @return $this |
|
55
|
|
|
*/ |
|
56
|
|
|
public function success() |
|
57
|
|
|
{ |
|
58
|
|
|
$this->level = 'success'; |
|
59
|
|
|
|
|
60
|
|
|
return $this; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Indicate that the notification gives information about an error. |
|
65
|
|
|
* |
|
66
|
|
|
* @return $this |
|
67
|
|
|
*/ |
|
68
|
|
|
public function error() |
|
69
|
|
|
{ |
|
70
|
|
|
$this->level = 'error'; |
|
71
|
|
|
|
|
72
|
|
|
return $this; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Set the "level" of the notification (success, error, etc.). |
|
77
|
|
|
* |
|
78
|
|
|
* @param string $level |
|
79
|
|
|
* @return $this |
|
80
|
|
|
*/ |
|
81
|
1 |
|
public function level($level) |
|
82
|
|
|
{ |
|
83
|
1 |
|
$this->level = $level; |
|
84
|
|
|
|
|
85
|
1 |
|
return $this; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Set the subject of the notification. |
|
90
|
|
|
* |
|
91
|
|
|
* @param string $subject |
|
92
|
|
|
* @return $this |
|
93
|
|
|
*/ |
|
94
|
|
|
public function subject($subject) |
|
95
|
|
|
{ |
|
96
|
|
|
$this->subject = $subject; |
|
97
|
|
|
|
|
98
|
|
|
return $this; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Add a line of text to the notification. |
|
103
|
|
|
* |
|
104
|
|
|
* @param \Illuminate\Notifications\Action|string $line |
|
105
|
|
|
* @return $this |
|
106
|
|
|
*/ |
|
107
|
|
|
public function line($line) |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->with($line); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Add a line of text to the notification. |
|
114
|
|
|
* |
|
115
|
|
|
* @param \Illuminate\Notifications\Action|string|array $line |
|
116
|
|
|
* @return $this |
|
117
|
|
|
*/ |
|
118
|
1 |
|
public function with($line) |
|
119
|
|
|
{ |
|
120
|
1 |
|
if ($line instanceof Action) { |
|
121
|
|
|
$this->action($line->text, $line->url); |
|
122
|
1 |
|
} elseif (! $this->actionText) { |
|
123
|
1 |
|
$this->introLines[] = $this->formatLine($line); |
|
124
|
|
|
} else { |
|
125
|
|
|
$this->outroLines[] = $this->formatLine($line); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
1 |
|
return $this; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Format the given line of text. |
|
133
|
|
|
* |
|
134
|
|
|
* @param string|array $line |
|
135
|
|
|
* @return string |
|
136
|
|
|
*/ |
|
137
|
1 |
|
protected function formatLine($line) |
|
138
|
|
|
{ |
|
139
|
1 |
|
if (is_array($line)) { |
|
140
|
1 |
|
return implode(' ', array_map('trim', $line)); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
1 |
|
return trim(implode(' ', array_map('trim', explode(PHP_EOL, $line)))); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* Configure the "call to action" button. |
|
148
|
|
|
* |
|
149
|
|
|
* @param string $text |
|
150
|
|
|
* @param string $url |
|
151
|
|
|
* @return $this |
|
152
|
|
|
*/ |
|
153
|
|
|
public function action($text, $url) |
|
154
|
|
|
{ |
|
155
|
|
|
$this->actionText = $text; |
|
156
|
|
|
$this->actionUrl = $url; |
|
157
|
|
|
|
|
158
|
|
|
return $this; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* Get an array representation of the message. |
|
163
|
|
|
* |
|
164
|
|
|
* @return array |
|
165
|
|
|
*/ |
|
166
|
1 |
|
public function toArray() |
|
167
|
|
|
{ |
|
168
|
|
|
return [ |
|
169
|
1 |
|
'level' => $this->level, |
|
170
|
1 |
|
'subject' => $this->subject, |
|
171
|
1 |
|
'introLines' => $this->introLines, |
|
172
|
1 |
|
'outroLines' => $this->outroLines, |
|
173
|
1 |
|
'actionText' => $this->actionText, |
|
174
|
1 |
|
'actionUrl' => $this->actionUrl, |
|
175
|
|
|
]; |
|
176
|
|
|
} |
|
177
|
|
|
} |
|
178
|
|
|
|