commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
EventModel.php
1<?php
2
3declare(strict_types=1);
10
15use DateTimeImmutable;
16use stdClass;
17
21final class EventModel extends JsonObjectModel implements Event
22{
23 public const DISCRIMINATOR_VALUE = '';
28 protected $id;
29
35
40 protected $resourceType;
41
46 protected $type;
47
52 protected $createdAt;
53
58 private static $discriminatorClasses = [
59 'ImportContainerCreated' => ImportContainerCreatedEventModel::class,
60 'ImportContainerDeleted' => ImportContainerDeletedEventModel::class,
61 'ImportOperationRejected' => ImportOperationRejectedEventModel::class,
62 'ImportUnresolved' => ImportUnresolvedEventModel::class,
63 'ImportValidationFailed' => ImportValidationFailedEventModel::class,
64 'ImportWaitForMasterVariant' => ImportWaitForMasterVariantEventModel::class,
65 ];
66
70 public function __construct(
71 ?string $id = null,
72 ?string $notificationType = null,
73 ?string $resourceType = null,
74 ?DateTimeImmutable $createdAt = null,
75 ?string $type = null
76 ) {
77 $this->id = $id;
78 $this->notificationType = $notificationType;
79 $this->resourceType = $resourceType;
80 $this->createdAt = $createdAt;
81 $this->type = $type;
82 }
83
90 public function getId()
91 {
92 if (is_null($this->id)) {
94 $data = $this->raw(self::FIELD_ID);
95 if (is_null($data)) {
96 return null;
97 }
98 $this->id = (string) $data;
99 }
100
101 return $this->id;
102 }
103
108 public function getNotificationType()
109 {
110 if (is_null($this->notificationType)) {
112 $data = $this->raw(self::FIELD_NOTIFICATION_TYPE);
113 if (is_null($data)) {
114 return null;
115 }
116 $this->notificationType = (string) $data;
117 }
118
120 }
121
128 public function getResourceType()
129 {
130 if (is_null($this->resourceType)) {
132 $data = $this->raw(self::FIELD_RESOURCE_TYPE);
133 if (is_null($data)) {
134 return null;
135 }
136 $this->resourceType = (string) $data;
137 }
138
139 return $this->resourceType;
140 }
141
148 public function getType()
149 {
150 if (is_null($this->type)) {
152 $data = $this->raw(self::FIELD_TYPE);
153 if (is_null($data)) {
154 return null;
155 }
156 $this->type = (string) $data;
157 }
158
159 return $this->type;
160 }
161
168 public function getCreatedAt()
169 {
170 if (is_null($this->createdAt)) {
172 $data = $this->raw(self::FIELD_CREATED_AT);
173 if (is_null($data)) {
174 return null;
175 }
176 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
177 if (false === $data) {
178 return null;
179 }
180 $this->createdAt = $data;
181 }
182
183 return $this->createdAt;
184 }
185
186
190 public function setId(?string $id): void
191 {
192 $this->id = $id;
193 }
194
198 public function setNotificationType(?string $notificationType): void
199 {
200 $this->notificationType = $notificationType;
201 }
202
206 public function setResourceType(?string $resourceType): void
207 {
208 $this->resourceType = $resourceType;
209 }
210
214 public function setCreatedAt(?DateTimeImmutable $createdAt): void
215 {
216 $this->createdAt = $createdAt;
217 }
218
219
220 #[\ReturnTypeWillChange]
221 public function jsonSerialize()
222 {
223 $data = $this->toArray();
224 if (isset($data[Event::FIELD_CREATED_AT]) && $data[Event::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
225 $data[Event::FIELD_CREATED_AT] = $data[Event::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
226 }
227 return (object) $data;
228 }
229
234 public static function resolveDiscriminatorClass($value): string
235 {
236 $fieldName = Event::DISCRIMINATOR_FIELD;
237 if (is_object($value) && isset($value->$fieldName)) {
239 $discriminatorValue = $value->$fieldName;
240 if (isset(self::$discriminatorClasses[$discriminatorValue])) {
241 return self::$discriminatorClasses[$discriminatorValue];
242 }
243 }
244 if (is_array($value) && isset($value[$fieldName])) {
246 $discriminatorValue = $value[$fieldName];
247 if (isset(self::$discriminatorClasses[$discriminatorValue])) {
248 return self::$discriminatorClasses[$discriminatorValue];
249 }
250 }
251
253 $type = EventModel::class;
254 return $type;
255 }
256}
setCreatedAt(?DateTimeImmutable $createdAt)
setNotificationType(?string $notificationType)
__construct(?string $id=null, ?string $notificationType=null, ?string $resourceType=null, ?DateTimeImmutable $createdAt=null, ?string $type=null)