commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
ExtensionModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
21 use DateTimeImmutable;
22 use stdClass;
23 
27 final class ExtensionModel extends JsonObjectModel implements Extension
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 $key;
70 
75  protected $destination;
76 
81  protected $triggers;
82 
87  protected $timeoutInMs;
88 
89 
93  public function __construct(
94  ?string $id = null,
95  ?int $version = null,
96  ?DateTimeImmutable $createdAt = null,
97  ?DateTimeImmutable $lastModifiedAt = null,
99  ?CreatedBy $createdBy = null,
100  ?string $key = null,
103  ?int $timeoutInMs = null
104  ) {
105  $this->id = $id;
106  $this->version = $version;
107  $this->createdAt = $createdAt;
108  $this->lastModifiedAt = $lastModifiedAt;
109  $this->lastModifiedBy = $lastModifiedBy;
110  $this->createdBy = $createdBy;
111  $this->key = $key;
112  $this->destination = $destination;
113  $this->triggers = $triggers;
114  $this->timeoutInMs = $timeoutInMs;
115  }
116 
123  public function getId()
124  {
125  if (is_null($this->id)) {
127  $data = $this->raw(self::FIELD_ID);
128  if (is_null($data)) {
129  return null;
130  }
131  $this->id = (string) $data;
132  }
133 
134  return $this->id;
135  }
136 
143  public function getVersion()
144  {
145  if (is_null($this->version)) {
147  $data = $this->raw(self::FIELD_VERSION);
148  if (is_null($data)) {
149  return null;
150  }
151  $this->version = (int) $data;
152  }
153 
154  return $this->version;
155  }
156 
163  public function getCreatedAt()
164  {
165  if (is_null($this->createdAt)) {
167  $data = $this->raw(self::FIELD_CREATED_AT);
168  if (is_null($data)) {
169  return null;
170  }
171  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
172  if (false === $data) {
173  return null;
174  }
175  $this->createdAt = $data;
176  }
177 
178  return $this->createdAt;
179  }
180 
187  public function getLastModifiedAt()
188  {
189  if (is_null($this->lastModifiedAt)) {
191  $data = $this->raw(self::FIELD_LAST_MODIFIED_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->lastModifiedAt = $data;
200  }
201 
202  return $this->lastModifiedAt;
203  }
204 
211  public function getLastModifiedBy()
212  {
213  if (is_null($this->lastModifiedBy)) {
215  $data = $this->raw(self::FIELD_LAST_MODIFIED_BY);
216  if (is_null($data)) {
217  return null;
218  }
219 
220  $this->lastModifiedBy = LastModifiedByModel::of($data);
221  }
222 
223  return $this->lastModifiedBy;
224  }
225 
232  public function getCreatedBy()
233  {
234  if (is_null($this->createdBy)) {
236  $data = $this->raw(self::FIELD_CREATED_BY);
237  if (is_null($data)) {
238  return null;
239  }
240 
241  $this->createdBy = CreatedByModel::of($data);
242  }
243 
244  return $this->createdBy;
245  }
246 
253  public function getKey()
254  {
255  if (is_null($this->key)) {
257  $data = $this->raw(self::FIELD_KEY);
258  if (is_null($data)) {
259  return null;
260  }
261  $this->key = (string) $data;
262  }
263 
264  return $this->key;
265  }
266 
273  public function getDestination()
274  {
275  if (is_null($this->destination)) {
277  $data = $this->raw(self::FIELD_DESTINATION);
278  if (is_null($data)) {
279  return null;
280  }
282  $this->destination = $className::of($data);
283  }
284 
285  return $this->destination;
286  }
287 
294  public function getTriggers()
295  {
296  if (is_null($this->triggers)) {
298  $data = $this->raw(self::FIELD_TRIGGERS);
299  if (is_null($data)) {
300  return null;
301  }
302  $this->triggers = ExtensionTriggerCollection::fromArray($data);
303  }
304 
305  return $this->triggers;
306  }
307 
316  public function getTimeoutInMs()
317  {
318  if (is_null($this->timeoutInMs)) {
320  $data = $this->raw(self::FIELD_TIMEOUT_IN_MS);
321  if (is_null($data)) {
322  return null;
323  }
324  $this->timeoutInMs = (int) $data;
325  }
326 
327  return $this->timeoutInMs;
328  }
329 
330 
334  public function setId(?string $id): void
335  {
336  $this->id = $id;
337  }
338 
342  public function setVersion(?int $version): void
343  {
344  $this->version = $version;
345  }
346 
350  public function setCreatedAt(?DateTimeImmutable $createdAt): void
351  {
352  $this->createdAt = $createdAt;
353  }
354 
358  public function setLastModifiedAt(?DateTimeImmutable $lastModifiedAt): void
359  {
360  $this->lastModifiedAt = $lastModifiedAt;
361  }
362 
367  {
368  $this->lastModifiedBy = $lastModifiedBy;
369  }
370 
374  public function setCreatedBy(?CreatedBy $createdBy): void
375  {
376  $this->createdBy = $createdBy;
377  }
378 
382  public function setKey(?string $key): void
383  {
384  $this->key = $key;
385  }
386 
391  {
392  $this->destination = $destination;
393  }
394 
399  {
400  $this->triggers = $triggers;
401  }
402 
406  public function setTimeoutInMs(?int $timeoutInMs): void
407  {
408  $this->timeoutInMs = $timeoutInMs;
409  }
410 
411 
412  #[\ReturnTypeWillChange]
413  public function jsonSerialize()
414  {
415  $data = $this->toArray();
416  if (isset($data[Extension::FIELD_CREATED_AT]) && $data[Extension::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
417  $data[Extension::FIELD_CREATED_AT] = $data[Extension::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
418  }
419 
420  if (isset($data[Extension::FIELD_LAST_MODIFIED_AT]) && $data[Extension::FIELD_LAST_MODIFIED_AT] instanceof \DateTimeImmutable) {
421  $data[Extension::FIELD_LAST_MODIFIED_AT] = $data[Extension::FIELD_LAST_MODIFIED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
422  }
423  return (object) $data;
424  }
425 }
setTriggers(?ExtensionTriggerCollection $triggers)
setDestination(?ExtensionDestination $destination)
setLastModifiedBy(?LastModifiedBy $lastModifiedBy)
__construct(?string $id=null, ?int $version=null, ?DateTimeImmutable $createdAt=null, ?DateTimeImmutable $lastModifiedAt=null, ?LastModifiedBy $lastModifiedBy=null, ?CreatedBy $createdBy=null, ?string $key=null, ?ExtensionDestination $destination=null, ?ExtensionTriggerCollection $triggers=null, ?int $timeoutInMs=null)
setLastModifiedAt(?DateTimeImmutable $lastModifiedAt)