|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace PascalDeVink\CloudEvents; |
|
6
|
|
|
|
|
7
|
|
|
class CloudEvent |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @var EventType |
|
11
|
|
|
*/ |
|
12
|
|
|
private $eventType; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var CloudEventsVersion |
|
16
|
|
|
*/ |
|
17
|
|
|
private $cloudEventsVersion; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var Source |
|
21
|
|
|
*/ |
|
22
|
|
|
private $source; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var EventId |
|
26
|
|
|
*/ |
|
27
|
|
|
private $eventId; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var null|EventTime |
|
31
|
|
|
*/ |
|
32
|
|
|
private $eventTime; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var null|SchemaUrl |
|
36
|
|
|
*/ |
|
37
|
|
|
private $schemaUrl; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var null|Extensions |
|
41
|
|
|
*/ |
|
42
|
|
|
private $extensions; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var null|Data |
|
46
|
|
|
*/ |
|
47
|
|
|
private $data; |
|
48
|
|
|
|
|
49
|
18 |
|
public function __construct( |
|
50
|
|
|
EventType $eventType, |
|
51
|
|
|
CloudEventsVersion $cloudEventsVersion, |
|
52
|
|
|
Source $source, |
|
53
|
|
|
EventId $eventId, |
|
54
|
|
|
?EventTime $eventTime = null, |
|
55
|
|
|
?SchemaUrl $schemaUrl = null, |
|
56
|
|
|
?Extensions $extensions = null, |
|
57
|
|
|
?Data $data = null |
|
58
|
|
|
) { |
|
59
|
18 |
|
$this->eventType = $eventType; |
|
60
|
18 |
|
$this->cloudEventsVersion = $cloudEventsVersion; |
|
61
|
18 |
|
$this->source = $source; |
|
62
|
18 |
|
$this->eventId = $eventId; |
|
63
|
18 |
|
$this->eventTime = $eventTime; |
|
64
|
18 |
|
$this->schemaUrl = $schemaUrl; |
|
65
|
18 |
|
$this->extensions = $extensions; |
|
66
|
18 |
|
$this->data = $data; |
|
67
|
18 |
|
} |
|
68
|
|
|
|
|
69
|
3 |
|
public function getEventType() : EventType |
|
70
|
|
|
{ |
|
71
|
3 |
|
return $this->eventType; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
3 |
|
public function getCloudEventsVersion() : CloudEventsVersion |
|
75
|
|
|
{ |
|
76
|
3 |
|
return $this->cloudEventsVersion; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
3 |
|
public function getSource() : Source |
|
80
|
|
|
{ |
|
81
|
3 |
|
return $this->source; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
3 |
|
public function getEventId() : EventId |
|
85
|
|
|
{ |
|
86
|
3 |
|
return $this->eventId; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
3 |
|
public function getEventTime() : ?EventTime |
|
90
|
|
|
{ |
|
91
|
3 |
|
return $this->eventTime; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
3 |
|
public function getSchemaUrl() : ?SchemaUrl |
|
95
|
|
|
{ |
|
96
|
3 |
|
return $this->schemaUrl; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
3 |
|
public function getExtensions() : ?Extensions |
|
100
|
|
|
{ |
|
101
|
3 |
|
return $this->extensions; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
3 |
|
public function getData() : ?Data |
|
105
|
|
|
{ |
|
106
|
3 |
|
return $this->data; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
3 |
|
public function toArray() : array |
|
110
|
|
|
{ |
|
111
|
|
|
return [ |
|
112
|
3 |
|
'eventType' => $this->eventType->getValue(), |
|
113
|
3 |
|
'eventTypeVersion' => $this->eventType->getVersion(), |
|
114
|
3 |
|
'cloudEventsVersion' => (string) $this->cloudEventsVersion, |
|
115
|
3 |
|
'source' => (string) $this->source, |
|
116
|
3 |
|
'eventID' => (string) $this->eventId, |
|
117
|
3 |
|
'eventTime' => $this->data ? (string) $this->eventTime : null, |
|
118
|
3 |
|
'schemaURL' => $this->data ? (string) $this->schemaUrl : null, |
|
119
|
3 |
|
'contentType' => $this->data ? (string) $this->data->getContentType() : null, |
|
120
|
3 |
|
'extensions' => $this->extensions ? $this->extensions->getKeyValuePairs() : null, |
|
121
|
3 |
|
'data' => $this->data ? $this->data->getData() : null, |
|
122
|
|
|
]; |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|