1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ups\Entity; |
4
|
|
|
|
5
|
|
|
use DOMDocument; |
6
|
|
|
use DOMElement; |
7
|
|
|
use Ups\NodeInterface; |
8
|
|
|
|
9
|
|
|
class Dimensions implements NodeInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var int |
13
|
|
|
*/ |
14
|
|
|
private $length; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var int |
18
|
|
|
*/ |
19
|
|
|
private $width; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var int |
23
|
|
|
*/ |
24
|
|
|
private $height; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var UnitOfMeasurement |
28
|
|
|
*/ |
29
|
|
|
private $unitOfMeasurement; |
30
|
|
|
|
31
|
|
|
public function __construct($response = null) |
32
|
|
|
{ |
33
|
|
|
$this->setUnitOfMeasurement( |
34
|
|
|
new UnitOfMeasurement( |
35
|
|
|
isset($response->UnitOfMeasurement) ? $response->UnitOfMeasurement : null |
36
|
|
|
) |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
if (null !== $response) { |
40
|
|
|
if (isset($response->Length)) { |
41
|
|
|
$this->setLength($response->Length); |
42
|
|
|
} |
43
|
|
|
if (isset($response->Width)) { |
44
|
|
|
$this->setWidth($response->Width); |
45
|
|
|
} |
46
|
|
|
if (isset($response->Height)) { |
47
|
|
|
$this->setHeight($response->Height); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param null|DOMDocument $document |
54
|
|
|
* |
55
|
|
|
* @return DOMElement |
56
|
|
|
*/ |
57
|
|
|
public function toNode(DOMDocument $document = null) |
58
|
|
|
{ |
59
|
|
|
if (null === $document) { |
60
|
|
|
$document = new DOMDocument(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$node = $document->createElement('Dimensions'); |
64
|
|
|
$node->appendChild($document->createElement('Length', $this->getLength())); |
65
|
|
|
$node->appendChild($document->createElement('Height', $this->getHeight())); |
66
|
|
|
$node->appendChild($document->createElement('Width', $this->getWidth())); |
67
|
|
|
$node->appendChild($this->getUnitOfMeasurement()->toNode($document)); |
68
|
|
|
|
69
|
|
|
return $node; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return UnitOfMeasurement |
74
|
|
|
*/ |
75
|
|
|
public function getUnitOfMeasurement() |
76
|
|
|
{ |
77
|
|
|
return $this->unitOfMeasurement; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param UnitOfMeasurement $unitOfMeasurement |
82
|
|
|
* |
83
|
|
|
* @return $this |
84
|
|
|
*/ |
85
|
|
|
public function setUnitOfMeasurement(UnitOfMeasurement $unitOfMeasurement) |
86
|
|
|
{ |
87
|
|
|
$this->unitOfMeasurement = $unitOfMeasurement; |
88
|
|
|
|
89
|
|
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return int|null |
94
|
|
|
*/ |
95
|
|
|
public function getLength() |
96
|
|
|
{ |
97
|
|
|
return $this->length; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param int $var |
102
|
|
|
* @return Dimensions |
103
|
|
|
*/ |
104
|
|
|
public function setLength($var) |
105
|
|
|
{ |
106
|
|
|
$this->length = $var; |
107
|
|
|
|
108
|
|
|
return $this; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return int|null |
113
|
|
|
*/ |
114
|
|
|
public function getWidth() |
115
|
|
|
{ |
116
|
|
|
return $this->width; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @param int $var |
121
|
|
|
* @return Dimensions |
122
|
|
|
*/ |
123
|
|
|
public function setWidth($var) |
124
|
|
|
{ |
125
|
|
|
$this->width = $var; |
126
|
|
|
|
127
|
|
|
return $this; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return int|null |
132
|
|
|
*/ |
133
|
|
|
public function getHeight() |
134
|
|
|
{ |
135
|
|
|
return $this->height; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @param int $var |
140
|
|
|
* @return Dimensions |
141
|
|
|
*/ |
142
|
|
|
public function setHeight($var) |
143
|
|
|
{ |
144
|
|
|
$this->height = $var; |
145
|
|
|
|
146
|
|
|
return $this; |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|