commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
StateModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
23 use DateTimeImmutable;
24 use stdClass;
25 
29 final class StateModel extends JsonObjectModel implements State
30 {
35  protected $id;
36 
41  protected $version;
42 
47  protected $createdAt;
48 
53  protected $lastModifiedAt;
54 
59  protected $lastModifiedBy;
60 
65  protected $createdBy;
66 
71  protected $key;
72 
77  protected $type;
78 
83  protected $name;
84 
89  protected $description;
90 
95  protected $initial;
96 
101  protected $builtIn;
102 
107  protected $roles;
108 
113  protected $transitions;
114 
115 
119  public function __construct(
120  ?string $id = null,
121  ?int $version = null,
122  ?DateTimeImmutable $createdAt = null,
123  ?DateTimeImmutable $lastModifiedAt = null,
125  ?CreatedBy $createdBy = null,
126  ?string $key = null,
127  ?string $type = null,
128  ?LocalizedString $name = null,
130  ?bool $initial = null,
131  ?bool $builtIn = null,
132  ?array $roles = null,
134  ) {
135  $this->id = $id;
136  $this->version = $version;
137  $this->createdAt = $createdAt;
138  $this->lastModifiedAt = $lastModifiedAt;
139  $this->lastModifiedBy = $lastModifiedBy;
140  $this->createdBy = $createdBy;
141  $this->key = $key;
142  $this->type = $type;
143  $this->name = $name;
144  $this->description = $description;
145  $this->initial = $initial;
146  $this->builtIn = $builtIn;
147  $this->roles = $roles;
148  $this->transitions = $transitions;
149  }
150 
157  public function getId()
158  {
159  if (is_null($this->id)) {
161  $data = $this->raw(self::FIELD_ID);
162  if (is_null($data)) {
163  return null;
164  }
165  $this->id = (string) $data;
166  }
167 
168  return $this->id;
169  }
170 
177  public function getVersion()
178  {
179  if (is_null($this->version)) {
181  $data = $this->raw(self::FIELD_VERSION);
182  if (is_null($data)) {
183  return null;
184  }
185  $this->version = (int) $data;
186  }
187 
188  return $this->version;
189  }
190 
197  public function getCreatedAt()
198  {
199  if (is_null($this->createdAt)) {
201  $data = $this->raw(self::FIELD_CREATED_AT);
202  if (is_null($data)) {
203  return null;
204  }
205  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
206  if (false === $data) {
207  return null;
208  }
209  $this->createdAt = $data;
210  }
211 
212  return $this->createdAt;
213  }
214 
221  public function getLastModifiedAt()
222  {
223  if (is_null($this->lastModifiedAt)) {
225  $data = $this->raw(self::FIELD_LAST_MODIFIED_AT);
226  if (is_null($data)) {
227  return null;
228  }
229  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
230  if (false === $data) {
231  return null;
232  }
233  $this->lastModifiedAt = $data;
234  }
235 
236  return $this->lastModifiedAt;
237  }
238 
245  public function getLastModifiedBy()
246  {
247  if (is_null($this->lastModifiedBy)) {
249  $data = $this->raw(self::FIELD_LAST_MODIFIED_BY);
250  if (is_null($data)) {
251  return null;
252  }
253 
254  $this->lastModifiedBy = LastModifiedByModel::of($data);
255  }
256 
257  return $this->lastModifiedBy;
258  }
259 
266  public function getCreatedBy()
267  {
268  if (is_null($this->createdBy)) {
270  $data = $this->raw(self::FIELD_CREATED_BY);
271  if (is_null($data)) {
272  return null;
273  }
274 
275  $this->createdBy = CreatedByModel::of($data);
276  }
277 
278  return $this->createdBy;
279  }
280 
287  public function getKey()
288  {
289  if (is_null($this->key)) {
291  $data = $this->raw(self::FIELD_KEY);
292  if (is_null($data)) {
293  return null;
294  }
295  $this->key = (string) $data;
296  }
297 
298  return $this->key;
299  }
300 
307  public function getType()
308  {
309  if (is_null($this->type)) {
311  $data = $this->raw(self::FIELD_TYPE);
312  if (is_null($data)) {
313  return null;
314  }
315  $this->type = (string) $data;
316  }
317 
318  return $this->type;
319  }
320 
327  public function getName()
328  {
329  if (is_null($this->name)) {
331  $data = $this->raw(self::FIELD_NAME);
332  if (is_null($data)) {
333  return null;
334  }
335 
336  $this->name = LocalizedStringModel::of($data);
337  }
338 
339  return $this->name;
340  }
341 
348  public function getDescription()
349  {
350  if (is_null($this->description)) {
352  $data = $this->raw(self::FIELD_DESCRIPTION);
353  if (is_null($data)) {
354  return null;
355  }
356 
357  $this->description = LocalizedStringModel::of($data);
358  }
359 
360  return $this->description;
361  }
362 
369  public function getInitial()
370  {
371  if (is_null($this->initial)) {
373  $data = $this->raw(self::FIELD_INITIAL);
374  if (is_null($data)) {
375  return null;
376  }
377  $this->initial = (bool) $data;
378  }
379 
380  return $this->initial;
381  }
382 
389  public function getBuiltIn()
390  {
391  if (is_null($this->builtIn)) {
393  $data = $this->raw(self::FIELD_BUILT_IN);
394  if (is_null($data)) {
395  return null;
396  }
397  $this->builtIn = (bool) $data;
398  }
399 
400  return $this->builtIn;
401  }
402 
409  public function getRoles()
410  {
411  if (is_null($this->roles)) {
413  $data = $this->raw(self::FIELD_ROLES);
414  if (is_null($data)) {
415  return null;
416  }
417  $this->roles = $data;
418  }
419 
420  return $this->roles;
421  }
422 
433  public function getTransitions()
434  {
435  if (is_null($this->transitions)) {
437  $data = $this->raw(self::FIELD_TRANSITIONS);
438  if (is_null($data)) {
439  return null;
440  }
441  $this->transitions = StateReferenceCollection::fromArray($data);
442  }
443 
444  return $this->transitions;
445  }
446 
447 
451  public function setId(?string $id): void
452  {
453  $this->id = $id;
454  }
455 
459  public function setVersion(?int $version): void
460  {
461  $this->version = $version;
462  }
463 
467  public function setCreatedAt(?DateTimeImmutable $createdAt): void
468  {
469  $this->createdAt = $createdAt;
470  }
471 
475  public function setLastModifiedAt(?DateTimeImmutable $lastModifiedAt): void
476  {
477  $this->lastModifiedAt = $lastModifiedAt;
478  }
479 
484  {
485  $this->lastModifiedBy = $lastModifiedBy;
486  }
487 
491  public function setCreatedBy(?CreatedBy $createdBy): void
492  {
493  $this->createdBy = $createdBy;
494  }
495 
499  public function setKey(?string $key): void
500  {
501  $this->key = $key;
502  }
503 
507  public function setType(?string $type): void
508  {
509  $this->type = $type;
510  }
511 
515  public function setName(?LocalizedString $name): void
516  {
517  $this->name = $name;
518  }
519 
524  {
525  $this->description = $description;
526  }
527 
531  public function setInitial(?bool $initial): void
532  {
533  $this->initial = $initial;
534  }
535 
539  public function setBuiltIn(?bool $builtIn): void
540  {
541  $this->builtIn = $builtIn;
542  }
543 
547  public function setRoles(?array $roles): void
548  {
549  $this->roles = $roles;
550  }
551 
556  {
557  $this->transitions = $transitions;
558  }
559 
560 
561  #[\ReturnTypeWillChange]
562  public function jsonSerialize()
563  {
564  $data = $this->toArray();
565  if (isset($data[State::FIELD_CREATED_AT]) && $data[State::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
566  $data[State::FIELD_CREATED_AT] = $data[State::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
567  }
568 
569  if (isset($data[State::FIELD_LAST_MODIFIED_AT]) && $data[State::FIELD_LAST_MODIFIED_AT] instanceof \DateTimeImmutable) {
570  $data[State::FIELD_LAST_MODIFIED_AT] = $data[State::FIELD_LAST_MODIFIED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
571  }
572  return (object) $data;
573  }
574 }
setDescription(?LocalizedString $description)
Definition: StateModel.php:523
__construct(?string $id=null, ?int $version=null, ?DateTimeImmutable $createdAt=null, ?DateTimeImmutable $lastModifiedAt=null, ?LastModifiedBy $lastModifiedBy=null, ?CreatedBy $createdBy=null, ?string $key=null, ?string $type=null, ?LocalizedString $name=null, ?LocalizedString $description=null, ?bool $initial=null, ?bool $builtIn=null, ?array $roles=null, ?StateReferenceCollection $transitions=null)
Definition: StateModel.php:119
setLastModifiedBy(?LastModifiedBy $lastModifiedBy)
Definition: StateModel.php:483
setCreatedAt(?DateTimeImmutable $createdAt)
Definition: StateModel.php:467
setTransitions(?StateReferenceCollection $transitions)
Definition: StateModel.php:555
setLastModifiedAt(?DateTimeImmutable $lastModifiedAt)
Definition: StateModel.php:475
static of($data=null)
Definition: MapperMap.php:45