@@ -96,6 +96,21 @@ class CloudEvent
9696 */
9797 public $ data ;
9898
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+
99114 public function __construct ()
100115 {
101116 }
@@ -116,6 +131,9 @@ public static function parse(string $json): CloudEvent
116131 $ event ->type = (string )$ raw ['type ' ];
117132 $ event ->data_content_type = $ raw ['datacontenttype ' ] ?? null ;
118133 $ 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 ;
119137 $ time = $ raw ['time ' ] ?? null ;
120138 if ( ! empty ($ time )) {
121139 $ event ->time = new \DateTime ($ time );
@@ -131,6 +149,7 @@ public static function parse(string $json): CloudEvent
131149 public function to_json (): string |bool
132150 {
133151 Runtime::$ logger ?->debug('Serializing cloud event ' );
152+
134153 return json_encode ($ this ->to_array ());
135154 }
136155
@@ -158,6 +177,9 @@ public function to_array(): array
158177 if (isset ($ this ->data )) {
159178 $ json ['data ' ] = $ this ->data ;
160179 }
180+ if (isset ($ this ->trace_id )) {
181+ $ json ['traceid ' ] = $ this ->trace_id ;
182+ }
161183
162184 return $ json ;
163185 }
@@ -184,11 +206,9 @@ public function validate(): bool
184206 return false ;
185207 }
186208
187- // for non-custom events, the subject is an empty string
188- /*
189209 if (isset ($ this ->subject ) && empty ($ this ->subject )) {
190210 return false ;
191- }*/
211+ }
192212
193213 return true ;
194214 }
0 commit comments