commercetools-sdk-php-v2  master
The platform, import-api and ml-api PHP sdks generated from our api reference.
SyncInfoModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
17 use DateTimeImmutable;
18 use stdClass;
19 
23 final class SyncInfoModel extends JsonObjectModel implements SyncInfo
24 {
29  protected $channel;
30 
35  protected $externalId;
36 
41  protected $syncedAt;
42 
43 
47  public function __construct(
49  ?string $externalId = null,
50  ?DateTimeImmutable $syncedAt = null
51  ) {
52  $this->channel = $channel;
53  $this->externalId = $externalId;
54  $this->syncedAt = $syncedAt;
55  }
56 
63  public function getChannel()
64  {
65  if (is_null($this->channel)) {
67  $data = $this->raw(self::FIELD_CHANNEL);
68  if (is_null($data)) {
69  return null;
70  }
71 
72  $this->channel = ChannelKeyReferenceModel::of($data);
73  }
74 
75  return $this->channel;
76  }
77 
84  public function getExternalId()
85  {
86  if (is_null($this->externalId)) {
88  $data = $this->raw(self::FIELD_EXTERNAL_ID);
89  if (is_null($data)) {
90  return null;
91  }
92  $this->externalId = (string) $data;
93  }
94 
95  return $this->externalId;
96  }
97 
104  public function getSyncedAt()
105  {
106  if (is_null($this->syncedAt)) {
108  $data = $this->raw(self::FIELD_SYNCED_AT);
109  if (is_null($data)) {
110  return null;
111  }
112  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
113  if (false === $data) {
114  return null;
115  }
116  $this->syncedAt = $data;
117  }
118 
119  return $this->syncedAt;
120  }
121 
122 
126  public function setChannel(?ChannelKeyReference $channel): void
127  {
128  $this->channel = $channel;
129  }
130 
134  public function setExternalId(?string $externalId): void
135  {
136  $this->externalId = $externalId;
137  }
138 
142  public function setSyncedAt(?DateTimeImmutable $syncedAt): void
143  {
144  $this->syncedAt = $syncedAt;
145  }
146 
147 
148  #[\ReturnTypeWillChange]
149  public function jsonSerialize()
150  {
151  $data = $this->toArray();
152  if (isset($data[SyncInfo::FIELD_SYNCED_AT]) && $data[SyncInfo::FIELD_SYNCED_AT] instanceof \DateTimeImmutable) {
153  $data[SyncInfo::FIELD_SYNCED_AT] = $data[SyncInfo::FIELD_SYNCED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
154  }
155  return (object) $data;
156  }
157 }
__construct(?ChannelKeyReference $channel=null, ?string $externalId=null, ?DateTimeImmutable $syncedAt=null)