commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
All Classes Namespaces Functions Variables Pages
SubscriptionModel.php
1<?php
2
3declare(strict_types=1);
10
21use DateTimeImmutable;
22use stdClass;
23
27final class SubscriptionModel extends JsonObjectModel implements Subscription
28{
33 protected $id;
34
39 protected $version;
40
45 protected $createdAt;
46
51 protected $lastModifiedAt;
52
57 protected $lastModifiedBy;
58
63 protected $createdBy;
64
69 protected $changes;
70
75 protected $destination;
76
81 protected $key;
82
87 protected $messages;
88
93 protected $events;
94
99 protected $format;
100
105 protected $status;
106
107
111 public function __construct(
112 ?string $id = null,
113 ?int $version = null,
114 ?DateTimeImmutable $createdAt = null,
115 ?DateTimeImmutable $lastModifiedAt = null,
117 ?CreatedBy $createdBy = null,
120 ?string $key = null,
123 ?DeliveryFormat $format = null,
124 ?string $status = null
125 ) {
126 $this->id = $id;
127 $this->version = $version;
128 $this->createdAt = $createdAt;
129 $this->lastModifiedAt = $lastModifiedAt;
130 $this->lastModifiedBy = $lastModifiedBy;
131 $this->createdBy = $createdBy;
132 $this->changes = $changes;
133 $this->destination = $destination;
134 $this->key = $key;
135 $this->messages = $messages;
136 $this->events = $events;
137 $this->format = $format;
138 $this->status = $status;
139 }
140
147 public function getId()
148 {
149 if (is_null($this->id)) {
151 $data = $this->raw(self::FIELD_ID);
152 if (is_null($data)) {
153 return null;
154 }
155 $this->id = (string) $data;
156 }
157
158 return $this->id;
159 }
160
167 public function getVersion()
168 {
169 if (is_null($this->version)) {
171 $data = $this->raw(self::FIELD_VERSION);
172 if (is_null($data)) {
173 return null;
174 }
175 $this->version = (int) $data;
176 }
177
178 return $this->version;
179 }
180
187 public function getCreatedAt()
188 {
189 if (is_null($this->createdAt)) {
191 $data = $this->raw(self::FIELD_CREATED_AT);
192 if (is_null($data)) {
193 return null;
194 }
195 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
196 if (false === $data) {
197 return null;
198 }
199 $this->createdAt = $data;
200 }
201
202 return $this->createdAt;
203 }
204
211 public function getLastModifiedAt()
212 {
213 if (is_null($this->lastModifiedAt)) {
215 $data = $this->raw(self::FIELD_LAST_MODIFIED_AT);
216 if (is_null($data)) {
217 return null;
218 }
219 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
220 if (false === $data) {
221 return null;
222 }
223 $this->lastModifiedAt = $data;
224 }
225
227 }
228
235 public function getLastModifiedBy()
236 {
237 if (is_null($this->lastModifiedBy)) {
239 $data = $this->raw(self::FIELD_LAST_MODIFIED_BY);
240 if (is_null($data)) {
241 return null;
242 }
243
244 $this->lastModifiedBy = LastModifiedByModel::of($data);
245 }
246
248 }
249
256 public function getCreatedBy()
257 {
258 if (is_null($this->createdBy)) {
260 $data = $this->raw(self::FIELD_CREATED_BY);
261 if (is_null($data)) {
262 return null;
263 }
264
265 $this->createdBy = CreatedByModel::of($data);
266 }
267
268 return $this->createdBy;
269 }
270
277 public function getChanges()
278 {
279 if (is_null($this->changes)) {
281 $data = $this->raw(self::FIELD_CHANGES);
282 if (is_null($data)) {
283 return null;
284 }
285 $this->changes = ChangeSubscriptionCollection::fromArray($data);
286 }
287
288 return $this->changes;
289 }
290
297 public function getDestination()
298 {
299 if (is_null($this->destination)) {
301 $data = $this->raw(self::FIELD_DESTINATION);
302 if (is_null($data)) {
303 return null;
304 }
306 $this->destination = $className::of($data);
307 }
308
309 return $this->destination;
310 }
311
318 public function getKey()
319 {
320 if (is_null($this->key)) {
322 $data = $this->raw(self::FIELD_KEY);
323 if (is_null($data)) {
324 return null;
325 }
326 $this->key = (string) $data;
327 }
328
329 return $this->key;
330 }
331
338 public function getMessages()
339 {
340 if (is_null($this->messages)) {
342 $data = $this->raw(self::FIELD_MESSAGES);
343 if (is_null($data)) {
344 return null;
345 }
346 $this->messages = MessageSubscriptionCollection::fromArray($data);
347 }
348
349 return $this->messages;
350 }
351
358 public function getEvents()
359 {
360 if (is_null($this->events)) {
362 $data = $this->raw(self::FIELD_EVENTS);
363 if (is_null($data)) {
364 return null;
365 }
366 $this->events = EventSubscriptionCollection::fromArray($data);
367 }
368
369 return $this->events;
370 }
371
378 public function getFormat()
379 {
380 if (is_null($this->format)) {
382 $data = $this->raw(self::FIELD_FORMAT);
383 if (is_null($data)) {
384 return null;
385 }
387 $this->format = $className::of($data);
388 }
389
390 return $this->format;
391 }
392
399 public function getStatus()
400 {
401 if (is_null($this->status)) {
403 $data = $this->raw(self::FIELD_STATUS);
404 if (is_null($data)) {
405 return null;
406 }
407 $this->status = (string) $data;
408 }
409
410 return $this->status;
411 }
412
413
417 public function setId(?string $id): void
418 {
419 $this->id = $id;
420 }
421
425 public function setVersion(?int $version): void
426 {
427 $this->version = $version;
428 }
429
433 public function setCreatedAt(?DateTimeImmutable $createdAt): void
434 {
435 $this->createdAt = $createdAt;
436 }
437
441 public function setLastModifiedAt(?DateTimeImmutable $lastModifiedAt): void
442 {
443 $this->lastModifiedAt = $lastModifiedAt;
444 }
445
450 {
451 $this->lastModifiedBy = $lastModifiedBy;
452 }
453
457 public function setCreatedBy(?CreatedBy $createdBy): void
458 {
459 $this->createdBy = $createdBy;
460 }
461
466 {
467 $this->changes = $changes;
468 }
469
474 {
475 $this->destination = $destination;
476 }
477
481 public function setKey(?string $key): void
482 {
483 $this->key = $key;
484 }
485
490 {
491 $this->messages = $messages;
492 }
493
498 {
499 $this->events = $events;
500 }
501
505 public function setFormat(?DeliveryFormat $format): void
506 {
507 $this->format = $format;
508 }
509
513 public function setStatus(?string $status): void
514 {
515 $this->status = $status;
516 }
517
518
519 #[\ReturnTypeWillChange]
520 public function jsonSerialize()
521 {
522 $data = $this->toArray();
523 if (isset($data[Subscription::FIELD_CREATED_AT]) && $data[Subscription::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
524 $data[Subscription::FIELD_CREATED_AT] = $data[Subscription::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
525 }
526
527 if (isset($data[Subscription::FIELD_LAST_MODIFIED_AT]) && $data[Subscription::FIELD_LAST_MODIFIED_AT] instanceof \DateTimeImmutable) {
528 $data[Subscription::FIELD_LAST_MODIFIED_AT] = $data[Subscription::FIELD_LAST_MODIFIED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
529 }
530 return (object) $data;
531 }
532}
setChanges(?ChangeSubscriptionCollection $changes)
setMessages(?MessageSubscriptionCollection $messages)
__construct(?string $id=null, ?int $version=null, ?DateTimeImmutable $createdAt=null, ?DateTimeImmutable $lastModifiedAt=null, ?LastModifiedBy $lastModifiedBy=null, ?CreatedBy $createdBy=null, ?ChangeSubscriptionCollection $changes=null, ?Destination $destination=null, ?string $key=null, ?MessageSubscriptionCollection $messages=null, ?EventSubscriptionCollection $events=null, ?DeliveryFormat $format=null, ?string $status=null)
static fromArray(array $data)