1
|
|
|
<?php namespace SimpleUPS\Rates; |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Default |
6
|
|
|
* @since 1.0 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
class Package extends \SimpleUPS\Package |
10
|
|
|
{ |
11
|
|
|
const |
12
|
|
|
TYPE_UNKNOWN = '00', |
13
|
|
|
TYPE_UPS_LETTER = '01', |
14
|
|
|
TYPE_PACKAGE = '02', |
15
|
|
|
TYPE_TUBE = '03', |
16
|
|
|
TYPE_PAK = '04', |
17
|
|
|
TYPE_EXPRESS_BOX = '21', |
18
|
|
|
TYPE_25KG_BOX = '24', |
19
|
|
|
TYPE_10KG_BOX = '25', |
20
|
|
|
TYPE_PALLET = '30', |
21
|
|
|
TYPE_SMALL_EXPRESS_BOX = '2a', |
22
|
|
|
TYPE_MEDIUM_EXPRESS_BOX = '2b', |
23
|
|
|
TYPE_LARGE_EXPRESS_BOX = '2c'; |
24
|
|
|
|
25
|
|
|
private |
26
|
|
|
/* @var string $unitOfMeasurement */ |
27
|
|
|
$unitOfMeasurement = 'IN', |
28
|
|
|
|
29
|
|
|
/* @var string $type */ |
30
|
|
|
$type, |
31
|
|
|
/* @var float $length */ |
32
|
|
|
$length, |
33
|
|
|
|
34
|
|
|
/* @var float $width */ |
35
|
|
|
$width, |
36
|
|
|
|
37
|
|
|
/* @var float $height */ |
38
|
|
|
$height, |
39
|
|
|
|
40
|
|
|
/* @var float $insuranceAmount */ |
41
|
|
|
$insuranceAmount; |
42
|
|
|
|
43
|
|
|
private static |
44
|
|
|
$MEASUREMENT_INCHES = 'IN', |
45
|
|
|
$MEASUREMENT_CENTIMETERS = 'CM'; |
46
|
|
|
|
47
|
|
|
public function __construct() |
48
|
|
|
{ |
49
|
|
|
$this->measurement = self::$MEASUREMENT_INCHES; |
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Define this package as the dimensions being measured in inches |
54
|
|
|
*/ |
55
|
|
|
public function measuredInCentimeters() |
56
|
|
|
{ |
57
|
|
|
$this->setUnitOfMeasurement(self::$MEASUREMENT_CENTIMETERS); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param string $unitOfMeasurement |
62
|
|
|
* |
63
|
|
|
* @return Package |
64
|
|
|
*/ |
65
|
|
|
private function setUnitOfMeasurement($unitOfMeasurement) |
66
|
|
|
{ |
67
|
|
|
$this->unitOfMeasurement = $unitOfMeasurement; |
68
|
|
|
return $this; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
|
|
private function getUnitOfMeasurement() |
75
|
|
|
{ |
76
|
|
|
return $this->unitOfMeasurement; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Defines the type of package. "TYPE_PACKAGE" is default. Refer to class constants for possible values |
81
|
|
|
* |
82
|
|
|
* @param string $type |
83
|
|
|
* |
84
|
|
|
* @return Package |
85
|
|
|
*/ |
86
|
|
|
public function setType($type) |
87
|
|
|
{ |
88
|
|
|
$this->type = $type; |
89
|
|
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return float |
94
|
|
|
*/ |
95
|
|
|
public function getType() |
96
|
|
|
{ |
97
|
|
|
return $this->type; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param float $height |
102
|
|
|
* |
103
|
|
|
* @return Package |
104
|
|
|
*/ |
105
|
|
|
public function setHeight($height) |
106
|
|
|
{ |
107
|
|
|
$this->height = $height; |
108
|
|
|
return $this; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return float |
113
|
|
|
*/ |
114
|
|
|
public function getHeight() |
115
|
|
|
{ |
116
|
|
|
return $this->height; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @param float $length |
121
|
|
|
* |
122
|
|
|
* @return Package |
123
|
|
|
*/ |
124
|
|
|
public function setLength($length) |
125
|
|
|
{ |
126
|
|
|
$this->length = $length; |
127
|
|
|
return $this; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return float |
132
|
|
|
*/ |
133
|
|
|
public function getLength() |
134
|
|
|
{ |
135
|
|
|
return $this->length; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @param float $width |
140
|
|
|
* |
141
|
|
|
* @return Package |
142
|
|
|
*/ |
143
|
|
|
public function setWidth($width) |
144
|
|
|
{ |
145
|
|
|
$this->width = $width; |
146
|
|
|
return $this; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @return float |
151
|
|
|
*/ |
152
|
|
|
public function getWidth() |
153
|
|
|
{ |
154
|
|
|
return $this->width; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @internal |
159
|
|
|
* |
160
|
|
|
* @param \DomDocument $dom |
161
|
|
|
* |
162
|
|
|
* @return \DOMElement |
163
|
|
|
* @throw \SimpleUPS\Api\MissingParameterException |
164
|
|
|
*/ |
165
|
|
|
public function toXml(\DomDocument $dom) |
166
|
|
|
{ |
167
|
|
|
$package = $dom->createElement('Package'); |
168
|
|
|
|
169
|
|
|
if ($this->getType() == null) { |
170
|
|
|
$this->setType(Package::TYPE_PACKAGE); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
$package->appendChild($packagingType = $dom->createElement('PackagingType')); |
174
|
|
|
$packagingType->appendChild($dom->createElement('Code', $this->getType())); |
175
|
|
|
|
176
|
|
|
if ($this->getLength() != null || $this->getHeight() != null || $this->getWidth() != null) { |
177
|
|
|
$package->appendChild($dimensions = $dom->createElement('Dimensions')); |
178
|
|
|
$unitOfMeasurement = $dimensions->appendChild($dom->createElement('UnitOfMeasurement')); |
179
|
|
|
$unitOfMeasurement->appendChild($dom->createElement('Code', $this->getUnitOfMeasurement())); |
180
|
|
|
|
181
|
|
|
if ($this->getType() != Package::TYPE_UPS_LETTER && |
182
|
|
|
$this->getType() != Package::TYPE_TUBE && |
183
|
|
|
$this->getType() != Package::TYPE_EXPRESS_BOX |
184
|
|
|
) { |
185
|
|
|
|
186
|
|
|
if ($this->getLength() != null) { |
187
|
|
|
$dimensions->appendChild($dom->createElement('Length', $this->getLength())); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
if ($this->getHeight() != null) { |
191
|
|
|
$dimensions->appendChild($dom->createElement('Height', $this->getHeight())); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
if ($this->getWidth() != null) { |
195
|
|
|
$dimensions->appendChild($dom->createElement('Width', $this->getWidth())); |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
if ($this->getWeight() != null) { |
201
|
|
|
$package->appendChild($this->getWeight()->toXml($dom)); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
return $package; |
205
|
|
|
} |
206
|
|
|
} |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.