commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
CustomObjectModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
21 use DateTimeImmutable;
22 use stdClass;
23 
27 final class CustomObjectModel extends JsonObjectModel implements CustomObject
28 {
33  protected $id;
34 
39  protected $version;
40 
45  protected $createdAt;
46 
51  protected $lastModifiedAt;
52 
57  protected $lastModifiedBy;
58 
63  protected $createdBy;
64 
69  protected $container;
70 
75  protected $key;
76 
81  protected $value;
82 
83 
87  public function __construct(
88  ?string $id = null,
89  ?int $version = null,
90  ?DateTimeImmutable $createdAt = null,
91  ?DateTimeImmutable $lastModifiedAt = null,
93  ?CreatedBy $createdBy = null,
94  ?string $container = null,
95  ?string $key = null,
96  $value = null
97  ) {
98  $this->id = $id;
99  $this->version = $version;
100  $this->createdAt = $createdAt;
101  $this->lastModifiedAt = $lastModifiedAt;
102  $this->lastModifiedBy = $lastModifiedBy;
103  $this->createdBy = $createdBy;
104  $this->container = $container;
105  $this->key = $key;
106  $this->value = $value;
107  }
108 
115  public function getId()
116  {
117  if (is_null($this->id)) {
119  $data = $this->raw(self::FIELD_ID);
120  if (is_null($data)) {
121  return null;
122  }
123  $this->id = (string) $data;
124  }
125 
126  return $this->id;
127  }
128 
135  public function getVersion()
136  {
137  if (is_null($this->version)) {
139  $data = $this->raw(self::FIELD_VERSION);
140  if (is_null($data)) {
141  return null;
142  }
143  $this->version = (int) $data;
144  }
145 
146  return $this->version;
147  }
148 
155  public function getCreatedAt()
156  {
157  if (is_null($this->createdAt)) {
159  $data = $this->raw(self::FIELD_CREATED_AT);
160  if (is_null($data)) {
161  return null;
162  }
163  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
164  if (false === $data) {
165  return null;
166  }
167  $this->createdAt = $data;
168  }
169 
170  return $this->createdAt;
171  }
172 
179  public function getLastModifiedAt()
180  {
181  if (is_null($this->lastModifiedAt)) {
183  $data = $this->raw(self::FIELD_LAST_MODIFIED_AT);
184  if (is_null($data)) {
185  return null;
186  }
187  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
188  if (false === $data) {
189  return null;
190  }
191  $this->lastModifiedAt = $data;
192  }
193 
194  return $this->lastModifiedAt;
195  }
196 
203  public function getLastModifiedBy()
204  {
205  if (is_null($this->lastModifiedBy)) {
207  $data = $this->raw(self::FIELD_LAST_MODIFIED_BY);
208  if (is_null($data)) {
209  return null;
210  }
211 
212  $this->lastModifiedBy = LastModifiedByModel::of($data);
213  }
214 
215  return $this->lastModifiedBy;
216  }
217 
224  public function getCreatedBy()
225  {
226  if (is_null($this->createdBy)) {
228  $data = $this->raw(self::FIELD_CREATED_BY);
229  if (is_null($data)) {
230  return null;
231  }
232 
233  $this->createdBy = CreatedByModel::of($data);
234  }
235 
236  return $this->createdBy;
237  }
238 
245  public function getContainer()
246  {
247  if (is_null($this->container)) {
249  $data = $this->raw(self::FIELD_CONTAINER);
250  if (is_null($data)) {
251  return null;
252  }
253  $this->container = (string) $data;
254  }
255 
256  return $this->container;
257  }
258 
265  public function getKey()
266  {
267  if (is_null($this->key)) {
269  $data = $this->raw(self::FIELD_KEY);
270  if (is_null($data)) {
271  return null;
272  }
273  $this->key = (string) $data;
274  }
275 
276  return $this->key;
277  }
278 
288  public function getValue()
289  {
290  if (is_null($this->value)) {
292  $data = $this->raw(self::FIELD_VALUE);
293  if (is_null($data)) {
294  return null;
295  }
296  $this->value = $data;
297  }
298 
299  return $this->value;
300  }
301 
302 
306  public function setId(?string $id): void
307  {
308  $this->id = $id;
309  }
310 
314  public function setVersion(?int $version): void
315  {
316  $this->version = $version;
317  }
318 
322  public function setCreatedAt(?DateTimeImmutable $createdAt): void
323  {
324  $this->createdAt = $createdAt;
325  }
326 
330  public function setLastModifiedAt(?DateTimeImmutable $lastModifiedAt): void
331  {
332  $this->lastModifiedAt = $lastModifiedAt;
333  }
334 
339  {
340  $this->lastModifiedBy = $lastModifiedBy;
341  }
342 
346  public function setCreatedBy(?CreatedBy $createdBy): void
347  {
348  $this->createdBy = $createdBy;
349  }
350 
354  public function setContainer(?string $container): void
355  {
356  $this->container = $container;
357  }
358 
362  public function setKey(?string $key): void
363  {
364  $this->key = $key;
365  }
366 
370  public function setValue($value): void
371  {
372  $this->value = $value;
373  }
374 
375 
376  #[\ReturnTypeWillChange]
377  public function jsonSerialize()
378  {
379  $data = $this->toArray();
380  if (isset($data[CustomObject::FIELD_CREATED_AT]) && $data[CustomObject::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
381  $data[CustomObject::FIELD_CREATED_AT] = $data[CustomObject::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
382  }
383 
384  if (isset($data[CustomObject::FIELD_LAST_MODIFIED_AT]) && $data[CustomObject::FIELD_LAST_MODIFIED_AT] instanceof \DateTimeImmutable) {
385  $data[CustomObject::FIELD_LAST_MODIFIED_AT] = $data[CustomObject::FIELD_LAST_MODIFIED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
386  }
387  return (object) $data;
388  }
389 }
__construct(?string $id=null, ?int $version=null, ?DateTimeImmutable $createdAt=null, ?DateTimeImmutable $lastModifiedAt=null, ?LastModifiedBy $lastModifiedBy=null, ?CreatedBy $createdBy=null, ?string $container=null, ?string $key=null, $value=null)