commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
CloudEventsPayloadModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
15 use DateTimeImmutable;
16 use stdClass;
17 
22 {
23  public const DISCRIMINATOR_VALUE = 'CloudEvents';
28  protected $specversion;
29 
34  protected $id;
35 
40  protected $type;
41 
46  protected $source;
47 
52  protected $subject;
53 
58  protected $time;
59 
64  protected $sequence;
65 
70  protected $sequencetype;
71 
76  protected $dataref;
77 
82  protected $data;
83 
84 
88  public function __construct(
89  ?string $specversion = null,
90  ?string $id = null,
91  ?string $type = null,
92  ?string $source = null,
93  ?string $subject = null,
94  ?DateTimeImmutable $time = null,
95  ?string $sequence = null,
96  ?string $sequencetype = null,
97  ?string $dataref = null,
98  ?DeliveryPayload $data = null
99  ) {
100  $this->specversion = $specversion;
101  $this->id = $id;
102  $this->type = $type;
103  $this->source = $source;
104  $this->subject = $subject;
105  $this->time = $time;
106  $this->sequence = $sequence;
107  $this->sequencetype = $sequencetype;
108  $this->dataref = $dataref;
109  $this->data = $data;
110  }
111 
118  public function getSpecversion()
119  {
120  if (is_null($this->specversion)) {
122  $data = $this->raw(self::FIELD_SPECVERSION);
123  if (is_null($data)) {
124  return null;
125  }
126  $this->specversion = (string) $data;
127  }
128 
129  return $this->specversion;
130  }
131 
138  public function getId()
139  {
140  if (is_null($this->id)) {
142  $data = $this->raw(self::FIELD_ID);
143  if (is_null($data)) {
144  return null;
145  }
146  $this->id = (string) $data;
147  }
148 
149  return $this->id;
150  }
151 
159  public function getType()
160  {
161  if (is_null($this->type)) {
163  $data = $this->raw(self::FIELD_TYPE);
164  if (is_null($data)) {
165  return null;
166  }
167  $this->type = (string) $data;
168  }
169 
170  return $this->type;
171  }
172 
179  public function getSource()
180  {
181  if (is_null($this->source)) {
183  $data = $this->raw(self::FIELD_SOURCE);
184  if (is_null($data)) {
185  return null;
186  }
187  $this->source = (string) $data;
188  }
189 
190  return $this->source;
191  }
192 
199  public function getSubject()
200  {
201  if (is_null($this->subject)) {
203  $data = $this->raw(self::FIELD_SUBJECT);
204  if (is_null($data)) {
205  return null;
206  }
207  $this->subject = (string) $data;
208  }
209 
210  return $this->subject;
211  }
212 
219  public function getTime()
220  {
221  if (is_null($this->time)) {
223  $data = $this->raw(self::FIELD_TIME);
224  if (is_null($data)) {
225  return null;
226  }
227  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
228  if (false === $data) {
229  return null;
230  }
231  $this->time = $data;
232  }
233 
234  return $this->time;
235  }
236 
243  public function getSequence()
244  {
245  if (is_null($this->sequence)) {
247  $data = $this->raw(self::FIELD_SEQUENCE);
248  if (is_null($data)) {
249  return null;
250  }
251  $this->sequence = (string) $data;
252  }
253 
254  return $this->sequence;
255  }
256 
263  public function getSequencetype()
264  {
265  if (is_null($this->sequencetype)) {
267  $data = $this->raw(self::FIELD_SEQUENCETYPE);
268  if (is_null($data)) {
269  return null;
270  }
271  $this->sequencetype = (string) $data;
272  }
273 
274  return $this->sequencetype;
275  }
276 
283  public function getDataref()
284  {
285  if (is_null($this->dataref)) {
287  $data = $this->raw(self::FIELD_DATAREF);
288  if (is_null($data)) {
289  return null;
290  }
291  $this->dataref = (string) $data;
292  }
293 
294  return $this->dataref;
295  }
296 
303  public function getData()
304  {
305  if (is_null($this->data)) {
307  $data = $this->raw(self::FIELD_DATA);
308  if (is_null($data)) {
309  return null;
310  }
312  $this->data = $className::of($data);
313  }
314 
315  return $this->data;
316  }
317 
318 
322  public function setSpecversion(?string $specversion): void
323  {
324  $this->specversion = $specversion;
325  }
326 
330  public function setId(?string $id): void
331  {
332  $this->id = $id;
333  }
334 
338  public function setType(?string $type): void
339  {
340  $this->type = $type;
341  }
342 
346  public function setSource(?string $source): void
347  {
348  $this->source = $source;
349  }
350 
354  public function setSubject(?string $subject): void
355  {
356  $this->subject = $subject;
357  }
358 
362  public function setTime(?DateTimeImmutable $time): void
363  {
364  $this->time = $time;
365  }
366 
370  public function setSequence(?string $sequence): void
371  {
372  $this->sequence = $sequence;
373  }
374 
378  public function setSequencetype(?string $sequencetype): void
379  {
380  $this->sequencetype = $sequencetype;
381  }
382 
386  public function setDataref(?string $dataref): void
387  {
388  $this->dataref = $dataref;
389  }
390 
394  public function setData(?DeliveryPayload $data): void
395  {
396  $this->data = $data;
397  }
398 
399 
400  #[\ReturnTypeWillChange]
401  public function jsonSerialize()
402  {
403  $data = $this->toArray();
404  if (isset($data[CloudEventsPayload::FIELD_TIME]) && $data[CloudEventsPayload::FIELD_TIME] instanceof \DateTimeImmutable) {
405  $data[CloudEventsPayload::FIELD_TIME] = $data[CloudEventsPayload::FIELD_TIME]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
406  }
407  return (object) $data;
408  }
409 }
__construct(?string $specversion=null, ?string $id=null, ?string $type=null, ?string $source=null, ?string $subject=null, ?DateTimeImmutable $time=null, ?string $sequence=null, ?string $sequencetype=null, ?string $dataref=null, ?DeliveryPayload $data=null)