commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
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 $format;
94
99 protected $status;
100
101
105 public function __construct(
106 ?string $id = null,
107 ?int $version = null,
108 ?DateTimeImmutable $createdAt = null,
109 ?DateTimeImmutable $lastModifiedAt = null,
111 ?CreatedBy $createdBy = null,
114 ?string $key = null,
116 ?DeliveryFormat $format = null,
117 ?string $status = null
118 ) {
119 $this->id = $id;
120 $this->version = $version;
121 $this->createdAt = $createdAt;
122 $this->lastModifiedAt = $lastModifiedAt;
123 $this->lastModifiedBy = $lastModifiedBy;
124 $this->createdBy = $createdBy;
125 $this->changes = $changes;
126 $this->destination = $destination;
127 $this->key = $key;
128 $this->messages = $messages;
129 $this->format = $format;
130 $this->status = $status;
131 }
132
139 public function getId()
140 {
141 if (is_null($this->id)) {
143 $data = $this->raw(self::FIELD_ID);
144 if (is_null($data)) {
145 return null;
146 }
147 $this->id = (string) $data;
148 }
149
150 return $this->id;
151 }
152
159 public function getVersion()
160 {
161 if (is_null($this->version)) {
163 $data = $this->raw(self::FIELD_VERSION);
164 if (is_null($data)) {
165 return null;
166 }
167 $this->version = (int) $data;
168 }
169
170 return $this->version;
171 }
172
179 public function getCreatedAt()
180 {
181 if (is_null($this->createdAt)) {
183 $data = $this->raw(self::FIELD_CREATED_AT);
184 if (is_null($data)) {
185 return null;
186 }
187 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
188 if (false === $data) {
189 return null;
190 }
191 $this->createdAt = $data;
192 }
193
194 return $this->createdAt;
195 }
196
203 public function getLastModifiedAt()
204 {
205 if (is_null($this->lastModifiedAt)) {
207 $data = $this->raw(self::FIELD_LAST_MODIFIED_AT);
208 if (is_null($data)) {
209 return null;
210 }
211 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
212 if (false === $data) {
213 return null;
214 }
215 $this->lastModifiedAt = $data;
216 }
217
219 }
220
227 public function getLastModifiedBy()
228 {
229 if (is_null($this->lastModifiedBy)) {
231 $data = $this->raw(self::FIELD_LAST_MODIFIED_BY);
232 if (is_null($data)) {
233 return null;
234 }
235
236 $this->lastModifiedBy = LastModifiedByModel::of($data);
237 }
238
240 }
241
248 public function getCreatedBy()
249 {
250 if (is_null($this->createdBy)) {
252 $data = $this->raw(self::FIELD_CREATED_BY);
253 if (is_null($data)) {
254 return null;
255 }
256
257 $this->createdBy = CreatedByModel::of($data);
258 }
259
260 return $this->createdBy;
261 }
262
269 public function getChanges()
270 {
271 if (is_null($this->changes)) {
273 $data = $this->raw(self::FIELD_CHANGES);
274 if (is_null($data)) {
275 return null;
276 }
277 $this->changes = ChangeSubscriptionCollection::fromArray($data);
278 }
279
280 return $this->changes;
281 }
282
289 public function getDestination()
290 {
291 if (is_null($this->destination)) {
293 $data = $this->raw(self::FIELD_DESTINATION);
294 if (is_null($data)) {
295 return null;
296 }
298 $this->destination = $className::of($data);
299 }
300
301 return $this->destination;
302 }
303
310 public function getKey()
311 {
312 if (is_null($this->key)) {
314 $data = $this->raw(self::FIELD_KEY);
315 if (is_null($data)) {
316 return null;
317 }
318 $this->key = (string) $data;
319 }
320
321 return $this->key;
322 }
323
330 public function getMessages()
331 {
332 if (is_null($this->messages)) {
334 $data = $this->raw(self::FIELD_MESSAGES);
335 if (is_null($data)) {
336 return null;
337 }
338 $this->messages = MessageSubscriptionCollection::fromArray($data);
339 }
340
341 return $this->messages;
342 }
343
350 public function getFormat()
351 {
352 if (is_null($this->format)) {
354 $data = $this->raw(self::FIELD_FORMAT);
355 if (is_null($data)) {
356 return null;
357 }
359 $this->format = $className::of($data);
360 }
361
362 return $this->format;
363 }
364
371 public function getStatus()
372 {
373 if (is_null($this->status)) {
375 $data = $this->raw(self::FIELD_STATUS);
376 if (is_null($data)) {
377 return null;
378 }
379 $this->status = (string) $data;
380 }
381
382 return $this->status;
383 }
384
385
389 public function setId(?string $id): void
390 {
391 $this->id = $id;
392 }
393
397 public function setVersion(?int $version): void
398 {
399 $this->version = $version;
400 }
401
405 public function setCreatedAt(?DateTimeImmutable $createdAt): void
406 {
407 $this->createdAt = $createdAt;
408 }
409
413 public function setLastModifiedAt(?DateTimeImmutable $lastModifiedAt): void
414 {
415 $this->lastModifiedAt = $lastModifiedAt;
416 }
417
422 {
423 $this->lastModifiedBy = $lastModifiedBy;
424 }
425
429 public function setCreatedBy(?CreatedBy $createdBy): void
430 {
431 $this->createdBy = $createdBy;
432 }
433
438 {
439 $this->changes = $changes;
440 }
441
446 {
447 $this->destination = $destination;
448 }
449
453 public function setKey(?string $key): void
454 {
455 $this->key = $key;
456 }
457
462 {
463 $this->messages = $messages;
464 }
465
469 public function setFormat(?DeliveryFormat $format): void
470 {
471 $this->format = $format;
472 }
473
477 public function setStatus(?string $status): void
478 {
479 $this->status = $status;
480 }
481
482
483 #[\ReturnTypeWillChange]
484 public function jsonSerialize()
485 {
486 $data = $this->toArray();
487 if (isset($data[Subscription::FIELD_CREATED_AT]) && $data[Subscription::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
488 $data[Subscription::FIELD_CREATED_AT] = $data[Subscription::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
489 }
490
491 if (isset($data[Subscription::FIELD_LAST_MODIFIED_AT]) && $data[Subscription::FIELD_LAST_MODIFIED_AT] instanceof \DateTimeImmutable) {
492 $data[Subscription::FIELD_LAST_MODIFIED_AT] = $data[Subscription::FIELD_LAST_MODIFIED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
493 }
494 return (object) $data;
495 }
496}
setChanges(?ChangeSubscriptionCollection $changes)
__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, ?DeliveryFormat $format=null, ?string $status=null)
setMessages(?MessageSubscriptionCollection $messages)
static fromArray(array $data)