1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Z38\SwissPayment\Message; |
4
|
|
|
|
5
|
|
|
use Z38\SwissPayment\Text; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* AbstractMessages eases message creation using DOM |
9
|
|
|
*/ |
10
|
|
|
abstract class AbstractMessage implements MessageInterface |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Builds the DOM of the actual message |
14
|
|
|
* |
15
|
|
|
* @param \DOMDocument $doc |
16
|
|
|
* |
17
|
|
|
* @return \DOMElement |
18
|
|
|
*/ |
19
|
|
|
abstract protected function buildDom(\DOMDocument $doc); |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Gets the name of the schema |
23
|
|
|
* |
24
|
|
|
* @return string |
25
|
|
|
*/ |
26
|
|
|
abstract protected function getSchemaName(); |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Gets the location of the schema |
30
|
|
|
* |
31
|
|
|
* @return string|null The location or null |
32
|
|
|
*/ |
33
|
|
|
abstract protected function getSchemaLocation(); |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Builds a DOM document of the message |
37
|
|
|
* |
38
|
|
|
* @return \DOMDocument |
39
|
|
|
*/ |
40
|
2 |
|
public function asDom() |
41
|
|
|
{ |
42
|
2 |
|
$schema = $this->getSchemaName(); |
43
|
2 |
|
$location = $this->getSchemaLocation(); |
44
|
|
|
|
45
|
2 |
|
$doc = new \DOMDocument('1.0', 'UTF-8'); |
46
|
2 |
|
$root = $doc->createElement('Document'); |
47
|
2 |
|
$root->setAttribute('xmlns', $schema); |
48
|
2 |
|
if ($location !== null) { |
49
|
2 |
|
$root->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); |
50
|
2 |
|
$root->setAttribute('xsi:schemaLocation', $schema.' '.$location); |
51
|
2 |
|
} |
52
|
2 |
|
$root->appendChild($this->buildDom($doc)); |
53
|
2 |
|
$doc->appendChild($root); |
54
|
|
|
|
55
|
2 |
|
return $doc; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* {@inheritdoc} |
60
|
|
|
*/ |
61
|
2 |
|
public function asXml() |
62
|
|
|
{ |
63
|
2 |
|
return $this->asDom()->saveXML(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Returns the name of the software used to create the message |
68
|
|
|
* |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
2 |
|
public function getSoftwareName() |
72
|
|
|
{ |
73
|
2 |
|
return 'Z38_SwissPayment'; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Returns the version of the software used to create the message |
78
|
|
|
* |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
2 |
|
public function getSoftwareVersion() |
82
|
|
|
{ |
83
|
2 |
|
return '0.7.0'; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Creates a DOM element which contains details about the software used to create the message |
88
|
|
|
* |
89
|
|
|
* @param \DOMDocument $doc |
90
|
|
|
* |
91
|
|
|
* @return \DOMElement |
92
|
|
|
*/ |
93
|
2 |
|
protected function buildContactDetails(\DOMDocument $doc) |
94
|
|
|
{ |
95
|
2 |
|
$root = $doc->createElement('CtctDtls'); |
96
|
|
|
|
97
|
2 |
|
$root->appendChild(Text::xml($doc, 'Nm', $this->getSoftwareName())); |
98
|
2 |
|
$root->appendChild(Text::xml($doc, 'Othr', $this->getSoftwareVersion())); |
99
|
|
|
|
100
|
2 |
|
return $root; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|