-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabaseMessage.php
More file actions
99 lines (90 loc) · 2.02 KB
/
Copy pathDatabaseMessage.php
File metadata and controls
99 lines (90 loc) · 2.02 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
<?php
declare(strict_types=1);
namespace Crustum\Notification\Message;
/**
* Database Message
*
* Represents a notification message that will be stored in the database.
* This class serves as a data container for database notification payloads.
*
* Usage with array:
* ```
* return (new DatabaseMessage())
* ->data([
* 'title' => 'New Message',
* 'message' => 'You have a new message',
* 'action_url' => '/messages/1',
* ]);
* ```
*
* Usage with fluent API:
* ```
* return DatabaseMessage::new()
* ->title('New Message')
* ->message('You have a new message')
* ->actionurl(/sitelet?url=https%3A%2F%2Fgithub.com%2FCrustum%2FNotification%2Fblob%2Fmain%2Fsrc%2FMessage%2F%26%23039%3B%2Fmessages%2F1%26%23039%3B)
* ->icon('envelope')
* ->type('info');
* ```
*
* @phpstan-consistent-constructor
*/
class DatabaseMessage
{
use PayloadTrait;
/**
* The data that should be stored with the notification
*
* @var array<string, mixed>
*/
protected array $data = [];
/**
* Create a new database message instance
*
* @param array<string, mixed> $data Initial notification data
*/
public function __construct(array $data = [])
{
$this->data = $data;
}
/**
* Create a new database message instance
*
* @param array<string, mixed> $data Initial notification data
* @return static
* @phpstan-return static
*/
public static function new(array $data = []): static
{
return new static($data);
}
/**
* Set the data for the notification
*
* @param array<string, mixed> $data Notification data
* @return static
*/
public function data(array $data): static
{
$this->data = $data;
return $this;
}
/**
* Get the notification data
*
* @return array<string, mixed>
*/
public function getData(): array
{
return $this->data;
}
/**
* Convert message to array
*
* @return array<string, mixed>
*/
public function toArray(): array
{
return $this->data;
}
}