1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Slince shipment tracker library |
4
|
|
|
* @author Tao <[email protected]> |
5
|
|
|
*/ |
6
|
|
|
namespace Slince\ShipmentTracking\Foundation; |
7
|
|
|
|
8
|
|
|
class Shipment implements ShipmentInterface, \JsonSerializable |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var ShipmentEvent[] |
12
|
|
|
*/ |
13
|
|
|
protected $events; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var float |
17
|
|
|
*/ |
18
|
|
|
protected $weight; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $weightUnit; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $origin; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $destination; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var \DateTime |
37
|
|
|
*/ |
38
|
|
|
protected $deliveredAt; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
protected $status; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var boolean |
47
|
|
|
*/ |
48
|
|
|
protected $isDelivered; |
49
|
|
|
|
50
|
|
|
public function __construct(array $events = [], $isDelivered = null) |
51
|
|
|
{ |
52
|
|
|
$this->events = $events; |
53
|
|
|
$this->isDelivered = $isDelivered; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return float |
58
|
|
|
*/ |
59
|
|
|
public function getWeight() |
60
|
|
|
{ |
61
|
|
|
return $this->weight; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param float $weight |
66
|
|
|
* @return Shipment |
67
|
|
|
*/ |
68
|
|
|
public function setWeight($weight) |
69
|
|
|
{ |
70
|
|
|
$this->weight = $weight; |
71
|
|
|
return $this; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
|
|
public function getWeightUnit() |
78
|
|
|
{ |
79
|
|
|
return $this->weightUnit; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param string $weightUnit |
84
|
|
|
* @return Shipment |
85
|
|
|
*/ |
86
|
|
|
public function setWeightUnit($weightUnit) |
87
|
|
|
{ |
88
|
|
|
$this->weightUnit = $weightUnit; |
89
|
|
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return string |
94
|
|
|
*/ |
95
|
|
|
public function getOrigin() |
96
|
|
|
{ |
97
|
|
|
return $this->origin; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param string $origin |
102
|
|
|
* @return Shipment |
103
|
|
|
*/ |
104
|
|
|
public function setOrigin($origin) |
105
|
|
|
{ |
106
|
|
|
$this->origin = $origin; |
107
|
|
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return string |
112
|
|
|
*/ |
113
|
|
|
public function getDestination() |
114
|
|
|
{ |
115
|
|
|
return $this->destination; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param string $destination |
120
|
|
|
* @return Shipment |
121
|
|
|
*/ |
122
|
|
|
public function setDestination($destination) |
123
|
|
|
{ |
124
|
|
|
$this->destination = $destination; |
125
|
|
|
return $this; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @return \DateTime |
130
|
|
|
*/ |
131
|
|
|
public function getDeliveredAt() |
132
|
|
|
{ |
133
|
|
|
return $this->deliveredAt; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @param \DateTime $deliveredAt |
138
|
|
|
* @return Shipment |
139
|
|
|
*/ |
140
|
|
|
public function setDeliveredAt($deliveredAt) |
141
|
|
|
{ |
142
|
|
|
$this->deliveredAt = $deliveredAt; |
143
|
|
|
return $this; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @param ShipmentEvent[] $events |
148
|
|
|
*/ |
149
|
|
|
public function setEvents($events) |
150
|
|
|
{ |
151
|
|
|
$this->events = $events; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @return ShipmentEvent[] |
156
|
|
|
*/ |
157
|
|
|
public function getEvents() |
158
|
|
|
{ |
159
|
|
|
return $this->events; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @return string |
164
|
|
|
*/ |
165
|
|
|
public function getStatus() |
166
|
|
|
{ |
167
|
|
|
return $this->status; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @param string $status |
172
|
|
|
* @return Shipment |
173
|
|
|
*/ |
174
|
|
|
public function setStatus($status) |
175
|
|
|
{ |
176
|
|
|
$this->status = $status; |
177
|
|
|
return $this; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @return bool |
182
|
|
|
*/ |
183
|
|
|
public function isDelivered() |
184
|
|
|
{ |
185
|
|
|
return $this->isDelivered; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @param bool $isDelivered |
190
|
|
|
* @return Shipment |
191
|
|
|
*/ |
192
|
|
|
public function setIsDelivered($isDelivered) |
193
|
|
|
{ |
194
|
|
|
$this->isDelivered = $isDelivered; |
195
|
|
|
return $this; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* {@inheritdoc} |
200
|
|
|
*/ |
201
|
|
|
public function jsonSerialize() |
202
|
|
|
{ |
203
|
|
|
return [ |
204
|
|
|
'is_delivered' => $this->isDelivered, |
205
|
|
|
'status' => $this->status, |
206
|
|
|
'weight' => $this->weight, |
207
|
|
|
'weight_unit' => $this->weightUnit, |
208
|
|
|
'origin' => $this->origin, |
209
|
|
|
'destination' => $this->destination, |
210
|
|
|
'delivered_at' => $this->deliveredAt, |
211
|
|
|
'events' => $this->events |
212
|
|
|
]; |
213
|
|
|
} |
214
|
|
|
} |
215
|
|
|
|