commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
ZoneModel.php
1<?php
2
3declare(strict_types=1);
10
21use DateTimeImmutable;
22use stdClass;
23
27final class ZoneModel extends JsonObjectModel implements Zone
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 $name;
76
81 protected $description;
82
87 protected $locations;
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,
101 ?string $name = null,
102 ?string $description = 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->name = $name;
113 $this->description = $description;
114 $this->locations = $locations;
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
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
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 getName()
274 {
275 if (is_null($this->name)) {
277 $data = $this->raw(self::FIELD_NAME);
278 if (is_null($data)) {
279 return null;
280 }
281 $this->name = (string) $data;
282 }
283
284 return $this->name;
285 }
286
293 public function getDescription()
294 {
295 if (is_null($this->description)) {
297 $data = $this->raw(self::FIELD_DESCRIPTION);
298 if (is_null($data)) {
299 return null;
300 }
301 $this->description = (string) $data;
302 }
303
304 return $this->description;
305 }
306
313 public function getLocations()
314 {
315 if (is_null($this->locations)) {
317 $data = $this->raw(self::FIELD_LOCATIONS);
318 if (is_null($data)) {
319 return null;
320 }
321 $this->locations = LocationCollection::fromArray($data);
322 }
323
324 return $this->locations;
325 }
326
327
331 public function setId(?string $id): void
332 {
333 $this->id = $id;
334 }
335
339 public function setVersion(?int $version): void
340 {
341 $this->version = $version;
342 }
343
347 public function setCreatedAt(?DateTimeImmutable $createdAt): void
348 {
349 $this->createdAt = $createdAt;
350 }
351
355 public function setLastModifiedAt(?DateTimeImmutable $lastModifiedAt): void
356 {
357 $this->lastModifiedAt = $lastModifiedAt;
358 }
359
364 {
365 $this->lastModifiedBy = $lastModifiedBy;
366 }
367
371 public function setCreatedBy(?CreatedBy $createdBy): void
372 {
373 $this->createdBy = $createdBy;
374 }
375
379 public function setKey(?string $key): void
380 {
381 $this->key = $key;
382 }
383
387 public function setName(?string $name): void
388 {
389 $this->name = $name;
390 }
391
395 public function setDescription(?string $description): void
396 {
397 $this->description = $description;
398 }
399
404 {
405 $this->locations = $locations;
406 }
407
408
409 #[\ReturnTypeWillChange]
410 public function jsonSerialize()
411 {
412 $data = $this->toArray();
413 if (isset($data[Zone::FIELD_CREATED_AT]) && $data[Zone::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
414 $data[Zone::FIELD_CREATED_AT] = $data[Zone::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
415 }
416
417 if (isset($data[Zone::FIELD_LAST_MODIFIED_AT]) && $data[Zone::FIELD_LAST_MODIFIED_AT] instanceof \DateTimeImmutable) {
418 $data[Zone::FIELD_LAST_MODIFIED_AT] = $data[Zone::FIELD_LAST_MODIFIED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
419 }
420 return (object) $data;
421 }
422}
setLocations(?LocationCollection $locations)
setLastModifiedBy(?LastModifiedBy $lastModifiedBy)
setLastModifiedAt(?DateTimeImmutable $lastModifiedAt)
setCreatedBy(?CreatedBy $createdBy)
setCreatedAt(?DateTimeImmutable $createdAt)
__construct(?string $id=null, ?int $version=null, ?DateTimeImmutable $createdAt=null, ?DateTimeImmutable $lastModifiedAt=null, ?LastModifiedBy $lastModifiedBy=null, ?CreatedBy $createdBy=null, ?string $key=null, ?string $name=null, ?string $description=null, ?LocationCollection $locations=null)
Definition ZoneModel.php:93
static fromArray(array $data)