-
Notifications
You must be signed in to change notification settings - Fork 20
/
SoapMessage.php
262 lines (233 loc) · 5.26 KB
/
SoapMessage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<?php
/*
* This file is part of the BeSimpleSoapCommon.
*
* (c) Christian Kerl <[email protected]>
* (c) Francis Besset <[email protected]>
* (c) Andreas Schamberger <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace BeSimple\SoapCommon;
/**
* Base class for SoapRequest and SoapResponse.
*
* @author Christian Kerl <[email protected]>
* @author Andreas Schamberger <[email protected]>
*/
abstract class SoapMessage
{
/**
* $_SERVER key for 'Content-Type' header.
*
* @var string
*/
const CONTENT_TYPE_HEADER = 'CONTENT_TYPE';
/**
* $_SERVER key for 'Content-Type' header (with PHP cli-webserver)
*
* @var string
*/
const HTTP_CONTENT_TYPE_HEADER = 'HTTP_CONTENT_TYPE';
/**
* $_SERVER key for 'SOAPAction' header.
*
* @var string
*/
const SOAP_ACTION_HEADER = 'HTTP_SOAPACTION';
/**
* Content types for SOAP versions.
*
* @var array(string=>string)
*/
static protected $versionToContentTypeMap = array(
SOAP_1_1 => 'text/xml; charset=utf-8',
SOAP_1_2 => 'application/soap+xml; charset=utf-8'
);
/**
* SOAP action.
*
* @var string
*/
protected $action;
/**
* Mime attachments.
*
* @var array(\BeSimple\SoapCommon\Mime\Part)
*/
protected $attachments = array();
/**
* Message content (MIME Message or SOAP Envelope).
*
* @var string
*/
protected $content;
/**
*
* Enter description here ...
* @var \DOMDocument
*/
protected $contentDomDocument = null;
/**
* Message content type.
*
* @var string
*/
protected $contentType;
/**
* Service location.
*
* @var string
*/
protected $location;
/**
* SOAP version (SOAP_1_1|SOAP_1_2)
*
* @var string
*/
protected $version;
/**
* Get content type for given SOAP version.
*
* @param string $version SOAP version constant SOAP_1_1|SOAP_1_2
*
* @return string
* @throws \InvalidArgumentException
*/
public static function getContentTypeForVersion($version)
{
if (!in_array($version, array(SOAP_1_1, SOAP_1_2))) {
throw new \InvalidArgumentException("The 'version' argument has to be either 'SOAP_1_1' or 'SOAP_1_2'!");
}
return self::$versionToContentTypeMap[$version];
}
/**
* Get SOAP action.
*
* @return string
*/
public function getAction()
{
return $this->action;
}
/**
* Set SOAP action.
*
* @param string $action SOAP action
*/
public function setAction($action)
{
$this->action = $action;
}
/**
* Get attachments.
*
* @return array(\BeSimple\SoapCommon\Mime\Part)
*/
public function getAttachments()
{
return $this->attachments;
}
/**
* Set SOAP action.
*
* @param array(\BeSimple\SoapCommon\Mime\Part) $attachments Attachment array
*/
public function setAttachments(array $attachments)
{
$this->attachments = $attachments;
}
/**
* Get message content (MIME Message or SOAP Envelope).
*
* @return string
*/
public function getContent()
{
if (null !== $this->contentDomDocument) {
$this->content = $this->contentDomDocument->saveXML();
$this->contentDomDocument = null;
}
return $this->content;
}
/**
* Set message content (MIME Message or SOAP Envelope).
*
* @param string $content SOAP message
*/
public function setContent($content)
{
$this->content = $content;
if (null !== $this->contentDomDocument) {
$this->contentDomDocument->loadXML($this->content);
}
}
/**
* Get SOAP message as \DOMDocument
*
* @return \DOMDocument
*/
public function getContentDocument()
{
if (null === $this->contentDomDocument) {
$this->contentDomDocument = new \DOMDocument();
$this->contentDomDocument->loadXML($this->content);
}
return $this->contentDomDocument;
}
/**
* Get content type.
*
* @return string
*/
public function getContentType()
{
return $this->contentType;
}
/**
* Set content type.
*
* @param string $contentType Content type header
*/
public function setContentType($contentType)
{
$this->contentType = $contentType;
}
/**
* Get location.
*
* @return string
*/
public function getLocation()
{
return $this->location;
}
/**
* Set location.
*
* @param string $location Location string
*/
public function setLocation($location)
{
$this->location = $location;
}
/**
* Get version.
*
* @return string
*/
public function getVersion()
{
return $this->version;
}
/**
* Set version.
*
* @param string $version SOAP version SOAP_1_1|SOAP_1_2
*/
public function setVersion($version)
{
$this->version = $version;
}
}