Total Complexity | 9 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | class Notification |
||
8 | { |
||
9 | public function __construct( |
||
10 | protected string $message, |
||
11 | protected ?string $title, |
||
12 | protected ?string $type = null, |
||
13 | protected bool $sanitize = true, |
||
14 | ) { |
||
15 | $this->type = $type ?? NotificationType::$info; |
||
16 | } |
||
17 | |||
18 | protected function asArray(): array |
||
19 | { |
||
20 | $message = $this->sanitize ? htmlspecialchars($this->message, ENT_QUOTES) : $this->message; |
||
21 | $title = $this->sanitize && $this->title ? htmlspecialchars($this->title, ENT_QUOTES) : $this->title; |
||
22 | $type = $this->type; |
||
23 | |||
24 | return compact('message', 'title', 'type'); |
||
25 | } |
||
26 | |||
27 | public function doNotSanitize(): Notification |
||
32 | } |
||
33 | |||
34 | public static function make( |
||
35 | string $message, |
||
36 | ?string $title, |
||
37 | ?string $type = null |
||
38 | ): array { |
||
39 | return (new static($message, $title, $type))->asArray(); |
||
40 | } |
||
41 | |||
42 | public function push(): void |
||
43 | { |
||
44 | session()->push(config('tall-toasts.session_keys.toasts'), $this->asArray()); |
||
45 | } |
||
46 | |||
47 | public function pushOnNextPage(): void |
||
50 | } |
||
51 | } |
||
52 |