|
1
|
|
|
<?php namespace SimpleUPS; |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Contains information about the shipper |
|
5
|
|
|
* @since 1.0 |
|
6
|
|
|
*/ |
|
7
|
|
|
class Shipper extends Model |
|
8
|
|
|
{ |
|
9
|
|
|
private |
|
10
|
|
|
/* @var string $number */ |
|
11
|
|
|
$number, |
|
12
|
|
|
|
|
13
|
|
|
/* @var InstructionalAddress $address */ |
|
14
|
|
|
$address; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @internal |
|
18
|
|
|
* |
|
19
|
|
|
* @param InstructionalAddress $address |
|
20
|
|
|
* |
|
21
|
|
|
* @return Shipper |
|
22
|
|
|
*/ |
|
23
|
|
|
public function setAddress(\SimpleUPS\InstructionalAddress $address) |
|
24
|
|
|
{ |
|
25
|
|
|
$this->address = $address; |
|
26
|
|
|
return $this; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Get the shipper's address |
|
31
|
|
|
* @return InstructionalAddress |
|
32
|
|
|
*/ |
|
33
|
|
|
public function getAddress() |
|
34
|
|
|
{ |
|
35
|
|
|
return $this->address; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @internal |
|
40
|
|
|
* |
|
41
|
|
|
* @param string $number |
|
42
|
|
|
* |
|
43
|
|
|
* @return Shipper |
|
44
|
|
|
*/ |
|
45
|
|
|
public function setNumber($number) |
|
46
|
|
|
{ |
|
47
|
|
|
$this->number = (string)$number; |
|
48
|
|
|
return $this; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Get the shipper UPS account number |
|
53
|
|
|
* @return string |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getNumber() |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->number; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @internal |
|
62
|
|
|
* |
|
63
|
|
|
* @param \DomDocument $dom |
|
64
|
|
|
* |
|
65
|
|
|
* @return \DOMElement |
|
66
|
|
|
*/ |
|
67
|
|
|
public function toXml(\DomDocument $dom) |
|
68
|
|
|
{ |
|
69
|
|
|
$shipper = $dom->createElement('Shipper'); |
|
70
|
|
|
|
|
71
|
|
|
if ($this->getAddress()->getAddressee() != null) { |
|
72
|
|
|
$shipper->appendChild($dom->createElement('Name', $this->getAddress()->getAddressee())); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
if ($this->getNumber() != null) { |
|
76
|
|
|
$shipper->appendChild($dom->createElement('ShipperNumber', $this->getNumber())); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
if ($this->getAddress() != null) { |
|
80
|
|
|
$shipper->appendChild($this->getAddress()->toXml($dom)); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
return $shipper; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @internal |
|
88
|
|
|
* |
|
89
|
|
|
* @param \SimpleXMLElement $xml |
|
90
|
|
|
* |
|
91
|
|
|
* @return Shipper |
|
92
|
|
|
*/ |
|
93
|
|
|
public static function fromXml(\SimpleXMLElement $xml) |
|
94
|
|
|
{ |
|
95
|
|
|
$shipper = new Shipper(); |
|
96
|
|
|
$shipper->setIsResponse(); |
|
97
|
|
|
|
|
98
|
|
|
if (isset($xml->ShipperNumber)) { |
|
99
|
|
|
$shipper->setNumber($xml->ShipperNumber); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
if (isset($xml->Address)) { |
|
103
|
|
|
$shipper->setAddress(InstructionalAddress::fromXml($xml->Address)); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
return $shipper; |
|
107
|
|
|
} |
|
108
|
|
|
} |