@@ 12-86 (lines=75) @@ | ||
9 | /** |
|
10 | * Class Quantity. |
|
11 | */ |
|
12 | class Quantity implements NodeInterface |
|
13 | { |
|
14 | ||
15 | /** |
|
16 | * @var UnitOfMeasurement |
|
17 | */ |
|
18 | private $unitOfMeasurement; |
|
19 | ||
20 | /** |
|
21 | * @var int |
|
22 | */ |
|
23 | private $value; |
|
24 | ||
25 | /** |
|
26 | * @param null|DOMDocument $document |
|
27 | * |
|
28 | * @return DOMElement |
|
29 | */ |
|
30 | public function toNode(DOMDocument $document = null) |
|
31 | { |
|
32 | if (null === $document) { |
|
33 | $document = new DOMDocument(); |
|
34 | } |
|
35 | ||
36 | $node = $document->createElement('Quantity'); |
|
37 | ||
38 | // Required |
|
39 | $node->appendChild($document->createElement('Value', $this->getValue())); |
|
40 | ||
41 | // Optional |
|
42 | if ($this->getUnitOfMeasurement() instanceof UnitOfMeasurement) { |
|
43 | $node->appendChild($this->getUnitOfMeasurement()->toNode($document)); |
|
44 | } |
|
45 | ||
46 | return $node; |
|
47 | } |
|
48 | ||
49 | /** |
|
50 | * @return int |
|
51 | */ |
|
52 | public function getValue() |
|
53 | { |
|
54 | return $this->value; |
|
55 | } |
|
56 | ||
57 | /** |
|
58 | * @param int $value |
|
59 | * @return Quantity |
|
60 | */ |
|
61 | public function setValue($value) |
|
62 | { |
|
63 | $this->value = $value; |
|
64 | ||
65 | return $this; |
|
66 | } |
|
67 | ||
68 | /** |
|
69 | * @return UnitOfMeasurement |
|
70 | */ |
|
71 | public function getUnitOfMeasurement() |
|
72 | { |
|
73 | return $this->unitOfMeasurement; |
|
74 | } |
|
75 | ||
76 | /** |
|
77 | * @param UnitOfMeasurement $unitOfMeasurement |
|
78 | * @return Quantity |
|
79 | */ |
|
80 | public function setUnitOfMeasurement(UnitOfMeasurement $unitOfMeasurement) |
|
81 | { |
|
82 | $this->unitOfMeasurement = $unitOfMeasurement; |
|
83 | ||
84 | return $this; |
|
85 | } |
|
86 | } |
|
87 |
@@ 12-86 (lines=75) @@ | ||
9 | /** |
|
10 | * Class Weight |
|
11 | */ |
|
12 | class Weight implements NodeInterface |
|
13 | { |
|
14 | ||
15 | /** |
|
16 | * @var UnitOfMeasurement |
|
17 | */ |
|
18 | private $unitOfMeasurement; |
|
19 | ||
20 | /** |
|
21 | * @var int |
|
22 | */ |
|
23 | private $value; |
|
24 | ||
25 | /** |
|
26 | * @param null|DOMDocument $document |
|
27 | * |
|
28 | * @return DOMElement |
|
29 | */ |
|
30 | public function toNode(DOMDocument $document = null) |
|
31 | { |
|
32 | if (null === $document) { |
|
33 | $document = new DOMDocument(); |
|
34 | } |
|
35 | ||
36 | $node = $document->createElement('Weight'); |
|
37 | ||
38 | // Required |
|
39 | $node->appendChild($document->createElement('Value', $this->getValue())); |
|
40 | ||
41 | // Optional |
|
42 | if ($this->getUnitOfMeasurement() instanceof UnitOfMeasurement) { |
|
43 | $node->appendChild($this->getUnitOfMeasurement()->toNode($document)); |
|
44 | } |
|
45 | ||
46 | return $node; |
|
47 | } |
|
48 | ||
49 | /** |
|
50 | * @return int |
|
51 | */ |
|
52 | public function getValue() |
|
53 | { |
|
54 | return $this->value; |
|
55 | } |
|
56 | ||
57 | /** |
|
58 | * @param int $value |
|
59 | * @return Quantity |
|
60 | */ |
|
61 | public function setValue($value) |
|
62 | { |
|
63 | $this->value = $value; |
|
64 | ||
65 | return $this; |
|
66 | } |
|
67 | ||
68 | /** |
|
69 | * @return UnitOfMeasurement |
|
70 | */ |
|
71 | public function getUnitOfMeasurement() |
|
72 | { |
|
73 | return $this->unitOfMeasurement; |
|
74 | } |
|
75 | ||
76 | /** |
|
77 | * @param UnitOfMeasurement $unitOfMeasurement |
|
78 | * @return Quantity |
|
79 | */ |
|
80 | public function setUnitOfMeasurement(UnitOfMeasurement $unitOfMeasurement) |
|
81 | { |
|
82 | $this->unitOfMeasurement = $unitOfMeasurement; |
|
83 | ||
84 | return $this; |
|
85 | } |
|
86 | } |
|
87 |