Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathMessage.php
More file actions
Latest commit
140 lines (124 loc) · 3.33 KB
/
Copy pathMessage.php
File metadata and controls
140 lines (124 loc) · 3.33 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
namespaceTraderInteractive\Mongo;
useMongoDB\BSON\ObjectId;
useMongoDB\BSON\UTCDateTime;
finalclass Message
{
/**
* @var ObjectId
*/
private$id;
/**
* @var array
*/
private$payload;
/**
* @var UTCDateTime
*/
private$earliestGet;
/**
* @var float
*/
private$priority;
/**
* Construct a new Message instance.
*
* @param ObjectId $id The unique id of the message.
* @param array $payload The data to store in the message.
* @param UTCDateTime $earliestGet The earliest unix timestamp time which the message can be retreived.
* @param float $priority The priority for order out of get(). 0 is higher priority than 1.
*/
publicfunction__construct(
ObjectId$id = null,
array$payload = [],
UTCDateTime$earliestGet = null,
float$priority = 0.0
) {
$this->id = $id ?? newObjectId();
$this->payload = $payload;
$this->earliestGet = $earliestGet ?? newUTCDateTime();
$this->priority = $this->validatePriority($priority);
}
/**
* Gets the unique id of the message.
*
* @return ObjectId
*/
publicfunctiongetId() : ObjectId
{
return$this->id;
}
/**
* Gets the data to store in the message.
*
* @return array
*/
publicfunctiongetPayload() : array
{
return$this->payload;
}
/**
* Gets the earliest unix timestamp time which the message can be retreived.
*
* @return UTCDateTime
*/
publicfunctiongetEarliestGet() : UTCDateTime
{
return$this->earliestGet;
}
/**
* Gets the priority for order out of get(). 0 is higher priority than 1.
*
* @return float
*/
publicfunctiongetPriority() : float
{
return$this->priority;
}
/**
* Create a clone of this message with the data to store in the message.
*
* @param array $payload The data to store in the message.
*
* @return Message
*/
publicfunctionwithPayload(array$payload) : Message
{
$clone = clone$this;
$clone->payload = $payload;
return$clone;
}
/**
* Create a clone of this message with the earliest unix timestamp time which the message can be retreived.
*
* @param UTCDateTIme $earliestGet The earliest unix timestamp time which the message can be retreived.
*
* @return Message
*/
publicfunctionwithEarliestGet(UTCDateTime$earliestGet) : Message
{
$clone = clone$this;
$clone->earliestGet = $earliestGet;
return$clone;
}
/**
* Create a clone of this message with the priority for order out of get(). 0 is higher priority than 1.
*
* @param float $priority The priority for order out of get(). 0 is higher priority than 1.
*
* @return Message
*/
publicfunctionwithPriority(float$priority) : Message
{
$clone = clone$this;
$clone->priority = $this->validatePriority($priority);
return$clone;
}
privatefunctionvalidatePriority(float$priority) : float
{
if (is_nan($priority)) {
thrownew \InvalidArgumentException('$priority was NaN');
}
return$priority;
}
}