commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
CartLockModel.php
1<?php
2
3declare(strict_types=1);
10
15use DateTimeImmutable;
16use stdClass;
17
21final class CartLockModel extends JsonObjectModel implements CartLock
22{
27 protected $createdAt;
28
33 protected $clientId;
34
35
39 public function __construct(
40 ?DateTimeImmutable $createdAt = null,
41 ?string $clientId = null
42 ) {
43 $this->createdAt = $createdAt;
44 $this->clientId = $clientId;
45 }
46
53 public function getCreatedAt()
54 {
55 if (is_null($this->createdAt)) {
57 $data = $this->raw(self::FIELD_CREATED_AT);
58 if (is_null($data)) {
59 return null;
60 }
61 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
62 if (false === $data) {
63 return null;
64 }
65 $this->createdAt = $data;
66 }
67
68 return $this->createdAt;
69 }
70
77 public function getClientId()
78 {
79 if (is_null($this->clientId)) {
81 $data = $this->raw(self::FIELD_CLIENT_ID);
82 if (is_null($data)) {
83 return null;
84 }
85 $this->clientId = (string) $data;
86 }
87
88 return $this->clientId;
89 }
90
91
95 public function setCreatedAt(?DateTimeImmutable $createdAt): void
96 {
97 $this->createdAt = $createdAt;
98 }
99
103 public function setClientId(?string $clientId): void
104 {
105 $this->clientId = $clientId;
106 }
107
108
109 #[\ReturnTypeWillChange]
110 public function jsonSerialize()
111 {
112 $data = $this->toArray();
113 if (isset($data[CartLock::FIELD_CREATED_AT]) && $data[CartLock::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
114 $data[CartLock::FIELD_CREATED_AT] = $data[CartLock::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
115 }
116 return (object) $data;
117 }
118}
__construct(?DateTimeImmutable $createdAt=null, ?string $clientId=null)
setCreatedAt(?DateTimeImmutable $createdAt)