commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
ImportContainerModel.php
1<?php
2
3declare(strict_types=1);
10
15use DateTimeImmutable;
16use stdClass;
17
22{
27 protected $key;
28
33 protected $resourceType;
34
39 protected $version;
40
45 protected $createdAt;
46
51 protected $lastModifiedAt;
52
53
57 public function __construct(
58 ?string $key = null,
59 ?string $resourceType = null,
60 ?int $version = null,
61 ?DateTimeImmutable $createdAt = null,
62 ?DateTimeImmutable $lastModifiedAt = null
63 ) {
64 $this->key = $key;
65 $this->resourceType = $resourceType;
66 $this->version = $version;
67 $this->createdAt = $createdAt;
68 $this->lastModifiedAt = $lastModifiedAt;
69 }
70
78 public function getKey()
79 {
80 if (is_null($this->key)) {
82 $data = $this->raw(self::FIELD_KEY);
83 if (is_null($data)) {
84 return null;
85 }
86 $this->key = (string) $data;
87 }
88
89 return $this->key;
90 }
91
99 public function getResourceType()
100 {
101 if (is_null($this->resourceType)) {
103 $data = $this->raw(self::FIELD_RESOURCE_TYPE);
104 if (is_null($data)) {
105 return null;
106 }
107 $this->resourceType = (string) $data;
108 }
109
110 return $this->resourceType;
111 }
112
119 public function getVersion()
120 {
121 if (is_null($this->version)) {
123 $data = $this->raw(self::FIELD_VERSION);
124 if (is_null($data)) {
125 return null;
126 }
127 $this->version = (int) $data;
128 }
129
130 return $this->version;
131 }
132
139 public function getCreatedAt()
140 {
141 if (is_null($this->createdAt)) {
143 $data = $this->raw(self::FIELD_CREATED_AT);
144 if (is_null($data)) {
145 return null;
146 }
147 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
148 if (false === $data) {
149 return null;
150 }
151 $this->createdAt = $data;
152 }
153
154 return $this->createdAt;
155 }
156
163 public function getLastModifiedAt()
164 {
165 if (is_null($this->lastModifiedAt)) {
167 $data = $this->raw(self::FIELD_LAST_MODIFIED_AT);
168 if (is_null($data)) {
169 return null;
170 }
171 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
172 if (false === $data) {
173 return null;
174 }
175 $this->lastModifiedAt = $data;
176 }
177
179 }
180
181
185 public function setKey(?string $key): void
186 {
187 $this->key = $key;
188 }
189
193 public function setResourceType(?string $resourceType): void
194 {
195 $this->resourceType = $resourceType;
196 }
197
201 public function setVersion(?int $version): void
202 {
203 $this->version = $version;
204 }
205
209 public function setCreatedAt(?DateTimeImmutable $createdAt): void
210 {
211 $this->createdAt = $createdAt;
212 }
213
217 public function setLastModifiedAt(?DateTimeImmutable $lastModifiedAt): void
218 {
219 $this->lastModifiedAt = $lastModifiedAt;
220 }
221
222
223 #[\ReturnTypeWillChange]
224 public function jsonSerialize()
225 {
226 $data = $this->toArray();
227 if (isset($data[ImportContainer::FIELD_CREATED_AT]) && $data[ImportContainer::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
228 $data[ImportContainer::FIELD_CREATED_AT] = $data[ImportContainer::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
229 }
230
231 if (isset($data[ImportContainer::FIELD_LAST_MODIFIED_AT]) && $data[ImportContainer::FIELD_LAST_MODIFIED_AT] instanceof \DateTimeImmutable) {
232 $data[ImportContainer::FIELD_LAST_MODIFIED_AT] = $data[ImportContainer::FIELD_LAST_MODIFIED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
233 }
234 return (object) $data;
235 }
236}
__construct(?string $key=null, ?string $resourceType=null, ?int $version=null, ?DateTimeImmutable $createdAt=null, ?DateTimeImmutable $lastModifiedAt=null)