commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
CustomerTokenModel.php
1<?php
2
3declare(strict_types=1);
10
15use DateTimeImmutable;
16use stdClass;
17
21final class CustomerTokenModel extends JsonObjectModel implements CustomerToken
22{
27 protected $id;
28
33 protected $customerId;
34
39 protected $value;
40
45 protected $expiresAt;
46
52
57 protected $createdAt;
58
63 protected $lastModifiedAt;
64
65
69 public function __construct(
70 ?string $id = null,
71 ?string $customerId = null,
72 ?string $value = null,
73 ?DateTimeImmutable $expiresAt = null,
74 ?bool $invalidateOlderTokens = null,
75 ?DateTimeImmutable $createdAt = null,
76 ?DateTimeImmutable $lastModifiedAt = null
77 ) {
78 $this->id = $id;
79 $this->customerId = $customerId;
80 $this->value = $value;
81 $this->expiresAt = $expiresAt;
82 $this->invalidateOlderTokens = $invalidateOlderTokens;
83 $this->createdAt = $createdAt;
84 $this->lastModifiedAt = $lastModifiedAt;
85 }
86
93 public function getId()
94 {
95 if (is_null($this->id)) {
97 $data = $this->raw(self::FIELD_ID);
98 if (is_null($data)) {
99 return null;
100 }
101 $this->id = (string) $data;
102 }
103
104 return $this->id;
105 }
106
113 public function getCustomerId()
114 {
115 if (is_null($this->customerId)) {
117 $data = $this->raw(self::FIELD_CUSTOMER_ID);
118 if (is_null($data)) {
119 return null;
120 }
121 $this->customerId = (string) $data;
122 }
123
124 return $this->customerId;
125 }
126
133 public function getValue()
134 {
135 if (is_null($this->value)) {
137 $data = $this->raw(self::FIELD_VALUE);
138 if (is_null($data)) {
139 return null;
140 }
141 $this->value = (string) $data;
142 }
143
144 return $this->value;
145 }
146
153 public function getExpiresAt()
154 {
155 if (is_null($this->expiresAt)) {
157 $data = $this->raw(self::FIELD_EXPIRES_AT);
158 if (is_null($data)) {
159 return null;
160 }
161 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
162 if (false === $data) {
163 return null;
164 }
165 $this->expiresAt = $data;
166 }
167
168 return $this->expiresAt;
169 }
170
177 public function getInvalidateOlderTokens()
178 {
179 if (is_null($this->invalidateOlderTokens)) {
181 $data = $this->raw(self::FIELD_INVALIDATE_OLDER_TOKENS);
182 if (is_null($data)) {
183 return null;
184 }
185 $this->invalidateOlderTokens = (bool) $data;
186 }
187
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
237 }
238
239
243 public function setId(?string $id): void
244 {
245 $this->id = $id;
246 }
247
251 public function setCustomerId(?string $customerId): void
252 {
253 $this->customerId = $customerId;
254 }
255
259 public function setValue(?string $value): void
260 {
261 $this->value = $value;
262 }
263
267 public function setExpiresAt(?DateTimeImmutable $expiresAt): void
268 {
269 $this->expiresAt = $expiresAt;
270 }
271
276 {
277 $this->invalidateOlderTokens = $invalidateOlderTokens;
278 }
279
283 public function setCreatedAt(?DateTimeImmutable $createdAt): void
284 {
285 $this->createdAt = $createdAt;
286 }
287
291 public function setLastModifiedAt(?DateTimeImmutable $lastModifiedAt): void
292 {
293 $this->lastModifiedAt = $lastModifiedAt;
294 }
295
296
297 #[\ReturnTypeWillChange]
298 public function jsonSerialize()
299 {
300 $data = $this->toArray();
301 if (isset($data[CustomerToken::FIELD_EXPIRES_AT]) && $data[CustomerToken::FIELD_EXPIRES_AT] instanceof \DateTimeImmutable) {
302 $data[CustomerToken::FIELD_EXPIRES_AT] = $data[CustomerToken::FIELD_EXPIRES_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
303 }
304
305 if (isset($data[CustomerToken::FIELD_CREATED_AT]) && $data[CustomerToken::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
306 $data[CustomerToken::FIELD_CREATED_AT] = $data[CustomerToken::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
307 }
308
309 if (isset($data[CustomerToken::FIELD_LAST_MODIFIED_AT]) && $data[CustomerToken::FIELD_LAST_MODIFIED_AT] instanceof \DateTimeImmutable) {
310 $data[CustomerToken::FIELD_LAST_MODIFIED_AT] = $data[CustomerToken::FIELD_LAST_MODIFIED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
311 }
312 return (object) $data;
313 }
314}
setLastModifiedAt(?DateTimeImmutable $lastModifiedAt)
__construct(?string $id=null, ?string $customerId=null, ?string $value=null, ?DateTimeImmutable $expiresAt=null, ?bool $invalidateOlderTokens=null, ?DateTimeImmutable $createdAt=null, ?DateTimeImmutable $lastModifiedAt=null)