commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
ApprovalFlowApprovalModel.php
1<?php
2
3declare(strict_types=1);
10
17use DateTimeImmutable;
18use stdClass;
19
24{
29 protected $approver;
30
35 protected $approvedAt;
36
37
41 public function __construct(
42 ?Associate $approver = null,
43 ?DateTimeImmutable $approvedAt = null
44 ) {
45 $this->approver = $approver;
46 $this->approvedAt = $approvedAt;
47 }
48
55 public function getApprover()
56 {
57 if (is_null($this->approver)) {
59 $data = $this->raw(self::FIELD_APPROVER);
60 if (is_null($data)) {
61 return null;
62 }
63
64 $this->approver = AssociateModel::of($data);
65 }
66
67 return $this->approver;
68 }
69
76 public function getApprovedAt()
77 {
78 if (is_null($this->approvedAt)) {
80 $data = $this->raw(self::FIELD_APPROVED_AT);
81 if (is_null($data)) {
82 return null;
83 }
84 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
85 if (false === $data) {
86 return null;
87 }
88 $this->approvedAt = $data;
89 }
90
91 return $this->approvedAt;
92 }
93
94
98 public function setApprover(?Associate $approver): void
99 {
100 $this->approver = $approver;
101 }
102
106 public function setApprovedAt(?DateTimeImmutable $approvedAt): void
107 {
108 $this->approvedAt = $approvedAt;
109 }
110
111
112 #[\ReturnTypeWillChange]
113 public function jsonSerialize()
114 {
115 $data = $this->toArray();
116 if (isset($data[ApprovalFlowApproval::FIELD_APPROVED_AT]) && $data[ApprovalFlowApproval::FIELD_APPROVED_AT] instanceof \DateTimeImmutable) {
117 $data[ApprovalFlowApproval::FIELD_APPROVED_AT] = $data[ApprovalFlowApproval::FIELD_APPROVED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
118 }
119 return (object) $data;
120 }
121}
__construct(?Associate $approver=null, ?DateTimeImmutable $approvedAt=null)