commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
AttributeGroupModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
23 use DateTimeImmutable;
24 use stdClass;
25 
29 final class AttributeGroupModel extends JsonObjectModel implements AttributeGroup
30 {
35  protected $id;
36 
41  protected $version;
42 
47  protected $createdAt;
48 
53  protected $lastModifiedAt;
54 
59  protected $lastModifiedBy;
60 
65  protected $createdBy;
66 
71  protected $name;
72 
77  protected $description;
78 
83  protected $attributes;
84 
89  protected $key;
90 
91 
95  public function __construct(
96  ?string $id = null,
97  ?int $version = null,
98  ?DateTimeImmutable $createdAt = null,
99  ?DateTimeImmutable $lastModifiedAt = null,
101  ?CreatedBy $createdBy = null,
102  ?LocalizedString $name = null,
105  ?string $key = null
106  ) {
107  $this->id = $id;
108  $this->version = $version;
109  $this->createdAt = $createdAt;
110  $this->lastModifiedAt = $lastModifiedAt;
111  $this->lastModifiedBy = $lastModifiedBy;
112  $this->createdBy = $createdBy;
113  $this->name = $name;
114  $this->description = $description;
115  $this->attributes = $attributes;
116  $this->key = $key;
117  }
118 
125  public function getId()
126  {
127  if (is_null($this->id)) {
129  $data = $this->raw(self::FIELD_ID);
130  if (is_null($data)) {
131  return null;
132  }
133  $this->id = (string) $data;
134  }
135 
136  return $this->id;
137  }
138 
145  public function getVersion()
146  {
147  if (is_null($this->version)) {
149  $data = $this->raw(self::FIELD_VERSION);
150  if (is_null($data)) {
151  return null;
152  }
153  $this->version = (int) $data;
154  }
155 
156  return $this->version;
157  }
158 
165  public function getCreatedAt()
166  {
167  if (is_null($this->createdAt)) {
169  $data = $this->raw(self::FIELD_CREATED_AT);
170  if (is_null($data)) {
171  return null;
172  }
173  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
174  if (false === $data) {
175  return null;
176  }
177  $this->createdAt = $data;
178  }
179 
180  return $this->createdAt;
181  }
182 
189  public function getLastModifiedAt()
190  {
191  if (is_null($this->lastModifiedAt)) {
193  $data = $this->raw(self::FIELD_LAST_MODIFIED_AT);
194  if (is_null($data)) {
195  return null;
196  }
197  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
198  if (false === $data) {
199  return null;
200  }
201  $this->lastModifiedAt = $data;
202  }
203 
204  return $this->lastModifiedAt;
205  }
206 
213  public function getLastModifiedBy()
214  {
215  if (is_null($this->lastModifiedBy)) {
217  $data = $this->raw(self::FIELD_LAST_MODIFIED_BY);
218  if (is_null($data)) {
219  return null;
220  }
221 
222  $this->lastModifiedBy = LastModifiedByModel::of($data);
223  }
224 
225  return $this->lastModifiedBy;
226  }
227 
234  public function getCreatedBy()
235  {
236  if (is_null($this->createdBy)) {
238  $data = $this->raw(self::FIELD_CREATED_BY);
239  if (is_null($data)) {
240  return null;
241  }
242 
243  $this->createdBy = CreatedByModel::of($data);
244  }
245 
246  return $this->createdBy;
247  }
248 
255  public function getName()
256  {
257  if (is_null($this->name)) {
259  $data = $this->raw(self::FIELD_NAME);
260  if (is_null($data)) {
261  return null;
262  }
263 
264  $this->name = LocalizedStringModel::of($data);
265  }
266 
267  return $this->name;
268  }
269 
276  public function getDescription()
277  {
278  if (is_null($this->description)) {
280  $data = $this->raw(self::FIELD_DESCRIPTION);
281  if (is_null($data)) {
282  return null;
283  }
284 
285  $this->description = LocalizedStringModel::of($data);
286  }
287 
288  return $this->description;
289  }
290 
297  public function getAttributes()
298  {
299  if (is_null($this->attributes)) {
301  $data = $this->raw(self::FIELD_ATTRIBUTES);
302  if (is_null($data)) {
303  return null;
304  }
305  $this->attributes = AttributeReferenceCollection::fromArray($data);
306  }
307 
308  return $this->attributes;
309  }
310 
317  public function getKey()
318  {
319  if (is_null($this->key)) {
321  $data = $this->raw(self::FIELD_KEY);
322  if (is_null($data)) {
323  return null;
324  }
325  $this->key = (string) $data;
326  }
327 
328  return $this->key;
329  }
330 
331 
335  public function setId(?string $id): void
336  {
337  $this->id = $id;
338  }
339 
343  public function setVersion(?int $version): void
344  {
345  $this->version = $version;
346  }
347 
351  public function setCreatedAt(?DateTimeImmutable $createdAt): void
352  {
353  $this->createdAt = $createdAt;
354  }
355 
359  public function setLastModifiedAt(?DateTimeImmutable $lastModifiedAt): void
360  {
361  $this->lastModifiedAt = $lastModifiedAt;
362  }
363 
368  {
369  $this->lastModifiedBy = $lastModifiedBy;
370  }
371 
375  public function setCreatedBy(?CreatedBy $createdBy): void
376  {
377  $this->createdBy = $createdBy;
378  }
379 
383  public function setName(?LocalizedString $name): void
384  {
385  $this->name = $name;
386  }
387 
392  {
393  $this->description = $description;
394  }
395 
400  {
401  $this->attributes = $attributes;
402  }
403 
407  public function setKey(?string $key): void
408  {
409  $this->key = $key;
410  }
411 
412 
413  #[\ReturnTypeWillChange]
414  public function jsonSerialize()
415  {
416  $data = $this->toArray();
417  if (isset($data[AttributeGroup::FIELD_CREATED_AT]) && $data[AttributeGroup::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
418  $data[AttributeGroup::FIELD_CREATED_AT] = $data[AttributeGroup::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
419  }
420 
421  if (isset($data[AttributeGroup::FIELD_LAST_MODIFIED_AT]) && $data[AttributeGroup::FIELD_LAST_MODIFIED_AT] instanceof \DateTimeImmutable) {
422  $data[AttributeGroup::FIELD_LAST_MODIFIED_AT] = $data[AttributeGroup::FIELD_LAST_MODIFIED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
423  }
424  return (object) $data;
425  }
426 }
setAttributes(?AttributeReferenceCollection $attributes)
__construct(?string $id=null, ?int $version=null, ?DateTimeImmutable $createdAt=null, ?DateTimeImmutable $lastModifiedAt=null, ?LastModifiedBy $lastModifiedBy=null, ?CreatedBy $createdBy=null, ?LocalizedString $name=null, ?LocalizedString $description=null, ?AttributeReferenceCollection $attributes=null, ?string $key=null)
static of($data=null)
Definition: MapperMap.php:45