commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
ApprovalRuleModel.php
1<?php
2
3declare(strict_types=1);
10
25use DateTimeImmutable;
26use stdClass;
27
31final class ApprovalRuleModel extends JsonObjectModel implements ApprovalRule
32{
37 protected $id;
38
43 protected $version;
44
49 protected $createdAt;
50
55 protected $lastModifiedAt;
56
61 protected $createdBy;
62
67 protected $lastModifiedBy;
68
73 protected $key;
74
79 protected $name;
80
85 protected $description;
86
91 protected $status;
92
97 protected $predicate;
98
103 protected $approvers;
104
109 protected $requesters;
110
115 protected $businessUnit;
116
121 protected $custom;
122
123
127 public function __construct(
128 ?string $id = null,
129 ?int $version = null,
130 ?DateTimeImmutable $createdAt = null,
131 ?DateTimeImmutable $lastModifiedAt = null,
132 ?CreatedBy $createdBy = null,
134 ?string $key = null,
135 ?string $name = null,
136 ?string $description = null,
137 ?string $status = null,
138 ?string $predicate = null,
142 ?CustomFields $custom = null
143 ) {
144 $this->id = $id;
145 $this->version = $version;
146 $this->createdAt = $createdAt;
147 $this->lastModifiedAt = $lastModifiedAt;
148 $this->createdBy = $createdBy;
149 $this->lastModifiedBy = $lastModifiedBy;
150 $this->key = $key;
151 $this->name = $name;
152 $this->description = $description;
153 $this->status = $status;
154 $this->predicate = $predicate;
155 $this->approvers = $approvers;
156 $this->requesters = $requesters;
157 $this->businessUnit = $businessUnit;
158 $this->custom = $custom;
159 }
160
167 public function getId()
168 {
169 if (is_null($this->id)) {
171 $data = $this->raw(self::FIELD_ID);
172 if (is_null($data)) {
173 return null;
174 }
175 $this->id = (string) $data;
176 }
177
178 return $this->id;
179 }
180
187 public function getVersion()
188 {
189 if (is_null($this->version)) {
191 $data = $this->raw(self::FIELD_VERSION);
192 if (is_null($data)) {
193 return null;
194 }
195 $this->version = (int) $data;
196 }
197
198 return $this->version;
199 }
200
207 public function getCreatedAt()
208 {
209 if (is_null($this->createdAt)) {
211 $data = $this->raw(self::FIELD_CREATED_AT);
212 if (is_null($data)) {
213 return null;
214 }
215 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
216 if (false === $data) {
217 return null;
218 }
219 $this->createdAt = $data;
220 }
221
222 return $this->createdAt;
223 }
224
231 public function getLastModifiedAt()
232 {
233 if (is_null($this->lastModifiedAt)) {
235 $data = $this->raw(self::FIELD_LAST_MODIFIED_AT);
236 if (is_null($data)) {
237 return null;
238 }
239 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
240 if (false === $data) {
241 return null;
242 }
243 $this->lastModifiedAt = $data;
244 }
245
247 }
248
255 public function getCreatedBy()
256 {
257 if (is_null($this->createdBy)) {
259 $data = $this->raw(self::FIELD_CREATED_BY);
260 if (is_null($data)) {
261 return null;
262 }
263
264 $this->createdBy = CreatedByModel::of($data);
265 }
266
267 return $this->createdBy;
268 }
269
276 public function getLastModifiedBy()
277 {
278 if (is_null($this->lastModifiedBy)) {
280 $data = $this->raw(self::FIELD_LAST_MODIFIED_BY);
281 if (is_null($data)) {
282 return null;
283 }
284
285 $this->lastModifiedBy = LastModifiedByModel::of($data);
286 }
287
289 }
290
297 public function getKey()
298 {
299 if (is_null($this->key)) {
301 $data = $this->raw(self::FIELD_KEY);
302 if (is_null($data)) {
303 return null;
304 }
305 $this->key = (string) $data;
306 }
307
308 return $this->key;
309 }
310
317 public function getName()
318 {
319 if (is_null($this->name)) {
321 $data = $this->raw(self::FIELD_NAME);
322 if (is_null($data)) {
323 return null;
324 }
325 $this->name = (string) $data;
326 }
327
328 return $this->name;
329 }
330
337 public function getDescription()
338 {
339 if (is_null($this->description)) {
341 $data = $this->raw(self::FIELD_DESCRIPTION);
342 if (is_null($data)) {
343 return null;
344 }
345 $this->description = (string) $data;
346 }
347
348 return $this->description;
349 }
350
357 public function getStatus()
358 {
359 if (is_null($this->status)) {
361 $data = $this->raw(self::FIELD_STATUS);
362 if (is_null($data)) {
363 return null;
364 }
365 $this->status = (string) $data;
366 }
367
368 return $this->status;
369 }
370
377 public function getPredicate()
378 {
379 if (is_null($this->predicate)) {
381 $data = $this->raw(self::FIELD_PREDICATE);
382 if (is_null($data)) {
383 return null;
384 }
385 $this->predicate = (string) $data;
386 }
387
388 return $this->predicate;
389 }
390
397 public function getApprovers()
398 {
399 if (is_null($this->approvers)) {
401 $data = $this->raw(self::FIELD_APPROVERS);
402 if (is_null($data)) {
403 return null;
404 }
405
406 $this->approvers = ApproverHierarchyModel::of($data);
407 }
408
409 return $this->approvers;
410 }
411
418 public function getRequesters()
419 {
420 if (is_null($this->requesters)) {
422 $data = $this->raw(self::FIELD_REQUESTERS);
423 if (is_null($data)) {
424 return null;
425 }
426 $this->requesters = RuleRequesterCollection::fromArray($data);
427 }
428
429 return $this->requesters;
430 }
431
438 public function getBusinessUnit()
439 {
440 if (is_null($this->businessUnit)) {
442 $data = $this->raw(self::FIELD_BUSINESS_UNIT);
443 if (is_null($data)) {
444 return null;
445 }
446
447 $this->businessUnit = BusinessUnitKeyReferenceModel::of($data);
448 }
449
450 return $this->businessUnit;
451 }
452
459 public function getCustom()
460 {
461 if (is_null($this->custom)) {
463 $data = $this->raw(self::FIELD_CUSTOM);
464 if (is_null($data)) {
465 return null;
466 }
467
468 $this->custom = CustomFieldsModel::of($data);
469 }
470
471 return $this->custom;
472 }
473
474
478 public function setId(?string $id): void
479 {
480 $this->id = $id;
481 }
482
486 public function setVersion(?int $version): void
487 {
488 $this->version = $version;
489 }
490
494 public function setCreatedAt(?DateTimeImmutable $createdAt): void
495 {
496 $this->createdAt = $createdAt;
497 }
498
502 public function setLastModifiedAt(?DateTimeImmutable $lastModifiedAt): void
503 {
504 $this->lastModifiedAt = $lastModifiedAt;
505 }
506
510 public function setCreatedBy(?CreatedBy $createdBy): void
511 {
512 $this->createdBy = $createdBy;
513 }
514
519 {
520 $this->lastModifiedBy = $lastModifiedBy;
521 }
522
526 public function setKey(?string $key): void
527 {
528 $this->key = $key;
529 }
530
534 public function setName(?string $name): void
535 {
536 $this->name = $name;
537 }
538
542 public function setDescription(?string $description): void
543 {
544 $this->description = $description;
545 }
546
550 public function setStatus(?string $status): void
551 {
552 $this->status = $status;
553 }
554
558 public function setPredicate(?string $predicate): void
559 {
560 $this->predicate = $predicate;
561 }
562
567 {
568 $this->approvers = $approvers;
569 }
570
575 {
576 $this->requesters = $requesters;
577 }
578
583 {
584 $this->businessUnit = $businessUnit;
585 }
586
590 public function setCustom(?CustomFields $custom): void
591 {
592 $this->custom = $custom;
593 }
594
595
596 #[\ReturnTypeWillChange]
597 public function jsonSerialize()
598 {
599 $data = $this->toArray();
600 if (isset($data[ApprovalRule::FIELD_CREATED_AT]) && $data[ApprovalRule::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
601 $data[ApprovalRule::FIELD_CREATED_AT] = $data[ApprovalRule::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
602 }
603
604 if (isset($data[ApprovalRule::FIELD_LAST_MODIFIED_AT]) && $data[ApprovalRule::FIELD_LAST_MODIFIED_AT] instanceof \DateTimeImmutable) {
605 $data[ApprovalRule::FIELD_LAST_MODIFIED_AT] = $data[ApprovalRule::FIELD_LAST_MODIFIED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
606 }
607 return (object) $data;
608 }
609}
setBusinessUnit(?BusinessUnitKeyReference $businessUnit)
__construct(?string $id=null, ?int $version=null, ?DateTimeImmutable $createdAt=null, ?DateTimeImmutable $lastModifiedAt=null, ?CreatedBy $createdBy=null, ?LastModifiedBy $lastModifiedBy=null, ?string $key=null, ?string $name=null, ?string $description=null, ?string $status=null, ?string $predicate=null, ?ApproverHierarchy $approvers=null, ?RuleRequesterCollection $requesters=null, ?BusinessUnitKeyReference $businessUnit=null, ?CustomFields $custom=null)
static fromArray(array $data)