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 'CheckoutOrderCreationFailed' => CheckoutOrderCreationFailedEventModel::class,
60 'CheckoutPaymentAuthorizationCancelled' => CheckoutPaymentAuthorizationCancelledEventModel::class,
61 'CheckoutPaymentAuthorizationFailed' => CheckoutPaymentAuthorizationFailedEventModel::class,
62 'CheckoutPaymentAuthorized' => CheckoutPaymentAuthorizedEventModel::class,
63 'CheckoutPaymentCancelAuthorizationFailed' => CheckoutPaymentCancelAuthorizationFailedEventModel::class,
64 'CheckoutPaymentChargeFailed' => CheckoutPaymentChargeFailedEventModel::class,
65 'CheckoutPaymentCharged' => CheckoutPaymentChargedEventModel::class,
66 'CheckoutPaymentRefundFailed' => CheckoutPaymentRefundFailedEventModel::class,
67 'CheckoutPaymentRefunded' => CheckoutPaymentRefundedEventModel::class,
68 'ImportContainerCreated' => ImportContainerCreatedEventModel::class,
69 'ImportContainerDeleted' => ImportContainerDeletedEventModel::class,
70 'ImportOperationRejected' => ImportOperationRejectedEventModel::class,
71 'ImportUnresolved' => ImportUnresolvedEventModel::class,
72 'ImportValidationFailed' => ImportValidationFailedEventModel::class,
73 'ImportWaitForMasterVariant' => ImportWaitForMasterVariantEventModel::class,
74 ];
75
79 public function __construct(
80 ?string $id = null,
81 ?string $notificationType = null,
82 ?string $resourceType = null,
83 ?DateTimeImmutable $createdAt = null,
84 ?string $type = null
85 ) {
86 $this->id = $id;
87 $this->notificationType = $notificationType;
88 $this->resourceType = $resourceType;
89 $this->createdAt = $createdAt;
90 $this->type = $type;
91 }
92
99 public function getId()
100 {
101 if (is_null($this->id)) {
103 $data = $this->raw(self::FIELD_ID);
104 if (is_null($data)) {
105 return null;
106 }
107 $this->id = (string) $data;
108 }
109
110 return $this->id;
111 }
112
117 public function getNotificationType()
118 {
119 if (is_null($this->notificationType)) {
121 $data = $this->raw(self::FIELD_NOTIFICATION_TYPE);
122 if (is_null($data)) {
123 return null;
124 }
125 $this->notificationType = (string) $data;
126 }
127
129 }
130
137 public function getResourceType()
138 {
139 if (is_null($this->resourceType)) {
141 $data = $this->raw(self::FIELD_RESOURCE_TYPE);
142 if (is_null($data)) {
143 return null;
144 }
145 $this->resourceType = (string) $data;
146 }
147
148 return $this->resourceType;
149 }
150
157 public function getType()
158 {
159 if (is_null($this->type)) {
161 $data = $this->raw(self::FIELD_TYPE);
162 if (is_null($data)) {
163 return null;
164 }
165 $this->type = (string) $data;
166 }
167
168 return $this->type;
169 }
170
177 public function getCreatedAt()
178 {
179 if (is_null($this->createdAt)) {
181 $data = $this->raw(self::FIELD_CREATED_AT);
182 if (is_null($data)) {
183 return null;
184 }
185 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
186 if (false === $data) {
187 return null;
188 }
189 $this->createdAt = $data;
190 }
191
192 return $this->createdAt;
193 }
194
195
199 public function setId(?string $id): void
200 {
201 $this->id = $id;
202 }
203
207 public function setNotificationType(?string $notificationType): void
208 {
209 $this->notificationType = $notificationType;
210 }
211
215 public function setResourceType(?string $resourceType): void
216 {
217 $this->resourceType = $resourceType;
218 }
219
223 public function setCreatedAt(?DateTimeImmutable $createdAt): void
224 {
225 $this->createdAt = $createdAt;
226 }
227
228
229 #[\ReturnTypeWillChange]
230 public function jsonSerialize()
231 {
232 $data = $this->toArray();
233 if (isset($data[Event::FIELD_CREATED_AT]) && $data[Event::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
234 $data[Event::FIELD_CREATED_AT] = $data[Event::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
235 }
236 return (object) $data;
237 }
238
243 public static function resolveDiscriminatorClass($value): string
244 {
245 $fieldName = Event::DISCRIMINATOR_FIELD;
246 if (is_object($value) && isset($value->$fieldName)) {
248 $discriminatorValue = $value->$fieldName;
249 if (isset(self::$discriminatorClasses[$discriminatorValue])) {
250 return self::$discriminatorClasses[$discriminatorValue];
251 }
252 }
253 if (is_array($value) && isset($value[$fieldName])) {
255 $discriminatorValue = $value[$fieldName];
256 if (isset(self::$discriminatorClasses[$discriminatorValue])) {
257 return self::$discriminatorClasses[$discriminatorValue];
258 }
259 }
260
262 $type = EventModel::class;
263 return $type;
264 }
265}
setCreatedAt(?DateTimeImmutable $createdAt)
setNotificationType(?string $notificationType)
__construct(?string $id=null, ?string $notificationType=null, ?string $resourceType=null, ?DateTimeImmutable $createdAt=null, ?string $type=null)