commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
BaseEventModel.php
1<?php
2
3declare(strict_types=1);
10
15use DateTimeImmutable;
16use stdClass;
17
21final class BaseEventModel extends JsonObjectModel implements BaseEvent
22{
27 protected $id;
28
34
39 protected $resourceType;
40
45 protected $type;
46
51 protected $data;
52
57 protected $createdAt;
58
59
63 public function __construct(
64 ?string $id = null,
65 ?string $notificationType = null,
66 ?string $resourceType = null,
67 ?string $type = null,
68 ?JsonObject $data = null,
69 ?DateTimeImmutable $createdAt = null
70 ) {
71 $this->id = $id;
72 $this->notificationType = $notificationType;
73 $this->resourceType = $resourceType;
74 $this->type = $type;
75 $this->data = $data;
76 $this->createdAt = $createdAt;
77 }
78
85 public function getId()
86 {
87 if (is_null($this->id)) {
89 $data = $this->raw(self::FIELD_ID);
90 if (is_null($data)) {
91 return null;
92 }
93 $this->id = (string) $data;
94 }
95
96 return $this->id;
97 }
98
103 public function getNotificationType()
104 {
105 if (is_null($this->notificationType)) {
107 $data = $this->raw(self::FIELD_NOTIFICATION_TYPE);
108 if (is_null($data)) {
109 return null;
110 }
111 $this->notificationType = (string) $data;
112 }
113
115 }
116
123 public function getResourceType()
124 {
125 if (is_null($this->resourceType)) {
127 $data = $this->raw(self::FIELD_RESOURCE_TYPE);
128 if (is_null($data)) {
129 return null;
130 }
131 $this->resourceType = (string) $data;
132 }
133
134 return $this->resourceType;
135 }
136
143 public function getType()
144 {
145 if (is_null($this->type)) {
147 $data = $this->raw(self::FIELD_TYPE);
148 if (is_null($data)) {
149 return null;
150 }
151 $this->type = (string) $data;
152 }
153
154 return $this->type;
155 }
156
163 public function getData()
164 {
165 if (is_null($this->data)) {
167 $data = $this->raw(self::FIELD_DATA);
168 if (is_null($data)) {
169 return null;
170 }
171 $this->data = JsonObjectModel::of($data);
172 }
173
174 return $this->data;
175 }
176
183 public function getCreatedAt()
184 {
185 if (is_null($this->createdAt)) {
187 $data = $this->raw(self::FIELD_CREATED_AT);
188 if (is_null($data)) {
189 return null;
190 }
191 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
192 if (false === $data) {
193 return null;
194 }
195 $this->createdAt = $data;
196 }
197
198 return $this->createdAt;
199 }
200
201
205 public function setId(?string $id): void
206 {
207 $this->id = $id;
208 }
209
213 public function setNotificationType(?string $notificationType): void
214 {
215 $this->notificationType = $notificationType;
216 }
217
221 public function setResourceType(?string $resourceType): void
222 {
223 $this->resourceType = $resourceType;
224 }
225
229 public function setType(?string $type): void
230 {
231 $this->type = $type;
232 }
233
237 public function setData(?JsonObject $data): void
238 {
239 $this->data = $data;
240 }
241
245 public function setCreatedAt(?DateTimeImmutable $createdAt): void
246 {
247 $this->createdAt = $createdAt;
248 }
249
250
251 #[\ReturnTypeWillChange]
252 public function jsonSerialize()
253 {
254 $data = $this->toArray();
255 if (isset($data[BaseEvent::FIELD_CREATED_AT]) && $data[BaseEvent::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
256 $data[BaseEvent::FIELD_CREATED_AT] = $data[BaseEvent::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
257 }
258 return (object) $data;
259 }
260}
setCreatedAt(?DateTimeImmutable $createdAt)
__construct(?string $id=null, ?string $notificationType=null, ?string $resourceType=null, ?string $type=null, ?JsonObject $data=null, ?DateTimeImmutable $createdAt=null)