commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
ChannelModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
31 use DateTimeImmutable;
32 use stdClass;
33 
37 final class ChannelModel extends JsonObjectModel implements Channel
38 {
43  protected $id;
44 
49  protected $version;
50 
55  protected $createdAt;
56 
61  protected $lastModifiedAt;
62 
67  protected $lastModifiedBy;
68 
73  protected $createdBy;
74 
79  protected $key;
80 
85  protected $roles;
86 
91  protected $name;
92 
97  protected $description;
98 
103  protected $address;
104 
110 
115  protected $custom;
116 
121  protected $geoLocation;
122 
123 
127  public function __construct(
128  ?string $id = null,
129  ?int $version = null,
130  ?DateTimeImmutable $createdAt = null,
131  ?DateTimeImmutable $lastModifiedAt = null,
133  ?CreatedBy $createdBy = null,
134  ?string $key = null,
135  ?array $roles = null,
136  ?LocalizedString $name = null,
138  ?Address $address = null,
140  ?CustomFields $custom = null,
141  ?GeoJson $geoLocation = null
142  ) {
143  $this->id = $id;
144  $this->version = $version;
145  $this->createdAt = $createdAt;
146  $this->lastModifiedAt = $lastModifiedAt;
147  $this->lastModifiedBy = $lastModifiedBy;
148  $this->createdBy = $createdBy;
149  $this->key = $key;
150  $this->roles = $roles;
151  $this->name = $name;
152  $this->description = $description;
153  $this->address = $address;
154  $this->reviewRatingStatistics = $reviewRatingStatistics;
155  $this->custom = $custom;
156  $this->geoLocation = $geoLocation;
157  }
158 
165  public function getId()
166  {
167  if (is_null($this->id)) {
169  $data = $this->raw(self::FIELD_ID);
170  if (is_null($data)) {
171  return null;
172  }
173  $this->id = (string) $data;
174  }
175 
176  return $this->id;
177  }
178 
185  public function getVersion()
186  {
187  if (is_null($this->version)) {
189  $data = $this->raw(self::FIELD_VERSION);
190  if (is_null($data)) {
191  return null;
192  }
193  $this->version = (int) $data;
194  }
195 
196  return $this->version;
197  }
198 
205  public function getCreatedAt()
206  {
207  if (is_null($this->createdAt)) {
209  $data = $this->raw(self::FIELD_CREATED_AT);
210  if (is_null($data)) {
211  return null;
212  }
213  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
214  if (false === $data) {
215  return null;
216  }
217  $this->createdAt = $data;
218  }
219 
220  return $this->createdAt;
221  }
222 
229  public function getLastModifiedAt()
230  {
231  if (is_null($this->lastModifiedAt)) {
233  $data = $this->raw(self::FIELD_LAST_MODIFIED_AT);
234  if (is_null($data)) {
235  return null;
236  }
237  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
238  if (false === $data) {
239  return null;
240  }
241  $this->lastModifiedAt = $data;
242  }
243 
244  return $this->lastModifiedAt;
245  }
246 
253  public function getLastModifiedBy()
254  {
255  if (is_null($this->lastModifiedBy)) {
257  $data = $this->raw(self::FIELD_LAST_MODIFIED_BY);
258  if (is_null($data)) {
259  return null;
260  }
261 
262  $this->lastModifiedBy = LastModifiedByModel::of($data);
263  }
264 
265  return $this->lastModifiedBy;
266  }
267 
274  public function getCreatedBy()
275  {
276  if (is_null($this->createdBy)) {
278  $data = $this->raw(self::FIELD_CREATED_BY);
279  if (is_null($data)) {
280  return null;
281  }
282 
283  $this->createdBy = CreatedByModel::of($data);
284  }
285 
286  return $this->createdBy;
287  }
288 
295  public function getKey()
296  {
297  if (is_null($this->key)) {
299  $data = $this->raw(self::FIELD_KEY);
300  if (is_null($data)) {
301  return null;
302  }
303  $this->key = (string) $data;
304  }
305 
306  return $this->key;
307  }
308 
315  public function getRoles()
316  {
317  if (is_null($this->roles)) {
319  $data = $this->raw(self::FIELD_ROLES);
320  if (is_null($data)) {
321  return null;
322  }
323  $this->roles = $data;
324  }
325 
326  return $this->roles;
327  }
328 
335  public function getName()
336  {
337  if (is_null($this->name)) {
339  $data = $this->raw(self::FIELD_NAME);
340  if (is_null($data)) {
341  return null;
342  }
343 
344  $this->name = LocalizedStringModel::of($data);
345  }
346 
347  return $this->name;
348  }
349 
356  public function getDescription()
357  {
358  if (is_null($this->description)) {
360  $data = $this->raw(self::FIELD_DESCRIPTION);
361  if (is_null($data)) {
362  return null;
363  }
364 
365  $this->description = LocalizedStringModel::of($data);
366  }
367 
368  return $this->description;
369  }
370 
377  public function getAddress()
378  {
379  if (is_null($this->address)) {
381  $data = $this->raw(self::FIELD_ADDRESS);
382  if (is_null($data)) {
383  return null;
384  }
385 
386  $this->address = AddressModel::of($data);
387  }
388 
389  return $this->address;
390  }
391 
398  public function getReviewRatingStatistics()
399  {
400  if (is_null($this->reviewRatingStatistics)) {
402  $data = $this->raw(self::FIELD_REVIEW_RATING_STATISTICS);
403  if (is_null($data)) {
404  return null;
405  }
406 
407  $this->reviewRatingStatistics = ReviewRatingStatisticsModel::of($data);
408  }
409 
411  }
412 
419  public function getCustom()
420  {
421  if (is_null($this->custom)) {
423  $data = $this->raw(self::FIELD_CUSTOM);
424  if (is_null($data)) {
425  return null;
426  }
427 
428  $this->custom = CustomFieldsModel::of($data);
429  }
430 
431  return $this->custom;
432  }
433 
440  public function getGeoLocation()
441  {
442  if (is_null($this->geoLocation)) {
444  $data = $this->raw(self::FIELD_GEO_LOCATION);
445  if (is_null($data)) {
446  return null;
447  }
448  $className = GeoJsonModel::resolveDiscriminatorClass($data);
449  $this->geoLocation = $className::of($data);
450  }
451 
452  return $this->geoLocation;
453  }
454 
455 
459  public function setId(?string $id): void
460  {
461  $this->id = $id;
462  }
463 
467  public function setVersion(?int $version): void
468  {
469  $this->version = $version;
470  }
471 
475  public function setCreatedAt(?DateTimeImmutable $createdAt): void
476  {
477  $this->createdAt = $createdAt;
478  }
479 
483  public function setLastModifiedAt(?DateTimeImmutable $lastModifiedAt): void
484  {
485  $this->lastModifiedAt = $lastModifiedAt;
486  }
487 
492  {
493  $this->lastModifiedBy = $lastModifiedBy;
494  }
495 
499  public function setCreatedBy(?CreatedBy $createdBy): void
500  {
501  $this->createdBy = $createdBy;
502  }
503 
507  public function setKey(?string $key): void
508  {
509  $this->key = $key;
510  }
511 
515  public function setRoles(?array $roles): void
516  {
517  $this->roles = $roles;
518  }
519 
523  public function setName(?LocalizedString $name): void
524  {
525  $this->name = $name;
526  }
527 
532  {
533  $this->description = $description;
534  }
535 
539  public function setAddress(?Address $address): void
540  {
541  $this->address = $address;
542  }
543 
548  {
549  $this->reviewRatingStatistics = $reviewRatingStatistics;
550  }
551 
555  public function setCustom(?CustomFields $custom): void
556  {
557  $this->custom = $custom;
558  }
559 
563  public function setGeoLocation(?GeoJson $geoLocation): void
564  {
565  $this->geoLocation = $geoLocation;
566  }
567 
568 
569  #[\ReturnTypeWillChange]
570  public function jsonSerialize()
571  {
572  $data = $this->toArray();
573  if (isset($data[Channel::FIELD_CREATED_AT]) && $data[Channel::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
574  $data[Channel::FIELD_CREATED_AT] = $data[Channel::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
575  }
576 
577  if (isset($data[Channel::FIELD_LAST_MODIFIED_AT]) && $data[Channel::FIELD_LAST_MODIFIED_AT] instanceof \DateTimeImmutable) {
578  $data[Channel::FIELD_LAST_MODIFIED_AT] = $data[Channel::FIELD_LAST_MODIFIED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
579  }
580  return (object) $data;
581  }
582 }
setLastModifiedBy(?LastModifiedBy $lastModifiedBy)
setReviewRatingStatistics(?ReviewRatingStatistics $reviewRatingStatistics)
setLastModifiedAt(?DateTimeImmutable $lastModifiedAt)
setDescription(?LocalizedString $description)
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, ?array $roles=null, ?LocalizedString $name=null, ?LocalizedString $description=null, ?Address $address=null, ?ReviewRatingStatistics $reviewRatingStatistics=null, ?CustomFields $custom=null, ?GeoJson $geoLocation=null)
static of($data=null)
Definition: MapperMap.php:45