@@ -96,6 +96,21 @@ class CloudEvent
96
96
*/
97
97
public $ data ;
98
98
99
+ /**
100
+ * @var string|null The trace id
101
+ */
102
+ public ?string $ trace_id ;
103
+
104
+ /**
105
+ * @var string|null The topic
106
+ */
107
+ public ?string $ topic ;
108
+
109
+ /**
110
+ * @var string|null The name of the pubsub
111
+ */
112
+ public ?string $ pubsub_name ;
113
+
99
114
public function __construct ()
100
115
{
101
116
}
@@ -116,6 +131,9 @@ public static function parse(string $json): CloudEvent
116
131
$ event ->type = (string )$ raw ['type ' ];
117
132
$ event ->data_content_type = $ raw ['datacontenttype ' ] ?? null ;
118
133
$ event ->subject = $ raw ['subject ' ] ?? null ;
134
+ $ event ->pubsub_name = $ raw ['pubsubname ' ] ?? null ;
135
+ $ event ->topic = $ raw ['topic ' ] ?? null ;
136
+ $ event ->trace_id = $ raw ['traceid ' ] ?? null ;
119
137
$ time = $ raw ['time ' ] ?? null ;
120
138
if ( ! empty ($ time )) {
121
139
$ event ->time = new \DateTime ($ time );
@@ -131,6 +149,7 @@ public static function parse(string $json): CloudEvent
131
149
public function to_json (): string |bool
132
150
{
133
151
Runtime::$ logger ?->debug('Serializing cloud event ' );
152
+
134
153
return json_encode ($ this ->to_array ());
135
154
}
136
155
@@ -158,6 +177,9 @@ public function to_array(): array
158
177
if (isset ($ this ->data )) {
159
178
$ json ['data ' ] = $ this ->data ;
160
179
}
180
+ if (isset ($ this ->trace_id )) {
181
+ $ json ['traceid ' ] = $ this ->trace_id ;
182
+ }
161
183
162
184
return $ json ;
163
185
}
@@ -184,11 +206,9 @@ public function validate(): bool
184
206
return false ;
185
207
}
186
208
187
- // for non-custom events, the subject is an empty string
188
- /*
189
209
if (isset ($ this ->subject ) && empty ($ this ->subject )) {
190
210
return false ;
191
- }*/
211
+ }
192
212
193
213
return true ;
194
214
}
0 commit comments