commercetools-sdk-php-v2  master
The platform, import-api and ml-api PHP sdks generated from our api reference.
ParcelModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
17 use DateTimeImmutable;
18 use stdClass;
19 
23 final class ParcelModel extends JsonObjectModel implements Parcel
24 {
29  protected $id;
30 
35  protected $createdAt;
36 
41  protected $measurements;
42 
47  protected $trackingData;
48 
53  protected $items;
54 
59  protected $custom;
60 
61 
65  public function __construct(
66  ?string $id = null,
67  ?DateTimeImmutable $createdAt = null,
71  ?Custom $custom = null
72  ) {
73  $this->id = $id;
74  $this->createdAt = $createdAt;
75  $this->measurements = $measurements;
76  $this->trackingData = $trackingData;
77  $this->items = $items;
78  $this->custom = $custom;
79  }
80 
85  public function getId()
86  {
87  if (is_null($this->id)) {
89  $data = $this->raw(self::FIELD_ID);
90  if (is_null($data)) {
91  return null;
92  }
93  $this->id = (string) $data;
94  }
95 
96  return $this->id;
97  }
98 
103  public function getCreatedAt()
104  {
105  if (is_null($this->createdAt)) {
107  $data = $this->raw(self::FIELD_CREATED_AT);
108  if (is_null($data)) {
109  return null;
110  }
111  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
112  if (false === $data) {
113  return null;
114  }
115  $this->createdAt = $data;
116  }
117 
118  return $this->createdAt;
119  }
120 
125  public function getMeasurements()
126  {
127  if (is_null($this->measurements)) {
129  $data = $this->raw(self::FIELD_MEASUREMENTS);
130  if (is_null($data)) {
131  return null;
132  }
133 
134  $this->measurements = ParcelMeasurementsModel::of($data);
135  }
136 
137  return $this->measurements;
138  }
139 
144  public function getTrackingData()
145  {
146  if (is_null($this->trackingData)) {
148  $data = $this->raw(self::FIELD_TRACKING_DATA);
149  if (is_null($data)) {
150  return null;
151  }
152 
153  $this->trackingData = TrackingDataModel::of($data);
154  }
155 
156  return $this->trackingData;
157  }
158 
163  public function getItems()
164  {
165  if (is_null($this->items)) {
167  $data = $this->raw(self::FIELD_ITEMS);
168  if (is_null($data)) {
169  return null;
170  }
171  $this->items = DeliveryItemCollection::fromArray($data);
172  }
173 
174  return $this->items;
175  }
176 
183  public function getCustom()
184  {
185  if (is_null($this->custom)) {
187  $data = $this->raw(self::FIELD_CUSTOM);
188  if (is_null($data)) {
189  return null;
190  }
191 
192  $this->custom = CustomModel::of($data);
193  }
194 
195  return $this->custom;
196  }
197 
198 
202  public function setId(?string $id): void
203  {
204  $this->id = $id;
205  }
206 
210  public function setCreatedAt(?DateTimeImmutable $createdAt): void
211  {
212  $this->createdAt = $createdAt;
213  }
214 
219  {
220  $this->measurements = $measurements;
221  }
222 
227  {
228  $this->trackingData = $trackingData;
229  }
230 
234  public function setItems(?DeliveryItemCollection $items): void
235  {
236  $this->items = $items;
237  }
238 
242  public function setCustom(?Custom $custom): void
243  {
244  $this->custom = $custom;
245  }
246 
247 
248  #[\ReturnTypeWillChange]
249  public function jsonSerialize()
250  {
251  $data = $this->toArray();
252  if (isset($data[Parcel::FIELD_CREATED_AT]) && $data[Parcel::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
253  $data[Parcel::FIELD_CREATED_AT] = $data[Parcel::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
254  }
255  return (object) $data;
256  }
257 }
setMeasurements(?ParcelMeasurements $measurements)
setItems(?DeliveryItemCollection $items)
__construct(?string $id=null, ?DateTimeImmutable $createdAt=null, ?ParcelMeasurements $measurements=null, ?TrackingData $trackingData=null, ?DeliveryItemCollection $items=null, ?Custom $custom=null)
Definition: ParcelModel.php:65
setCreatedAt(?DateTimeImmutable $createdAt)
setTrackingData(?TrackingData $trackingData)