|
1
|
|
|
<?php namespace SimpleUPS\Track\SmallPackage; |
|
2
|
|
|
|
|
3
|
|
|
use \SimpleUPS\Service; |
|
4
|
|
|
use \SimpleUPS\Shipper; |
|
5
|
|
|
use \SimpleUPS\InstructionalAddress; |
|
6
|
|
|
use \SimpleUPS\Track\ShipmentType; |
|
|
|
|
|
|
7
|
|
|
use \SimpleUPS\Track\Status; |
|
8
|
|
|
use \SimpleUPS\Track\ReferenceNumber; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* A shipment is associated with a tracking number and is made up of 1 or more packages |
|
12
|
|
|
* @since 1.0 |
|
13
|
|
|
*/ |
|
14
|
|
|
class Shipment extends \SimpleUPS\Shipment |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
private |
|
18
|
|
|
/* @var \SimpleUPS\Track\Status $status */ |
|
19
|
|
|
$status, |
|
20
|
|
|
/* @var \SimpleUPS\Track\ShipmentType $shipmentType */ |
|
21
|
|
|
$shipmentType, |
|
22
|
|
|
|
|
23
|
|
|
/* @var ReferenceNumber $referenceNumber */ |
|
24
|
|
|
$referenceNumber, |
|
25
|
|
|
/* @var string $shipmentIdentificationNumber */ |
|
26
|
|
|
$shipmentIdentificationNumber, |
|
27
|
|
|
|
|
28
|
|
|
/* @var \DateTime $pickupDate */ |
|
29
|
|
|
$pickupDate, |
|
30
|
|
|
/* @var Weight $weight */ |
|
31
|
|
|
$weight, |
|
32
|
|
|
|
|
33
|
|
|
/* @var \DateTime $deliveryTime */ |
|
34
|
|
|
$deliveryTime; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @internal |
|
38
|
|
|
* |
|
39
|
|
|
* @param \DateTime $deliveryTime |
|
40
|
|
|
* |
|
41
|
|
|
* @return Shipment |
|
42
|
|
|
*/ |
|
43
|
|
|
public function setDeliveryTime(\DateTime $deliveryTime) |
|
44
|
|
|
{ |
|
45
|
|
|
$this->deliveryTime = $deliveryTime; |
|
46
|
|
|
return $this; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* When the item was delivered |
|
51
|
|
|
* @see getStatus() |
|
52
|
|
|
* @return \DateTime |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getDeliveryTime() |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->deliveryTime; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @internal |
|
61
|
|
|
* |
|
62
|
|
|
* @param \DateTime $pickupDate |
|
63
|
|
|
* |
|
64
|
|
|
* @return Shipment |
|
65
|
|
|
*/ |
|
66
|
|
|
public function setPickupDate(\DateTime $pickupDate) |
|
67
|
|
|
{ |
|
68
|
|
|
$this->pickupDate = $pickupDate; |
|
69
|
|
|
return $this; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Date the shipment was picked up from the shipper |
|
74
|
|
|
* @return \DateTime |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getPickupDate() |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->pickupDate; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @internal |
|
83
|
|
|
* |
|
84
|
|
|
* @param \SimpleUPS\Track\ShipmentType $shipmentType |
|
85
|
|
|
* |
|
86
|
|
|
* @return Shipment |
|
87
|
|
|
*/ |
|
88
|
|
|
public function setShipmentType(\SimpleUPS\Track\ShipmentType $shipmentType) |
|
89
|
|
|
{ |
|
90
|
|
|
$this->shipmentType = $shipmentType; |
|
91
|
|
|
return $this; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* The type of shipment being tracked |
|
96
|
|
|
* @return string |
|
97
|
|
|
*/ |
|
98
|
|
|
public function getShipmentType() |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->shipmentType->getDescription(); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Determine if this shipment is a small package |
|
105
|
|
|
* @return bool |
|
106
|
|
|
*/ |
|
107
|
|
|
public function isSmallPackage() |
|
108
|
|
|
{ |
|
109
|
|
|
return ShipmentType::TYPE_SMALL_PACKAGE == $this->shipmentType->getCode(); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Determine if this shipment is freight |
|
114
|
|
|
* @return bool |
|
115
|
|
|
*/ |
|
116
|
|
|
public function isFreight() |
|
117
|
|
|
{ |
|
118
|
|
|
return ShipmentType::TYPE_FREIGHT == $this->shipmentType->getCode(); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Determine if this shipment is mail innovations |
|
123
|
|
|
* @return bool |
|
124
|
|
|
*/ |
|
125
|
|
|
public function isMailInnovation() |
|
126
|
|
|
{ |
|
127
|
|
|
return ShipmentType::TYPE_MAIL_INNOVATION == $this->shipmentType->getCode(); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @internal |
|
132
|
|
|
* |
|
133
|
|
|
* @param Status $status |
|
134
|
|
|
* |
|
135
|
|
|
* @return Shipment |
|
136
|
|
|
*/ |
|
137
|
|
|
public function setStatus(Status $status) |
|
138
|
|
|
{ |
|
139
|
|
|
$this->status = $status; |
|
140
|
|
|
return $this; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* Status of shipment |
|
145
|
|
|
* @return Status |
|
146
|
|
|
*/ |
|
147
|
|
|
public function getStatus() |
|
148
|
|
|
{ |
|
149
|
|
|
return $this->status; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @internal |
|
154
|
|
|
* |
|
155
|
|
|
* @param \SimpleUPS\Weight $weight |
|
156
|
|
|
* |
|
157
|
|
|
* @return Shipment |
|
158
|
|
|
*/ |
|
159
|
|
|
public function setWeight(\SimpleUPS\Weight $weight) |
|
160
|
|
|
{ |
|
161
|
|
|
$this->weight = $weight; |
|
162
|
|
|
return $this; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* Shipment weight |
|
167
|
|
|
* @return \SimpleUPS\Weight |
|
168
|
|
|
*/ |
|
169
|
|
|
public function getWeight() |
|
170
|
|
|
{ |
|
171
|
|
|
return $this->weight; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* @internal |
|
176
|
|
|
* |
|
177
|
|
|
* @param ReferenceNumber $referenceNumber |
|
178
|
|
|
* |
|
179
|
|
|
* @return Shipment |
|
180
|
|
|
*/ |
|
181
|
|
|
public function setReferenceNumber(ReferenceNumber $referenceNumber) |
|
182
|
|
|
{ |
|
183
|
|
|
$this->referenceNumber = $referenceNumber; |
|
184
|
|
|
return $this; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* Shipment reference number |
|
189
|
|
|
* @return ReferenceNumber |
|
190
|
|
|
*/ |
|
191
|
|
|
public function getReferenceNumber() |
|
192
|
|
|
{ |
|
193
|
|
|
return $this->referenceNumber; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* @internal |
|
198
|
|
|
* |
|
199
|
|
|
* @param string $shipmentIdentificationNumber |
|
200
|
|
|
* |
|
201
|
|
|
* @return Shipment |
|
202
|
|
|
*/ |
|
203
|
|
|
public function setShipmentIdentificationNumber($shipmentIdentificationNumber) |
|
204
|
|
|
{ |
|
205
|
|
|
$this->shipmentIdentificationNumber = (string)$shipmentIdentificationNumber; |
|
206
|
|
|
return $this; |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
/** |
|
210
|
|
|
* Shipment identification number |
|
211
|
|
|
* @return string |
|
212
|
|
|
*/ |
|
213
|
|
|
public function getShipmentIdentificationNumber() |
|
214
|
|
|
{ |
|
215
|
|
|
return $this->shipmentIdentificationNumber; |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* @internal |
|
220
|
|
|
* |
|
221
|
|
|
* @param \SimpleXMLElement $xml |
|
222
|
|
|
* |
|
223
|
|
|
* @return Shipment |
|
224
|
|
|
*/ |
|
225
|
|
|
public static function fromXml(\SimpleXMLElement $xml) |
|
226
|
|
|
{ |
|
227
|
|
|
$shipment = new Shipment(); |
|
228
|
|
|
$shipment->setIsResponse(); |
|
229
|
|
|
|
|
230
|
|
|
if (isset($xml->PickupDate)) { |
|
231
|
|
|
$shipment->setPickupDate(new \DateTime((string)$xml->PickupDate)); |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
View Code Duplication |
if (isset($xml->ScheduledDeliveryDate) && isset($xml->ScheduledDeliveryTime)) { |
|
|
|
|
|
|
235
|
|
|
$shipment->setDeliveryTime( |
|
236
|
|
|
new \DateTime((string)trim($xml->ScheduledDeliveryDate . ' ' . $xml->ScheduledDeliveryTime)) |
|
237
|
|
|
); |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
if (isset($xml->ShipmentType)) { |
|
241
|
|
|
$shipment->setShipmentType(ShipmentType::fromXml($xml->ShipmentType)); |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
if (isset($xml->Shipper)) { |
|
245
|
|
|
$shipment->setShipper(Shipper::fromXml($xml->Shipper)); |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
if (isset($xml->ShipTo->Address)) { |
|
249
|
|
|
$shipment->setDestination(InstructionalAddress::fromXml($xml->ShipTo->Address)); |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
if (isset($xml->Package)) { |
|
253
|
|
|
foreach ($xml->Package as $package) { |
|
254
|
|
|
$shipment->addPackage(Package::fromXml($package)); |
|
255
|
|
|
} |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
if (isset($xml->Service)) { |
|
259
|
|
|
$shipment->setService(Service::fromXml($xml->Service)); |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
if (isset($xml->CurrentStatus)) { |
|
263
|
|
|
$shipment->setStatus(Status::fromXml($xml->CurrentStatus)); |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
if (isset($xml->ReferenceNumber)) { |
|
267
|
|
|
$shipment->setReferenceNumber(ReferenceNumber::fromXml($xml->ReferenceNumber)); |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
if (isset($xml->ShipmentWeight)) { |
|
271
|
|
|
$shipment->setWeight(\SimpleUPS\Weight::fromXml($xml->ShipmentWeight)); |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
if (isset($xml->ShipmentIdentificationNumber)) { |
|
275
|
|
|
$shipment->setShipmentIdentificationNumber($xml->ShipmentIdentificationNumber); |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
return $shipment; |
|
279
|
|
|
|
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
} |
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: