Passed
Branch feature/php-cs-fixer (263a85)
by Michael
02:49
created
src/nusoap.php 1 patch
Indentation   +7934 added lines, -7934 removed lines patch added patch discarded remove patch
@@ -85,840 +85,840 @@  discard block
 block discarded – undo
85 85
  */
86 86
 class nusoap_base
87 87
 {
88
-    /**
89
-     * Identification for HTTP headers.
90
-     *
91
-     * @var string
92
-     * @access private
93
-     */
94
-    protected $title = 'NuSOAP';
95
-    /**
96
-     * Version for HTTP headers.
97
-     *
98
-     * @var string
99
-     * @access private
100
-     */
101
-    protected $version = '0.9.6';
102
-    /**
103
-     * CVS revision for HTTP headers.
104
-     *
105
-     * @var string
106
-     * @access private
107
-     */
108
-    protected $revision = '$Revision: 1.123 $';
109
-    /**
110
-     * Current error string (manipulated by getError/setError)
111
-     *
112
-     * @var string
113
-     * @access private
114
-     */
115
-    protected $error_str = '';
116
-    /**
117
-     * Current debug string (manipulated by debug/appendDebug/clearDebug/getDebug/getDebugAsXMLComment)
118
-     *
119
-     * @var string
120
-     * @access private
121
-     */
122
-    private $debug_str = '';
123
-    /**
124
-     * toggles automatic encoding of special characters as entities
125
-     * (should always be true, I think)
126
-     *
127
-     * @var boolean
128
-     * @access private
129
-     */
130
-    private $charencoding = true;
131
-    /**
132
-     * the debug level for this instance
133
-     *
134
-     * @var    integer
135
-     * @access private
136
-     */
137
-    private $debugLevel;
88
+	/**
89
+	 * Identification for HTTP headers.
90
+	 *
91
+	 * @var string
92
+	 * @access private
93
+	 */
94
+	protected $title = 'NuSOAP';
95
+	/**
96
+	 * Version for HTTP headers.
97
+	 *
98
+	 * @var string
99
+	 * @access private
100
+	 */
101
+	protected $version = '0.9.6';
102
+	/**
103
+	 * CVS revision for HTTP headers.
104
+	 *
105
+	 * @var string
106
+	 * @access private
107
+	 */
108
+	protected $revision = '$Revision: 1.123 $';
109
+	/**
110
+	 * Current error string (manipulated by getError/setError)
111
+	 *
112
+	 * @var string
113
+	 * @access private
114
+	 */
115
+	protected $error_str = '';
116
+	/**
117
+	 * Current debug string (manipulated by debug/appendDebug/clearDebug/getDebug/getDebugAsXMLComment)
118
+	 *
119
+	 * @var string
120
+	 * @access private
121
+	 */
122
+	private $debug_str = '';
123
+	/**
124
+	 * toggles automatic encoding of special characters as entities
125
+	 * (should always be true, I think)
126
+	 *
127
+	 * @var boolean
128
+	 * @access private
129
+	 */
130
+	private $charencoding = true;
131
+	/**
132
+	 * the debug level for this instance
133
+	 *
134
+	 * @var    integer
135
+	 * @access private
136
+	 */
137
+	private $debugLevel;
138
+
139
+	/**
140
+	 * set schema version
141
+	 *
142
+	 * @var      string
143
+	 * @access   public
144
+	 */
145
+	public $XMLSchemaVersion = 'http://www.w3.org/2001/XMLSchema';
146
+
147
+	/**
148
+	 * charset encoding for outgoing messages
149
+	 *
150
+	 * @var      string
151
+	 * @access   public
152
+	 */
153
+	public $soap_defencoding = 'ISO-8859-1';
154
+	//var $soap_defencoding = 'UTF-8';
155
+
156
+	/**
157
+	 * namespaces in an array of prefix => uri
158
+	 *
159
+	 * this is "seeded" by a set of constants, but it may be altered by code
160
+	 *
161
+	 * @var      array
162
+	 * @access   public
163
+	 */
164
+	public $namespaces = [
165
+		'SOAP-ENV' => 'http://schemas.xmlsoap.org/soap/envelope/',
166
+		'xsd' => 'http://www.w3.org/2001/XMLSchema',
167
+		'xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
168
+		'SOAP-ENC' => 'http://schemas.xmlsoap.org/soap/encoding/'
169
+	];
170
+
171
+	/**
172
+	 * namespaces used in the current context, e.g. during serialization
173
+	 *
174
+	 * @var      array
175
+	 * @access   private
176
+	 */
177
+	protected $usedNamespaces = [];
178
+
179
+	/**
180
+	 * XML Schema types in an array of uri => (array of xml type => php type)
181
+	 * is this legacy yet?
182
+	 * no, this is used by the nusoap_xmlschema class to verify type => namespace mappings.
183
+	 *
184
+	 * @var      array
185
+	 * @access   public
186
+	 */
187
+	public $typemap = [
188
+		'http://www.w3.org/2001/XMLSchema' => [
189
+			'string' => 'string', 'boolean' => 'boolean', 'float' => 'double', 'double' => 'double', 'decimal' => 'double',
190
+			'duration' => '', 'dateTime' => 'string', 'time' => 'string', 'date' => 'string', 'gYearMonth' => '',
191
+			'gYear' => '', 'gMonthDay' => '', 'gDay' => '', 'gMonth' => '', 'hexBinary' => 'string', 'base64Binary' => 'string',
192
+			// abstract "any" types
193
+			'anyType' => 'string', 'anySimpleType' => 'string',
194
+			// derived datatypes
195
+			'normalizedString' => 'string', 'token' => 'string', 'language' => '', 'NMTOKEN' => '', 'NMTOKENS' => '', 'Name' => '', 'NCName' => '', 'ID' => '',
196
+			'IDREF' => '', 'IDREFS' => '', 'ENTITY' => '', 'ENTITIES' => '', 'integer' => 'integer', 'nonPositiveInteger' => 'integer',
197
+			'negativeInteger' => 'integer', 'long' => 'integer', 'int' => 'integer', 'short' => 'integer', 'byte' => 'integer', 'nonNegativeInteger' => 'integer',
198
+			'unsignedLong' => '', 'unsignedInt' => '', 'unsignedShort' => '', 'unsignedByte' => '', 'positiveInteger' => ''
199
+		],
200
+		'http://www.w3.org/2000/10/XMLSchema' => [
201
+			'i4' => '', 'int' => 'integer', 'boolean' => 'boolean', 'string' => 'string', 'double' => 'double',
202
+			'float' => 'double', 'dateTime' => 'string',
203
+			'timeInstant' => 'string', 'base64Binary' => 'string', 'base64' => 'string', 'ur-type' => 'array'
204
+		],
205
+		'http://www.w3.org/1999/XMLSchema' => [
206
+			'i4' => '', 'int' => 'integer', 'boolean' => 'boolean', 'string' => 'string', 'double' => 'double',
207
+			'float' => 'double', 'dateTime' => 'string',
208
+			'timeInstant' => 'string', 'base64Binary' => 'string', 'base64' => 'string', 'ur-type' => 'array'
209
+		],
210
+		'http://soapinterop.org/xsd' => ['SOAPStruct' => 'struct'],
211
+		'http://schemas.xmlsoap.org/soap/encoding/' => ['base64' => 'string', 'array' => 'array', 'Array' => 'array'],
212
+		'http://xml.apache.org/xml-soap' => ['Map']
213
+	];
214
+
215
+	/**
216
+	 * XML entities to convert
217
+	 *
218
+	 * @var      array
219
+	 * @access   public
220
+	 * @deprecated
221
+	 * @see    expandEntities
222
+	 */
223
+	public $xmlEntities = [
224
+		'quot' => '"', 'amp' => '&',
225
+		'lt'   => '<', 'gt' => '>', 'apos' => "'"
226
+	];
227
+
228
+	/**
229
+	 * constructor
230
+	 *
231
+	 * @access    public
232
+	 */
233
+	public function __construct()
234
+	{
235
+		$this->debugLevel = $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'];
236
+	}
138 237
 
139
-    /**
140
-     * set schema version
141
-     *
142
-     * @var      string
143
-     * @access   public
144
-     */
145
-    public $XMLSchemaVersion = 'http://www.w3.org/2001/XMLSchema';
238
+	/**
239
+	 * gets the global debug level, which applies to future instances
240
+	 *
241
+	 * @return    integer    Debug level 0-9, where 0 turns off
242
+	 * @access    public
243
+	 */
244
+	public function getGlobalDebugLevel()
245
+	{
246
+		return $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'];
247
+	}
146 248
 
147
-    /**
148
-     * charset encoding for outgoing messages
149
-     *
150
-     * @var      string
151
-     * @access   public
152
-     */
153
-    public $soap_defencoding = 'ISO-8859-1';
154
-    //var $soap_defencoding = 'UTF-8';
155
-
156
-    /**
157
-     * namespaces in an array of prefix => uri
158
-     *
159
-     * this is "seeded" by a set of constants, but it may be altered by code
160
-     *
161
-     * @var      array
162
-     * @access   public
163
-     */
164
-    public $namespaces = [
165
-        'SOAP-ENV' => 'http://schemas.xmlsoap.org/soap/envelope/',
166
-        'xsd' => 'http://www.w3.org/2001/XMLSchema',
167
-        'xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
168
-        'SOAP-ENC' => 'http://schemas.xmlsoap.org/soap/encoding/'
169
-    ];
170
-
171
-    /**
172
-     * namespaces used in the current context, e.g. during serialization
173
-     *
174
-     * @var      array
175
-     * @access   private
176
-     */
177
-    protected $usedNamespaces = [];
178
-
179
-    /**
180
-     * XML Schema types in an array of uri => (array of xml type => php type)
181
-     * is this legacy yet?
182
-     * no, this is used by the nusoap_xmlschema class to verify type => namespace mappings.
183
-     *
184
-     * @var      array
185
-     * @access   public
186
-     */
187
-    public $typemap = [
188
-        'http://www.w3.org/2001/XMLSchema' => [
189
-            'string' => 'string', 'boolean' => 'boolean', 'float' => 'double', 'double' => 'double', 'decimal' => 'double',
190
-            'duration' => '', 'dateTime' => 'string', 'time' => 'string', 'date' => 'string', 'gYearMonth' => '',
191
-            'gYear' => '', 'gMonthDay' => '', 'gDay' => '', 'gMonth' => '', 'hexBinary' => 'string', 'base64Binary' => 'string',
192
-            // abstract "any" types
193
-            'anyType' => 'string', 'anySimpleType' => 'string',
194
-            // derived datatypes
195
-            'normalizedString' => 'string', 'token' => 'string', 'language' => '', 'NMTOKEN' => '', 'NMTOKENS' => '', 'Name' => '', 'NCName' => '', 'ID' => '',
196
-            'IDREF' => '', 'IDREFS' => '', 'ENTITY' => '', 'ENTITIES' => '', 'integer' => 'integer', 'nonPositiveInteger' => 'integer',
197
-            'negativeInteger' => 'integer', 'long' => 'integer', 'int' => 'integer', 'short' => 'integer', 'byte' => 'integer', 'nonNegativeInteger' => 'integer',
198
-            'unsignedLong' => '', 'unsignedInt' => '', 'unsignedShort' => '', 'unsignedByte' => '', 'positiveInteger' => ''
199
-        ],
200
-        'http://www.w3.org/2000/10/XMLSchema' => [
201
-            'i4' => '', 'int' => 'integer', 'boolean' => 'boolean', 'string' => 'string', 'double' => 'double',
202
-            'float' => 'double', 'dateTime' => 'string',
203
-            'timeInstant' => 'string', 'base64Binary' => 'string', 'base64' => 'string', 'ur-type' => 'array'
204
-        ],
205
-        'http://www.w3.org/1999/XMLSchema' => [
206
-            'i4' => '', 'int' => 'integer', 'boolean' => 'boolean', 'string' => 'string', 'double' => 'double',
207
-            'float' => 'double', 'dateTime' => 'string',
208
-            'timeInstant' => 'string', 'base64Binary' => 'string', 'base64' => 'string', 'ur-type' => 'array'
209
-        ],
210
-        'http://soapinterop.org/xsd' => ['SOAPStruct' => 'struct'],
211
-        'http://schemas.xmlsoap.org/soap/encoding/' => ['base64' => 'string', 'array' => 'array', 'Array' => 'array'],
212
-        'http://xml.apache.org/xml-soap' => ['Map']
213
-    ];
214
-
215
-    /**
216
-     * XML entities to convert
217
-     *
218
-     * @var      array
219
-     * @access   public
220
-     * @deprecated
221
-     * @see    expandEntities
222
-     */
223
-    public $xmlEntities = [
224
-        'quot' => '"', 'amp' => '&',
225
-        'lt'   => '<', 'gt' => '>', 'apos' => "'"
226
-    ];
227
-
228
-    /**
229
-     * constructor
230
-     *
231
-     * @access    public
232
-     */
233
-    public function __construct()
234
-    {
235
-        $this->debugLevel = $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'];
236
-    }
237
-
238
-    /**
239
-     * gets the global debug level, which applies to future instances
240
-     *
241
-     * @return    integer    Debug level 0-9, where 0 turns off
242
-     * @access    public
243
-     */
244
-    public function getGlobalDebugLevel()
245
-    {
246
-        return $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'];
247
-    }
248
-
249
-    /**
250
-     * sets the global debug level, which applies to future instances
251
-     *
252
-     * @param    int $level Debug level 0-9, where 0 turns off
253
-     * @access    public
254
-     */
255
-    public function setGlobalDebugLevel($level)
256
-    {
257
-        $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'] = $level;
258
-    }
259
-
260
-    /**
261
-     * gets the debug level for this instance
262
-     *
263
-     * @return    int    Debug level 0-9, where 0 turns off
264
-     * @access    public
265
-     */
266
-    public function getDebugLevel()
267
-    {
268
-        return $this->debugLevel;
269
-    }
270
-
271
-    /**
272
-     * sets the debug level for this instance
273
-     *
274
-     * @param    int $level Debug level 0-9, where 0 turns off
275
-     * @access    public
276
-     */
277
-    public function setDebugLevel($level)
278
-    {
279
-        $this->debugLevel = $level;
280
-    }
281
-
282
-    /**
283
-     * adds debug data to the instance debug string with formatting
284
-     *
285
-     * @param    string $string debug data
286
-     * @access   private
287
-     */
288
-    protected function debug($string)
289
-    {
290
-        if ($this->debugLevel > 0) {
291
-            $this->appendDebug($this->getmicrotime() . ' ' . get_class($this) . ": $string\n");
292
-        }
293
-    }
294
-
295
-    /**
296
-     * adds debug data to the instance debug string without formatting
297
-     *
298
-     * @param    string $string debug data
299
-     * @access   public
300
-     */
301
-    public function appendDebug($string)
302
-    {
303
-        if ($this->debugLevel > 0) {
304
-            // it would be nice to use a memory stream here to use
305
-            // memory more efficiently
306
-            $this->debug_str .= $string;
307
-        }
308
-    }
309
-
310
-    /**
311
-     * clears the current debug data for this instance
312
-     *
313
-     * @access   public
314
-     */
315
-    public function clearDebug()
316
-    {
317
-        // it would be nice to use a memory stream here to use
318
-        // memory more efficiently
319
-        $this->debug_str = '';
320
-    }
321
-
322
-    /**
323
-     * gets the current debug data for this instance
324
-     *
325
-     * @return   string debug data
326
-     * @access   public
327
-     */
328
-    public function &getDebug()
329
-    {
330
-        // it would be nice to use a memory stream here to use
331
-        // memory more efficiently
332
-        return $this->debug_str;
333
-    }
334
-
335
-    /**
336
-     * gets the current debug data for this instance as an XML comment
337
-     * this may change the contents of the debug data
338
-     *
339
-     * @return   string debug data as an XML comment
340
-     * @access   public
341
-     */
342
-    public function &getDebugAsXMLComment()
343
-    {
344
-        // it would be nice to use a memory stream here to use
345
-        // memory more efficiently
346
-        while (strpos($this->debug_str, '--')) {
347
-            $this->debug_str = str_replace('--', '- -', $this->debug_str);
348
-        }
349
-        $ret = "<!--\n" . $this->debug_str . "\n-->";
350
-        return $ret;
351
-    }
352
-
353
-    /**
354
-     * expands entities, e.g. changes '<' to '&lt;'.
355
-     *
356
-     * @param    string $val The string in which to expand entities.
357
-     * @access    private
358
-     * @return mixed|string
359
-     */
360
-    protected function expandEntities($val)
361
-    {
362
-        if ($this->charencoding) {
363
-            $val = str_replace('&', '&amp;', $val);
364
-            $val = str_replace("'", '&apos;', $val);
365
-            $val = str_replace('"', '&quot;', $val);
366
-            $val = str_replace('<', '&lt;', $val);
367
-            $val = str_replace('>', '&gt;', $val);
368
-        }
369
-        return $val;
370
-    }
371
-
372
-    /**
373
-     * returns error string if present
374
-     *
375
-     * @return   mixed error string or false
376
-     * @access   public
377
-     */
378
-    public function getError()
379
-    {
380
-        if ('' != $this->error_str) {
381
-            return $this->error_str;
382
-        }
383
-        return false;
384
-    }
385
-
386
-    /**
387
-     * sets error string
388
-     *
389
-     * @param string $str
390
-     * @return void $string error string
391
-     * @access   private
392
-     */
393
-    protected function setError($str)
394
-    {
395
-        $this->error_str = $str;
396
-    }
397
-
398
-    /**
399
-     * detect if array is a simple array or a struct (associative array)
400
-     *
401
-     * @param    mixed $val The PHP array
402
-     * @return    string    (arraySimple|arrayStruct)
403
-     * @access    private
404
-     */
405
-    protected function isArraySimpleOrStruct($val)
406
-    {
407
-        $keyList = array_keys($val);
408
-        foreach ($keyList as $keyListValue) {
409
-            if (!is_int($keyListValue)) {
410
-                return 'arrayStruct';
411
-            }
412
-        }
413
-        return 'arraySimple';
414
-    }
415
-
416
-    /**
417
-     * serializes PHP values in accordance w/ section 5. Type information is
418
-     * not serialized if $use == 'literal'.
419
-     *
420
-     * @param    mixed    $val        The value to serialize
421
-     * @param bool|string $name       The name (local part) of the XML element
422
-     * @param bool|string $type       The XML schema type (local part) for the element
423
-     * @param bool|string $name_ns    The namespace for the name of the XML element
424
-     * @param bool|string $type_ns    The namespace for the type of the element
425
-     * @param bool|string|array $attributes The attributes to serialize as name=>value pairs
426
-     * @param    string   $use        The WSDL "use" (encoded|literal)
427
-     * @param    boolean  $soapval    Whether this is called from soapval.
428
-     * @return    string    The serialized element, possibly with child elements
429
-     * @access    public
430
-     */
431
-    public function serialize_val($val, $name = false, $type = false, $name_ns = false, $type_ns = false, $attributes = false, $use = 'encoded', $soapval = false)
432
-    {
433
-        $this->debug("in serialize_val: name=$name, type=$type, name_ns=$name_ns, type_ns=$type_ns, use=$use, soapval=$soapval");
434
-        $this->appendDebug('value=' . $this->varDump($val));
435
-        $this->appendDebug('attributes=' . $this->varDump($attributes));
436
-
437
-        if (is_object($val) && 'soapval' === get_class($val) && (!$soapval)) {
438
-            $this->debug('serialize_val: serialize soapval');
439
-            $xml = $val->serialize($use);
440
-            $this->appendDebug($val->getDebug());
441
-            $val->clearDebug();
442
-            $this->debug("serialize_val of soapval returning $xml");
443
-            return $xml;
444
-        }
445
-        // force valid name if necessary
446
-        if (is_numeric($name)) {
447
-            $name = '__numeric_' . $name;
448
-        } elseif (!$name) {
449
-            $name = 'noname';
450
-        }
451
-        // if name has ns, add ns prefix to name
452
-        $xmlns = '';
453
-        if ($name_ns) {
454
-            $prefix = 'nu' . mt_rand(1000, 9999);
455
-            $name = $prefix . ':' . $name;
456
-            $xmlns .= " xmlns:$prefix=\"$name_ns\"";
457
-        }
458
-        // if type is prefixed, create type prefix
459
-        if ('' != $type_ns && $type_ns == $this->namespaces['xsd']) {
460
-            // need to fix this. shouldn't default to xsd if no ns specified
461
-            // w/o checking against typemap
462
-            $type_prefix = 'xsd';
463
-        } elseif ($type_ns) {
464
-            $type_prefix = 'ns' . mt_rand(1000, 9999);
465
-            $xmlns .= " xmlns:$type_prefix=\"$type_ns\"";
466
-        }
467
-        // serialize attributes if present
468
-        $atts = '';
469
-        if ($attributes) {
470
-            foreach ($attributes as $k => $v) {
471
-                $atts .= " $k=\"" . $this->expandEntities($v) . '"';
472
-            }
473
-        }
474
-        // serialize null value
475
-        if (null === $val) {
476
-            $this->debug('serialize_val: serialize null');
477
-            if ('literal' === $use) {
478
-                // TODO: depends on minOccurs
479
-                $xml = "<$name$xmlns$atts/>";
480
-                $this->debug("serialize_val returning $xml");
481
-                return $xml;
482
-            } else {
483
-                if (isset($type) && isset($type_prefix)) {
484
-                    $type_str = " xsi:type=\"$type_prefix:$type\"";
485
-                } else {
486
-                    $type_str = '';
487
-                }
488
-                $xml = "<$name$xmlns$type_str$atts xsi:nil=\"true\"/>";
489
-                $this->debug("serialize_val returning $xml");
490
-                return $xml;
491
-            }
492
-        }
493
-        // serialize if an xsd built-in primitive type
494
-        if ('' != $type && isset($this->typemap[$this->XMLSchemaVersion][$type])) {
495
-            $this->debug('serialize_val: serialize xsd built-in primitive type');
496
-            if (is_bool($val)) {
497
-                if ('boolean' === $type) {
498
-                    $val = $val ? 'true' : 'false';
499
-                } elseif (!$val) {
500
-                    $val = 0;
501
-                }
502
-            } elseif (is_string($val)) {
503
-                $val = $this->expandEntities($val);
504
-            }
505
-            if ('literal' === $use) {
506
-                $xml = "<$name$xmlns$atts>$val</$name>";
507
-                $this->debug("serialize_val returning $xml");
508
-                return $xml;
509
-            } else {
510
-                $xml = "<$name$xmlns xsi:type=\"xsd:$type\"$atts>$val</$name>";
511
-                $this->debug("serialize_val returning $xml");
512
-                return $xml;
513
-            }
514
-        }
515
-        // detect type and serialize
516
-        $xml = '';
517
-        switch (true) {
518
-            case (is_bool($val) || 'boolean' === $type):
519
-                $this->debug('serialize_val: serialize boolean');
520
-                if ('boolean' === $type) {
521
-                    $val = $val ? 'true' : 'false';
522
-                } elseif (!$val) {
523
-                    $val = 0;
524
-                }
525
-                if ('literal' === $use) {
526
-                    $xml .= "<$name$xmlns$atts>$val</$name>";
527
-                } else {
528
-                    $xml .= "<$name$xmlns xsi:type=\"xsd:boolean\"$atts>$val</$name>";
529
-                }
530
-                break;
531
-            case (is_int($val) || is_int($val) || 'int' === $type):
532
-                $this->debug('serialize_val: serialize int');
533
-                if ('literal' === $use) {
534
-                    $xml .= "<$name$xmlns$atts>$val</$name>";
535
-                } else {
536
-                    $xml .= "<$name$xmlns xsi:type=\"xsd:int\"$atts>$val</$name>";
537
-                }
538
-                break;
539
-            case (is_float($val) || is_float($val) || 'float' === $type):
540
-                $this->debug('serialize_val: serialize float');
541
-                if ('literal' === $use) {
542
-                    $xml .= "<$name$xmlns$atts>$val</$name>";
543
-                } else {
544
-                    $xml .= "<$name$xmlns xsi:type=\"xsd:float\"$atts>$val</$name>";
545
-                }
546
-                break;
547
-            case (is_string($val) || 'string' === $type):
548
-                $this->debug('serialize_val: serialize string');
549
-                $val = $this->expandEntities($val);
550
-                if ('literal' === $use) {
551
-                    $xml .= "<$name$xmlns$atts>$val</$name>";
552
-                } else {
553
-                    $xml .= "<$name$xmlns xsi:type=\"xsd:string\"$atts>$val</$name>";
554
-                }
555
-                break;
556
-            case is_object($val):
557
-                $this->debug('serialize_val: serialize object');
558
-                if ('soapval' === get_class($val)) {
559
-                    $this->debug('serialize_val: serialize soapval object');
560
-                    $pXml = $val->serialize($use);
561
-                    $this->appendDebug($val->getDebug());
562
-                    $val->clearDebug();
563
-                } else {
564
-                    if (!$name) {
565
-                        $name = get_class($val);
566
-                        $this->debug("In serialize_val, used class name $name as element name");
567
-                    } else {
568
-                        $this->debug("In serialize_val, do not override name $name for element name for class " . get_class($val));
569
-                    }
570
-                    foreach (get_object_vars($val) as $k => $v) {
571
-                        $pXml = isset($pXml) ? $pXml . $this->serialize_val($v, $k, false, false, false, false, $use) : $this->serialize_val($v, $k, false, false, false, false, $use);
572
-                    }
573
-                }
574
-                if (isset($type) && isset($type_prefix)) {
575
-                    $type_str = " xsi:type=\"$type_prefix:$type\"";
576
-                } else {
577
-                    $type_str = '';
578
-                }
579
-                if ('literal' === $use) {
580
-                    $xml .= "<$name$xmlns$atts>$pXml</$name>";
581
-                } else {
582
-                    $xml .= "<$name$xmlns$type_str$atts>$pXml</$name>";
583
-                }
584
-                break;
585
-            case (is_array($val) || $type):
586
-                // detect if struct or array
587
-                $valueType = $this->isArraySimpleOrStruct($val);
588
-                if ('arraySimple' === $valueType || preg_match('/^ArrayOf/', $type)) {
589
-                    $this->debug('serialize_val: serialize array');
590
-                    $i = 0;
591
-                    if (is_array($val) && count($val) > 0) {
592
-                        foreach ($val as $v) {
593
-                            if (is_object($v) && 'soapval' === get_class($v)) {
594
-                                $tt_ns = $v->type_ns;
595
-                                $tt = $v->type;
596
-                            } elseif (is_array($v)) {
597
-                                $tt = $this->isArraySimpleOrStruct($v);
598
-                            } else {
599
-                                $tt = gettype($v);
600
-                            }
601
-                            $array_types[$tt] = 1;
602
-                            // TODO: for literal, the name should be $name
603
-                            $xml .= $this->serialize_val($v, 'item', false, false, false, false, $use);
604
-                            ++$i;
605
-                        }
606
-                        if (is_array($array_types) && count($array_types) > 1) {
607
-                            $array_typename = 'xsd:anyType';
608
-                        } elseif (isset($tt) && isset($this->typemap[$this->XMLSchemaVersion][$tt])) {
609
-                            if ('integer' === $tt) {
610
-                                $tt = 'int';
611
-                            }
612
-                            $array_typename = 'xsd:' . $tt;
613
-                        } elseif (isset($tt) && 'arraySimple' === $tt) {
614
-                            $array_typename = 'SOAP-ENC:Array';
615
-                        } elseif (isset($tt) && 'arrayStruct' === $tt) {
616
-                            $array_typename = 'unnamed_struct_use_soapval';
617
-                        } else {
618
-                            // if type is prefixed, create type prefix
619
-                            if ('' != $tt_ns && $tt_ns == $this->namespaces['xsd']) {
620
-                                $array_typename = 'xsd:' . $tt;
621
-                            } elseif ($tt_ns) {
622
-                                $tt_prefix = 'ns' . mt_rand(1000, 9999);
623
-                                $array_typename = "$tt_prefix:$tt";
624
-                                $xmlns .= " xmlns:$tt_prefix=\"$tt_ns\"";
625
-                            } else {
626
-                                $array_typename = $tt;
627
-                            }
628
-                        }
629
-                        $array_type = $i;
630
-                        if ('literal' === $use) {
631
-                            $type_str = '';
632
-                        } elseif (isset($type) && isset($type_prefix)) {
633
-                            $type_str = " xsi:type=\"$type_prefix:$type\"";
634
-                        } else {
635
-                            $type_str = ' xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="' . $array_typename . "[$array_type]\"";
636
-                        }
637
-                        // empty array
638
-                    } else {
639
-                        if ('literal' === $use) {
640
-                            $type_str = '';
641
-                        } elseif (isset($type) && isset($type_prefix)) {
642
-                            $type_str = " xsi:type=\"$type_prefix:$type\"";
643
-                        } else {
644
-                            $type_str = ' xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="xsd:anyType[0]"';
645
-                        }
646
-                    }
647
-                    // TODO: for array in literal, there is no wrapper here
648
-                    $xml = "<$name$xmlns$type_str$atts>" . $xml . "</$name>";
649
-                } else {
650
-                    // got a struct
651
-                    $this->debug('serialize_val: serialize struct');
652
-                    if (isset($type) && isset($type_prefix)) {
653
-                        $type_str = " xsi:type=\"$type_prefix:$type\"";
654
-                    } else {
655
-                        $type_str = '';
656
-                    }
657
-                    if ('literal' === $use) {
658
-                        $xml .= "<$name$xmlns$atts>";
659
-                    } else {
660
-                        $xml .= "<$name$xmlns$type_str$atts>";
661
-                    }
662
-                    foreach ($val as $k => $v) {
663
-                        // Apache Map
664
-                        if ('Map' === $type && 'http://xml.apache.org/xml-soap' === $type_ns) {
665
-                            $xml .= '<item>';
666
-                            $xml .= $this->serialize_val($k, 'key', false, false, false, false, $use);
667
-                            $xml .= $this->serialize_val($v, 'value', false, false, false, false, $use);
668
-                            $xml .= '</item>';
669
-                        } else {
670
-                            $xml .= $this->serialize_val($v, $k, false, false, false, false, $use);
671
-                        }
672
-                    }
673
-                    $xml .= "</$name>";
674
-                }
675
-                break;
676
-            default:
677
-                $this->debug('serialize_val: serialize unknown');
678
-                $xml .= 'not detected, got ' . gettype($val) . ' for ' . $val;
679
-                break;
680
-        }
681
-        $this->debug("serialize_val returning $xml");
682
-        return $xml;
683
-    }
684
-
685
-    /**
686
-     * serializes a message
687
-     *
688
-     * @param string $body the XML of the SOAP body
689
-     * @param mixed $headers optional string of XML with SOAP header content, or array of soapval objects for SOAP headers, or associative array
690
-     * @param array $namespaces optional the namespaces used in generating the body and headers
691
-     * @param string $style optional (rpc|document)
692
-     * @param string $use optional (encoded|literal)
693
-     * @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
694
-     * @return string the message
695
-     * @access public
696
-     */
697
-    public function serializeEnvelope($body, $headers = false, $namespaces = [], $style = 'rpc', $use = 'encoded', $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/')
698
-    {
699
-        // TODO: add an option to automatically run utf8_encode on $body and $headers
700
-        // if $this->soap_defencoding is UTF-8.  Not doing this automatically allows
701
-        // one to send arbitrary UTF-8 characters, not just characters that map to ISO-8859-1
702
-
703
-        $this->debug('In serializeEnvelope length=' . strlen($body) . ' body (max 1000 characters)=' . substr($body, 0, 1000) . " style=$style use=$use encodingStyle=$encodingStyle");
704
-        $this->debug('headers:');
705
-        $this->appendDebug($this->varDump($headers));
706
-        $this->debug('namespaces:');
707
-        $this->appendDebug($this->varDump($namespaces));
708
-
709
-        // serialize namespaces
710
-        $ns_string = '';
711
-        foreach (array_merge($this->namespaces, $namespaces) as $k => $v) {
712
-            $ns_string .= " xmlns:$k=\"$v\"";
713
-        }
714
-        if ($encodingStyle) {
715
-            $ns_string = " SOAP-ENV:encodingStyle=\"$encodingStyle\"$ns_string";
716
-        }
717
-
718
-        // serialize headers
719
-        if ($headers) {
720
-            if (is_array($headers)) {
721
-                $xml = '';
722
-                foreach ($headers as $k => $v) {
723
-                    if (is_object($v) && 'soapval' === get_class($v)) {
724
-                        $xml .= $this->serialize_val($v, false, false, false, false, false, $use);
725
-                    } else {
726
-                        $xml .= $this->serialize_val($v, $k, false, false, false, false, $use);
727
-                    }
728
-                }
729
-                $headers = $xml;
730
-                $this->debug("In serializeEnvelope, serialized array of headers to $headers");
731
-            }
732
-            $headers = '<SOAP-ENV:Header>' . $headers . '</SOAP-ENV:Header>';
733
-        }
734
-        // serialize envelope
735
-        return
736
-            '<?xml version="1.0" encoding="' . $this->soap_defencoding . '"?' . '>' .
737
-            '<SOAP-ENV:Envelope' . $ns_string . '>' .
738
-            $headers . '<SOAP-ENV:Body>' .
739
-            $body . '</SOAP-ENV:Body>' . '</SOAP-ENV:Envelope>';
740
-    }
741
-
742
-    /**
743
-     * formats a string to be inserted into an HTML stream
744
-     *
745
-     * @param string $str The string to format
746
-     * @return string The formatted string
747
-     * @access public
748
-     * @deprecated
749
-     */
750
-    public function formatDump($str)
751
-    {
752
-        $str = htmlspecialchars($str);
753
-        return nl2br($str);
754
-    }
755
-
756
-    /**
757
-     * contracts (changes namespace to prefix) a qualified name
758
-     *
759
-     * @param    string $qname qname
760
-     * @return    string contracted qname
761
-     * @access   private
762
-     */
763
-    protected function contractQName($qname)
764
-    {
765
-        // get element namespace
766
-        //$this->xdebug("Contract $qname");
767
-        if (strrpos($qname, ':')) {
768
-            // get unqualified name
769
-            $name = substr($qname, strrpos($qname, ':') + 1);
770
-            // get ns
771
-            $ns = substr($qname, 0, strrpos($qname, ':'));
772
-            $p = $this->getPrefixFromNamespace($ns);
773
-            if ($p) {
774
-                return $p . ':' . $name;
775
-            }
776
-            return $qname;
777
-        } else {
778
-            return $qname;
779
-        }
780
-    }
781
-
782
-    /**
783
-     * expands (changes prefix to namespace) a qualified name
784
-     *
785
-     * @param    string $qname qname
786
-     * @return    string expanded qname
787
-     * @access   private
788
-     */
789
-    protected function expandQname($qname)
790
-    {
791
-        // get element prefix
792
-        if (strpos($qname, ':') && !preg_match('/^http:\/\//', $qname)) {
793
-            // get unqualified name
794
-            $name = substr(strstr($qname, ':'), 1);
795
-            // get ns prefix
796
-            $prefix = substr($qname, 0, strpos($qname, ':'));
797
-            if (isset($this->namespaces[$prefix])) {
798
-                return $this->namespaces[$prefix] . ':' . $name;
799
-            } else {
800
-                return $qname;
801
-            }
802
-        } else {
803
-            return $qname;
804
-        }
805
-    }
806
-
807
-    /**
808
-     * returns the local part of a prefixed string
809
-     * returns the original string, if not prefixed
810
-     *
811
-     * @param string $str The prefixed string
812
-     * @return string The local part
813
-     * @access public
814
-     */
815
-    public function getLocalPart($str)
816
-    {
817
-        if (false !== ($sstr = strrchr($str, ':'))) {
818
-            // get unqualified name
819
-            return substr($sstr, 1);
820
-        } else {
821
-            return $str;
822
-        }
823
-    }
824
-
825
-    /**
826
-     * returns the prefix part of a prefixed string
827
-     * returns false, if not prefixed
828
-     *
829
-     * @param string $str The prefixed string
830
-     * @return mixed The prefix or false if there is no prefix
831
-     * @access public
832
-     */
833
-    public function getPrefix($str)
834
-    {
835
-        if (false !== ($pos = strrpos($str, ':'))) {
836
-            // get prefix
837
-            return substr($str, 0, $pos);
838
-        }
839
-        return false;
840
-    }
841
-
842
-    /**
843
-     * pass it a prefix, it returns a namespace
844
-     *
845
-     * @param string $prefix The prefix
846
-     * @return mixed The namespace, false if no namespace has the specified prefix
847
-     * @access public
848
-     */
849
-    public function getNamespaceFromPrefix($prefix)
850
-    {
851
-        if (isset($this->namespaces[$prefix])) {
852
-            return $this->namespaces[$prefix];
853
-        }
854
-        //$this->setError("No namespace registered for prefix '$prefix'");
855
-        return false;
856
-    }
857
-
858
-    /**
859
-     * returns the prefix for a given namespace (or prefix)
860
-     * or false if no prefixes registered for the given namespace
861
-     *
862
-     * @param string $ns The namespace
863
-     * @return mixed The prefix, false if the namespace has no prefixes
864
-     * @access public
865
-     */
866
-    public function getPrefixFromNamespace($ns)
867
-    {
868
-        foreach ($this->namespaces as $p => $n) {
869
-            if ($ns == $n || $ns == $p) {
870
-                $this->usedNamespaces[$p] = $n;
871
-                return $p;
872
-            }
873
-        }
874
-        return false;
875
-    }
876
-
877
-    /**
878
-     * returns the time in ODBC canonical form with microseconds
879
-     *
880
-     * @return string The time in ODBC canonical form with microseconds
881
-     * @access public
882
-     */
883
-    public function getmicrotime()
884
-    {
885
-        if (function_exists('gettimeofday')) {
886
-            $tod = gettimeofday();
887
-            $sec = $tod['sec'];
888
-            $usec = $tod['usec'];
889
-        } else {
890
-            $sec = time();
891
-            $usec = 0;
892
-        }
893
-        return strftime('%Y-%m-%d %H:%M:%S', $sec) . '.' . sprintf('%06d', $usec);
894
-    }
895
-
896
-    /**
897
-     * Returns a string with the output of var_dump
898
-     *
899
-     * @param mixed $data The variable to var_dump
900
-     * @return string The output of var_dump
901
-     * @access public
902
-     */
903
-    public function varDump($data)
904
-    {
905
-        ob_start();
906
-        var_dump($data);
907
-        $ret_val = ob_get_contents();
908
-        ob_end_clean();
909
-        return $ret_val;
910
-    }
911
-
912
-    /**
913
-     * represents the object as a string
914
-     *
915
-     * @return    string
916
-     * @access   public
917
-     */
918
-    public function __toString()
919
-    {
920
-        return $this->varDump($this);
921
-    }
249
+	/**
250
+	 * sets the global debug level, which applies to future instances
251
+	 *
252
+	 * @param    int $level Debug level 0-9, where 0 turns off
253
+	 * @access    public
254
+	 */
255
+	public function setGlobalDebugLevel($level)
256
+	{
257
+		$GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'] = $level;
258
+	}
259
+
260
+	/**
261
+	 * gets the debug level for this instance
262
+	 *
263
+	 * @return    int    Debug level 0-9, where 0 turns off
264
+	 * @access    public
265
+	 */
266
+	public function getDebugLevel()
267
+	{
268
+		return $this->debugLevel;
269
+	}
270
+
271
+	/**
272
+	 * sets the debug level for this instance
273
+	 *
274
+	 * @param    int $level Debug level 0-9, where 0 turns off
275
+	 * @access    public
276
+	 */
277
+	public function setDebugLevel($level)
278
+	{
279
+		$this->debugLevel = $level;
280
+	}
281
+
282
+	/**
283
+	 * adds debug data to the instance debug string with formatting
284
+	 *
285
+	 * @param    string $string debug data
286
+	 * @access   private
287
+	 */
288
+	protected function debug($string)
289
+	{
290
+		if ($this->debugLevel > 0) {
291
+			$this->appendDebug($this->getmicrotime() . ' ' . get_class($this) . ": $string\n");
292
+		}
293
+	}
294
+
295
+	/**
296
+	 * adds debug data to the instance debug string without formatting
297
+	 *
298
+	 * @param    string $string debug data
299
+	 * @access   public
300
+	 */
301
+	public function appendDebug($string)
302
+	{
303
+		if ($this->debugLevel > 0) {
304
+			// it would be nice to use a memory stream here to use
305
+			// memory more efficiently
306
+			$this->debug_str .= $string;
307
+		}
308
+	}
309
+
310
+	/**
311
+	 * clears the current debug data for this instance
312
+	 *
313
+	 * @access   public
314
+	 */
315
+	public function clearDebug()
316
+	{
317
+		// it would be nice to use a memory stream here to use
318
+		// memory more efficiently
319
+		$this->debug_str = '';
320
+	}
321
+
322
+	/**
323
+	 * gets the current debug data for this instance
324
+	 *
325
+	 * @return   string debug data
326
+	 * @access   public
327
+	 */
328
+	public function &getDebug()
329
+	{
330
+		// it would be nice to use a memory stream here to use
331
+		// memory more efficiently
332
+		return $this->debug_str;
333
+	}
334
+
335
+	/**
336
+	 * gets the current debug data for this instance as an XML comment
337
+	 * this may change the contents of the debug data
338
+	 *
339
+	 * @return   string debug data as an XML comment
340
+	 * @access   public
341
+	 */
342
+	public function &getDebugAsXMLComment()
343
+	{
344
+		// it would be nice to use a memory stream here to use
345
+		// memory more efficiently
346
+		while (strpos($this->debug_str, '--')) {
347
+			$this->debug_str = str_replace('--', '- -', $this->debug_str);
348
+		}
349
+		$ret = "<!--\n" . $this->debug_str . "\n-->";
350
+		return $ret;
351
+	}
352
+
353
+	/**
354
+	 * expands entities, e.g. changes '<' to '&lt;'.
355
+	 *
356
+	 * @param    string $val The string in which to expand entities.
357
+	 * @access    private
358
+	 * @return mixed|string
359
+	 */
360
+	protected function expandEntities($val)
361
+	{
362
+		if ($this->charencoding) {
363
+			$val = str_replace('&', '&amp;', $val);
364
+			$val = str_replace("'", '&apos;', $val);
365
+			$val = str_replace('"', '&quot;', $val);
366
+			$val = str_replace('<', '&lt;', $val);
367
+			$val = str_replace('>', '&gt;', $val);
368
+		}
369
+		return $val;
370
+	}
371
+
372
+	/**
373
+	 * returns error string if present
374
+	 *
375
+	 * @return   mixed error string or false
376
+	 * @access   public
377
+	 */
378
+	public function getError()
379
+	{
380
+		if ('' != $this->error_str) {
381
+			return $this->error_str;
382
+		}
383
+		return false;
384
+	}
385
+
386
+	/**
387
+	 * sets error string
388
+	 *
389
+	 * @param string $str
390
+	 * @return void $string error string
391
+	 * @access   private
392
+	 */
393
+	protected function setError($str)
394
+	{
395
+		$this->error_str = $str;
396
+	}
397
+
398
+	/**
399
+	 * detect if array is a simple array or a struct (associative array)
400
+	 *
401
+	 * @param    mixed $val The PHP array
402
+	 * @return    string    (arraySimple|arrayStruct)
403
+	 * @access    private
404
+	 */
405
+	protected function isArraySimpleOrStruct($val)
406
+	{
407
+		$keyList = array_keys($val);
408
+		foreach ($keyList as $keyListValue) {
409
+			if (!is_int($keyListValue)) {
410
+				return 'arrayStruct';
411
+			}
412
+		}
413
+		return 'arraySimple';
414
+	}
415
+
416
+	/**
417
+	 * serializes PHP values in accordance w/ section 5. Type information is
418
+	 * not serialized if $use == 'literal'.
419
+	 *
420
+	 * @param    mixed    $val        The value to serialize
421
+	 * @param bool|string $name       The name (local part) of the XML element
422
+	 * @param bool|string $type       The XML schema type (local part) for the element
423
+	 * @param bool|string $name_ns    The namespace for the name of the XML element
424
+	 * @param bool|string $type_ns    The namespace for the type of the element
425
+	 * @param bool|string|array $attributes The attributes to serialize as name=>value pairs
426
+	 * @param    string   $use        The WSDL "use" (encoded|literal)
427
+	 * @param    boolean  $soapval    Whether this is called from soapval.
428
+	 * @return    string    The serialized element, possibly with child elements
429
+	 * @access    public
430
+	 */
431
+	public function serialize_val($val, $name = false, $type = false, $name_ns = false, $type_ns = false, $attributes = false, $use = 'encoded', $soapval = false)
432
+	{
433
+		$this->debug("in serialize_val: name=$name, type=$type, name_ns=$name_ns, type_ns=$type_ns, use=$use, soapval=$soapval");
434
+		$this->appendDebug('value=' . $this->varDump($val));
435
+		$this->appendDebug('attributes=' . $this->varDump($attributes));
436
+
437
+		if (is_object($val) && 'soapval' === get_class($val) && (!$soapval)) {
438
+			$this->debug('serialize_val: serialize soapval');
439
+			$xml = $val->serialize($use);
440
+			$this->appendDebug($val->getDebug());
441
+			$val->clearDebug();
442
+			$this->debug("serialize_val of soapval returning $xml");
443
+			return $xml;
444
+		}
445
+		// force valid name if necessary
446
+		if (is_numeric($name)) {
447
+			$name = '__numeric_' . $name;
448
+		} elseif (!$name) {
449
+			$name = 'noname';
450
+		}
451
+		// if name has ns, add ns prefix to name
452
+		$xmlns = '';
453
+		if ($name_ns) {
454
+			$prefix = 'nu' . mt_rand(1000, 9999);
455
+			$name = $prefix . ':' . $name;
456
+			$xmlns .= " xmlns:$prefix=\"$name_ns\"";
457
+		}
458
+		// if type is prefixed, create type prefix
459
+		if ('' != $type_ns && $type_ns == $this->namespaces['xsd']) {
460
+			// need to fix this. shouldn't default to xsd if no ns specified
461
+			// w/o checking against typemap
462
+			$type_prefix = 'xsd';
463
+		} elseif ($type_ns) {
464
+			$type_prefix = 'ns' . mt_rand(1000, 9999);
465
+			$xmlns .= " xmlns:$type_prefix=\"$type_ns\"";
466
+		}
467
+		// serialize attributes if present
468
+		$atts = '';
469
+		if ($attributes) {
470
+			foreach ($attributes as $k => $v) {
471
+				$atts .= " $k=\"" . $this->expandEntities($v) . '"';
472
+			}
473
+		}
474
+		// serialize null value
475
+		if (null === $val) {
476
+			$this->debug('serialize_val: serialize null');
477
+			if ('literal' === $use) {
478
+				// TODO: depends on minOccurs
479
+				$xml = "<$name$xmlns$atts/>";
480
+				$this->debug("serialize_val returning $xml");
481
+				return $xml;
482
+			} else {
483
+				if (isset($type) && isset($type_prefix)) {
484
+					$type_str = " xsi:type=\"$type_prefix:$type\"";
485
+				} else {
486
+					$type_str = '';
487
+				}
488
+				$xml = "<$name$xmlns$type_str$atts xsi:nil=\"true\"/>";
489
+				$this->debug("serialize_val returning $xml");
490
+				return $xml;
491
+			}
492
+		}
493
+		// serialize if an xsd built-in primitive type
494
+		if ('' != $type && isset($this->typemap[$this->XMLSchemaVersion][$type])) {
495
+			$this->debug('serialize_val: serialize xsd built-in primitive type');
496
+			if (is_bool($val)) {
497
+				if ('boolean' === $type) {
498
+					$val = $val ? 'true' : 'false';
499
+				} elseif (!$val) {
500
+					$val = 0;
501
+				}
502
+			} elseif (is_string($val)) {
503
+				$val = $this->expandEntities($val);
504
+			}
505
+			if ('literal' === $use) {
506
+				$xml = "<$name$xmlns$atts>$val</$name>";
507
+				$this->debug("serialize_val returning $xml");
508
+				return $xml;
509
+			} else {
510
+				$xml = "<$name$xmlns xsi:type=\"xsd:$type\"$atts>$val</$name>";
511
+				$this->debug("serialize_val returning $xml");
512
+				return $xml;
513
+			}
514
+		}
515
+		// detect type and serialize
516
+		$xml = '';
517
+		switch (true) {
518
+			case (is_bool($val) || 'boolean' === $type):
519
+				$this->debug('serialize_val: serialize boolean');
520
+				if ('boolean' === $type) {
521
+					$val = $val ? 'true' : 'false';
522
+				} elseif (!$val) {
523
+					$val = 0;
524
+				}
525
+				if ('literal' === $use) {
526
+					$xml .= "<$name$xmlns$atts>$val</$name>";
527
+				} else {
528
+					$xml .= "<$name$xmlns xsi:type=\"xsd:boolean\"$atts>$val</$name>";
529
+				}
530
+				break;
531
+			case (is_int($val) || is_int($val) || 'int' === $type):
532
+				$this->debug('serialize_val: serialize int');
533
+				if ('literal' === $use) {
534
+					$xml .= "<$name$xmlns$atts>$val</$name>";
535
+				} else {
536
+					$xml .= "<$name$xmlns xsi:type=\"xsd:int\"$atts>$val</$name>";
537
+				}
538
+				break;
539
+			case (is_float($val) || is_float($val) || 'float' === $type):
540
+				$this->debug('serialize_val: serialize float');
541
+				if ('literal' === $use) {
542
+					$xml .= "<$name$xmlns$atts>$val</$name>";
543
+				} else {
544
+					$xml .= "<$name$xmlns xsi:type=\"xsd:float\"$atts>$val</$name>";
545
+				}
546
+				break;
547
+			case (is_string($val) || 'string' === $type):
548
+				$this->debug('serialize_val: serialize string');
549
+				$val = $this->expandEntities($val);
550
+				if ('literal' === $use) {
551
+					$xml .= "<$name$xmlns$atts>$val</$name>";
552
+				} else {
553
+					$xml .= "<$name$xmlns xsi:type=\"xsd:string\"$atts>$val</$name>";
554
+				}
555
+				break;
556
+			case is_object($val):
557
+				$this->debug('serialize_val: serialize object');
558
+				if ('soapval' === get_class($val)) {
559
+					$this->debug('serialize_val: serialize soapval object');
560
+					$pXml = $val->serialize($use);
561
+					$this->appendDebug($val->getDebug());
562
+					$val->clearDebug();
563
+				} else {
564
+					if (!$name) {
565
+						$name = get_class($val);
566
+						$this->debug("In serialize_val, used class name $name as element name");
567
+					} else {
568
+						$this->debug("In serialize_val, do not override name $name for element name for class " . get_class($val));
569
+					}
570
+					foreach (get_object_vars($val) as $k => $v) {
571
+						$pXml = isset($pXml) ? $pXml . $this->serialize_val($v, $k, false, false, false, false, $use) : $this->serialize_val($v, $k, false, false, false, false, $use);
572
+					}
573
+				}
574
+				if (isset($type) && isset($type_prefix)) {
575
+					$type_str = " xsi:type=\"$type_prefix:$type\"";
576
+				} else {
577
+					$type_str = '';
578
+				}
579
+				if ('literal' === $use) {
580
+					$xml .= "<$name$xmlns$atts>$pXml</$name>";
581
+				} else {
582
+					$xml .= "<$name$xmlns$type_str$atts>$pXml</$name>";
583
+				}
584
+				break;
585
+			case (is_array($val) || $type):
586
+				// detect if struct or array
587
+				$valueType = $this->isArraySimpleOrStruct($val);
588
+				if ('arraySimple' === $valueType || preg_match('/^ArrayOf/', $type)) {
589
+					$this->debug('serialize_val: serialize array');
590
+					$i = 0;
591
+					if (is_array($val) && count($val) > 0) {
592
+						foreach ($val as $v) {
593
+							if (is_object($v) && 'soapval' === get_class($v)) {
594
+								$tt_ns = $v->type_ns;
595
+								$tt = $v->type;
596
+							} elseif (is_array($v)) {
597
+								$tt = $this->isArraySimpleOrStruct($v);
598
+							} else {
599
+								$tt = gettype($v);
600
+							}
601
+							$array_types[$tt] = 1;
602
+							// TODO: for literal, the name should be $name
603
+							$xml .= $this->serialize_val($v, 'item', false, false, false, false, $use);
604
+							++$i;
605
+						}
606
+						if (is_array($array_types) && count($array_types) > 1) {
607
+							$array_typename = 'xsd:anyType';
608
+						} elseif (isset($tt) && isset($this->typemap[$this->XMLSchemaVersion][$tt])) {
609
+							if ('integer' === $tt) {
610
+								$tt = 'int';
611
+							}
612
+							$array_typename = 'xsd:' . $tt;
613
+						} elseif (isset($tt) && 'arraySimple' === $tt) {
614
+							$array_typename = 'SOAP-ENC:Array';
615
+						} elseif (isset($tt) && 'arrayStruct' === $tt) {
616
+							$array_typename = 'unnamed_struct_use_soapval';
617
+						} else {
618
+							// if type is prefixed, create type prefix
619
+							if ('' != $tt_ns && $tt_ns == $this->namespaces['xsd']) {
620
+								$array_typename = 'xsd:' . $tt;
621
+							} elseif ($tt_ns) {
622
+								$tt_prefix = 'ns' . mt_rand(1000, 9999);
623
+								$array_typename = "$tt_prefix:$tt";
624
+								$xmlns .= " xmlns:$tt_prefix=\"$tt_ns\"";
625
+							} else {
626
+								$array_typename = $tt;
627
+							}
628
+						}
629
+						$array_type = $i;
630
+						if ('literal' === $use) {
631
+							$type_str = '';
632
+						} elseif (isset($type) && isset($type_prefix)) {
633
+							$type_str = " xsi:type=\"$type_prefix:$type\"";
634
+						} else {
635
+							$type_str = ' xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="' . $array_typename . "[$array_type]\"";
636
+						}
637
+						// empty array
638
+					} else {
639
+						if ('literal' === $use) {
640
+							$type_str = '';
641
+						} elseif (isset($type) && isset($type_prefix)) {
642
+							$type_str = " xsi:type=\"$type_prefix:$type\"";
643
+						} else {
644
+							$type_str = ' xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="xsd:anyType[0]"';
645
+						}
646
+					}
647
+					// TODO: for array in literal, there is no wrapper here
648
+					$xml = "<$name$xmlns$type_str$atts>" . $xml . "</$name>";
649
+				} else {
650
+					// got a struct
651
+					$this->debug('serialize_val: serialize struct');
652
+					if (isset($type) && isset($type_prefix)) {
653
+						$type_str = " xsi:type=\"$type_prefix:$type\"";
654
+					} else {
655
+						$type_str = '';
656
+					}
657
+					if ('literal' === $use) {
658
+						$xml .= "<$name$xmlns$atts>";
659
+					} else {
660
+						$xml .= "<$name$xmlns$type_str$atts>";
661
+					}
662
+					foreach ($val as $k => $v) {
663
+						// Apache Map
664
+						if ('Map' === $type && 'http://xml.apache.org/xml-soap' === $type_ns) {
665
+							$xml .= '<item>';
666
+							$xml .= $this->serialize_val($k, 'key', false, false, false, false, $use);
667
+							$xml .= $this->serialize_val($v, 'value', false, false, false, false, $use);
668
+							$xml .= '</item>';
669
+						} else {
670
+							$xml .= $this->serialize_val($v, $k, false, false, false, false, $use);
671
+						}
672
+					}
673
+					$xml .= "</$name>";
674
+				}
675
+				break;
676
+			default:
677
+				$this->debug('serialize_val: serialize unknown');
678
+				$xml .= 'not detected, got ' . gettype($val) . ' for ' . $val;
679
+				break;
680
+		}
681
+		$this->debug("serialize_val returning $xml");
682
+		return $xml;
683
+	}
684
+
685
+	/**
686
+	 * serializes a message
687
+	 *
688
+	 * @param string $body the XML of the SOAP body
689
+	 * @param mixed $headers optional string of XML with SOAP header content, or array of soapval objects for SOAP headers, or associative array
690
+	 * @param array $namespaces optional the namespaces used in generating the body and headers
691
+	 * @param string $style optional (rpc|document)
692
+	 * @param string $use optional (encoded|literal)
693
+	 * @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
694
+	 * @return string the message
695
+	 * @access public
696
+	 */
697
+	public function serializeEnvelope($body, $headers = false, $namespaces = [], $style = 'rpc', $use = 'encoded', $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/')
698
+	{
699
+		// TODO: add an option to automatically run utf8_encode on $body and $headers
700
+		// if $this->soap_defencoding is UTF-8.  Not doing this automatically allows
701
+		// one to send arbitrary UTF-8 characters, not just characters that map to ISO-8859-1
702
+
703
+		$this->debug('In serializeEnvelope length=' . strlen($body) . ' body (max 1000 characters)=' . substr($body, 0, 1000) . " style=$style use=$use encodingStyle=$encodingStyle");
704
+		$this->debug('headers:');
705
+		$this->appendDebug($this->varDump($headers));
706
+		$this->debug('namespaces:');
707
+		$this->appendDebug($this->varDump($namespaces));
708
+
709
+		// serialize namespaces
710
+		$ns_string = '';
711
+		foreach (array_merge($this->namespaces, $namespaces) as $k => $v) {
712
+			$ns_string .= " xmlns:$k=\"$v\"";
713
+		}
714
+		if ($encodingStyle) {
715
+			$ns_string = " SOAP-ENV:encodingStyle=\"$encodingStyle\"$ns_string";
716
+		}
717
+
718
+		// serialize headers
719
+		if ($headers) {
720
+			if (is_array($headers)) {
721
+				$xml = '';
722
+				foreach ($headers as $k => $v) {
723
+					if (is_object($v) && 'soapval' === get_class($v)) {
724
+						$xml .= $this->serialize_val($v, false, false, false, false, false, $use);
725
+					} else {
726
+						$xml .= $this->serialize_val($v, $k, false, false, false, false, $use);
727
+					}
728
+				}
729
+				$headers = $xml;
730
+				$this->debug("In serializeEnvelope, serialized array of headers to $headers");
731
+			}
732
+			$headers = '<SOAP-ENV:Header>' . $headers . '</SOAP-ENV:Header>';
733
+		}
734
+		// serialize envelope
735
+		return
736
+			'<?xml version="1.0" encoding="' . $this->soap_defencoding . '"?' . '>' .
737
+			'<SOAP-ENV:Envelope' . $ns_string . '>' .
738
+			$headers . '<SOAP-ENV:Body>' .
739
+			$body . '</SOAP-ENV:Body>' . '</SOAP-ENV:Envelope>';
740
+	}
741
+
742
+	/**
743
+	 * formats a string to be inserted into an HTML stream
744
+	 *
745
+	 * @param string $str The string to format
746
+	 * @return string The formatted string
747
+	 * @access public
748
+	 * @deprecated
749
+	 */
750
+	public function formatDump($str)
751
+	{
752
+		$str = htmlspecialchars($str);
753
+		return nl2br($str);
754
+	}
755
+
756
+	/**
757
+	 * contracts (changes namespace to prefix) a qualified name
758
+	 *
759
+	 * @param    string $qname qname
760
+	 * @return    string contracted qname
761
+	 * @access   private
762
+	 */
763
+	protected function contractQName($qname)
764
+	{
765
+		// get element namespace
766
+		//$this->xdebug("Contract $qname");
767
+		if (strrpos($qname, ':')) {
768
+			// get unqualified name
769
+			$name = substr($qname, strrpos($qname, ':') + 1);
770
+			// get ns
771
+			$ns = substr($qname, 0, strrpos($qname, ':'));
772
+			$p = $this->getPrefixFromNamespace($ns);
773
+			if ($p) {
774
+				return $p . ':' . $name;
775
+			}
776
+			return $qname;
777
+		} else {
778
+			return $qname;
779
+		}
780
+	}
781
+
782
+	/**
783
+	 * expands (changes prefix to namespace) a qualified name
784
+	 *
785
+	 * @param    string $qname qname
786
+	 * @return    string expanded qname
787
+	 * @access   private
788
+	 */
789
+	protected function expandQname($qname)
790
+	{
791
+		// get element prefix
792
+		if (strpos($qname, ':') && !preg_match('/^http:\/\//', $qname)) {
793
+			// get unqualified name
794
+			$name = substr(strstr($qname, ':'), 1);
795
+			// get ns prefix
796
+			$prefix = substr($qname, 0, strpos($qname, ':'));
797
+			if (isset($this->namespaces[$prefix])) {
798
+				return $this->namespaces[$prefix] . ':' . $name;
799
+			} else {
800
+				return $qname;
801
+			}
802
+		} else {
803
+			return $qname;
804
+		}
805
+	}
806
+
807
+	/**
808
+	 * returns the local part of a prefixed string
809
+	 * returns the original string, if not prefixed
810
+	 *
811
+	 * @param string $str The prefixed string
812
+	 * @return string The local part
813
+	 * @access public
814
+	 */
815
+	public function getLocalPart($str)
816
+	{
817
+		if (false !== ($sstr = strrchr($str, ':'))) {
818
+			// get unqualified name
819
+			return substr($sstr, 1);
820
+		} else {
821
+			return $str;
822
+		}
823
+	}
824
+
825
+	/**
826
+	 * returns the prefix part of a prefixed string
827
+	 * returns false, if not prefixed
828
+	 *
829
+	 * @param string $str The prefixed string
830
+	 * @return mixed The prefix or false if there is no prefix
831
+	 * @access public
832
+	 */
833
+	public function getPrefix($str)
834
+	{
835
+		if (false !== ($pos = strrpos($str, ':'))) {
836
+			// get prefix
837
+			return substr($str, 0, $pos);
838
+		}
839
+		return false;
840
+	}
841
+
842
+	/**
843
+	 * pass it a prefix, it returns a namespace
844
+	 *
845
+	 * @param string $prefix The prefix
846
+	 * @return mixed The namespace, false if no namespace has the specified prefix
847
+	 * @access public
848
+	 */
849
+	public function getNamespaceFromPrefix($prefix)
850
+	{
851
+		if (isset($this->namespaces[$prefix])) {
852
+			return $this->namespaces[$prefix];
853
+		}
854
+		//$this->setError("No namespace registered for prefix '$prefix'");
855
+		return false;
856
+	}
857
+
858
+	/**
859
+	 * returns the prefix for a given namespace (or prefix)
860
+	 * or false if no prefixes registered for the given namespace
861
+	 *
862
+	 * @param string $ns The namespace
863
+	 * @return mixed The prefix, false if the namespace has no prefixes
864
+	 * @access public
865
+	 */
866
+	public function getPrefixFromNamespace($ns)
867
+	{
868
+		foreach ($this->namespaces as $p => $n) {
869
+			if ($ns == $n || $ns == $p) {
870
+				$this->usedNamespaces[$p] = $n;
871
+				return $p;
872
+			}
873
+		}
874
+		return false;
875
+	}
876
+
877
+	/**
878
+	 * returns the time in ODBC canonical form with microseconds
879
+	 *
880
+	 * @return string The time in ODBC canonical form with microseconds
881
+	 * @access public
882
+	 */
883
+	public function getmicrotime()
884
+	{
885
+		if (function_exists('gettimeofday')) {
886
+			$tod = gettimeofday();
887
+			$sec = $tod['sec'];
888
+			$usec = $tod['usec'];
889
+		} else {
890
+			$sec = time();
891
+			$usec = 0;
892
+		}
893
+		return strftime('%Y-%m-%d %H:%M:%S', $sec) . '.' . sprintf('%06d', $usec);
894
+	}
895
+
896
+	/**
897
+	 * Returns a string with the output of var_dump
898
+	 *
899
+	 * @param mixed $data The variable to var_dump
900
+	 * @return string The output of var_dump
901
+	 * @access public
902
+	 */
903
+	public function varDump($data)
904
+	{
905
+		ob_start();
906
+		var_dump($data);
907
+		$ret_val = ob_get_contents();
908
+		ob_end_clean();
909
+		return $ret_val;
910
+	}
911
+
912
+	/**
913
+	 * represents the object as a string
914
+	 *
915
+	 * @return    string
916
+	 * @access   public
917
+	 */
918
+	public function __toString()
919
+	{
920
+		return $this->varDump($this);
921
+	}
922 922
 }
923 923
 
924 924
 // XML Schema Datatype Helper Functions
@@ -935,35 +935,35 @@  discard block
 block discarded – undo
935 935
  */
936 936
 function timestamp_to_iso8601($timestamp, $utc = true)
937 937
 {
938
-    $datestr = date('Y-m-d\TH:i:sO', $timestamp);
939
-    $pos = strrpos($datestr, '+');
940
-    if (false === $pos) {
941
-        $pos = strrpos($datestr, '-');
942
-    }
943
-    if (false !== $pos) {
944
-        if (strlen($datestr) == $pos + 5) {
945
-            $datestr = substr($datestr, 0, $pos + 3) . ':' . substr($datestr, -2);
946
-        }
947
-    }
948
-    if ($utc) {
949
-        $pattern = '/' .
950
-            '([0-9]{4})-' .    // centuries & years CCYY-
951
-            '([0-9]{2})-' .    // months MM-
952
-            '([0-9]{2})' .    // days DD
953
-            'T' .            // separator T
954
-            '([0-9]{2}):' .    // hours hh:
955
-            '([0-9]{2}):' .    // minutes mm:
956
-            '([0-9]{2})(\.[0-9]*)?' . // seconds ss.ss...
957
-            '(Z|[+\-][0-9]{2}:?[0-9]{2})?' . // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's
958
-            '/';
959
-
960
-        if (preg_match($pattern, $datestr, $regs)) {
961
-            return sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ', $regs[1], $regs[2], $regs[3], $regs[4], $regs[5], $regs[6]);
962
-        }
963
-        return false;
964
-    } else {
965
-        return $datestr;
966
-    }
938
+	$datestr = date('Y-m-d\TH:i:sO', $timestamp);
939
+	$pos = strrpos($datestr, '+');
940
+	if (false === $pos) {
941
+		$pos = strrpos($datestr, '-');
942
+	}
943
+	if (false !== $pos) {
944
+		if (strlen($datestr) == $pos + 5) {
945
+			$datestr = substr($datestr, 0, $pos + 3) . ':' . substr($datestr, -2);
946
+		}
947
+	}
948
+	if ($utc) {
949
+		$pattern = '/' .
950
+			'([0-9]{4})-' .    // centuries & years CCYY-
951
+			'([0-9]{2})-' .    // months MM-
952
+			'([0-9]{2})' .    // days DD
953
+			'T' .            // separator T
954
+			'([0-9]{2}):' .    // hours hh:
955
+			'([0-9]{2}):' .    // minutes mm:
956
+			'([0-9]{2})(\.[0-9]*)?' . // seconds ss.ss...
957
+			'(Z|[+\-][0-9]{2}:?[0-9]{2})?' . // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's
958
+			'/';
959
+
960
+		if (preg_match($pattern, $datestr, $regs)) {
961
+			return sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ', $regs[1], $regs[2], $regs[3], $regs[4], $regs[5], $regs[6]);
962
+		}
963
+		return false;
964
+	} else {
965
+		return $datestr;
966
+	}
967 967
 }
968 968
 
969 969
 /**
@@ -975,35 +975,35 @@  discard block
 block discarded – undo
975 975
  */
976 976
 function iso8601_to_timestamp($datestr)
977 977
 {
978
-    $pattern = '/' .
979
-        '([0-9]{4})-' .    // centuries & years CCYY-
980
-        '([0-9]{2})-' .    // months MM-
981
-        '([0-9]{2})' .    // days DD
982
-        'T' .            // separator T
983
-        '([0-9]{2}):' .    // hours hh:
984
-        '([0-9]{2}):' .    // minutes mm:
985
-        '([0-9]{2})(\.[0-9]+)?' . // seconds ss.ss...
986
-        '(Z|[+\-][0-9]{2}:?[0-9]{2})?' . // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's
987
-        '/';
988
-    if (preg_match($pattern, $datestr, $regs)) {
989
-        // not utc
990
-        if ('Z' !== $regs[8]) {
991
-            $op = substr($regs[8], 0, 1);
992
-            $h = substr($regs[8], 1, 2);
993
-            $m = substr($regs[8], strlen($regs[8]) - 2, 2);
994
-            if ('-' == $op) {
995
-                $regs[4] += $h;
996
-                $regs[5] += $m;
997
-            } elseif ('+' == $op) {
998
-                $regs[4] -= $h;
999
-                $regs[5] -= $m;
1000
-            }
1001
-        }
1002
-        return gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
1003
-    //		return strtotime("$regs[1]-$regs[2]-$regs[3] $regs[4]:$regs[5]:$regs[6]Z");
1004
-    } else {
1005
-        return false;
1006
-    }
978
+	$pattern = '/' .
979
+		'([0-9]{4})-' .    // centuries & years CCYY-
980
+		'([0-9]{2})-' .    // months MM-
981
+		'([0-9]{2})' .    // days DD
982
+		'T' .            // separator T
983
+		'([0-9]{2}):' .    // hours hh:
984
+		'([0-9]{2}):' .    // minutes mm:
985
+		'([0-9]{2})(\.[0-9]+)?' . // seconds ss.ss...
986
+		'(Z|[+\-][0-9]{2}:?[0-9]{2})?' . // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's
987
+		'/';
988
+	if (preg_match($pattern, $datestr, $regs)) {
989
+		// not utc
990
+		if ('Z' !== $regs[8]) {
991
+			$op = substr($regs[8], 0, 1);
992
+			$h = substr($regs[8], 1, 2);
993
+			$m = substr($regs[8], strlen($regs[8]) - 2, 2);
994
+			if ('-' == $op) {
995
+				$regs[4] += $h;
996
+				$regs[5] += $m;
997
+			} elseif ('+' == $op) {
998
+				$regs[4] -= $h;
999
+				$regs[5] -= $m;
1000
+			}
1001
+		}
1002
+		return gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
1003
+	//		return strtotime("$regs[1]-$regs[2]-$regs[3] $regs[4]:$regs[5]:$regs[6]Z");
1004
+	} else {
1005
+		return false;
1006
+	}
1007 1007
 }
1008 1008
 
1009 1009
 /**
@@ -1015,13 +1015,13 @@  discard block
 block discarded – undo
1015 1015
  */
1016 1016
 function usleepWindows($usec)
1017 1017
 {
1018
-    $start = gettimeofday();
1018
+	$start = gettimeofday();
1019 1019
 
1020
-    do {
1021
-        $stop = gettimeofday();
1022
-        $timePassed = 1000000 * ($stop['sec'] - $start['sec'])
1023
-            + $stop['usec'] - $start['usec'];
1024
-    } while ($timePassed < $usec);
1020
+	do {
1021
+		$stop = gettimeofday();
1022
+		$timePassed = 1000000 * ($stop['sec'] - $start['sec'])
1023
+			+ $stop['usec'] - $start['usec'];
1024
+	} while ($timePassed < $usec);
1025 1025
 }
1026 1026
 
1027 1027
 
@@ -1036,78 +1036,78 @@  discard block
 block discarded – undo
1036 1036
  */
1037 1037
 class nusoap_fault extends nusoap_base
1038 1038
 {
1039
-    /**
1040
-     * The fault code (client|server)
1041
-     *
1042
-     * @var string
1043
-     * @access private
1044
-     */
1045
-    private $faultcode;
1046
-    /**
1047
-     * The fault actor
1048
-     *
1049
-     * @var string
1050
-     * @access private
1051
-     */
1052
-    private $faultactor;
1053
-    /**
1054
-     * The fault string, a description of the fault
1055
-     *
1056
-     * @var string
1057
-     * @access private
1058
-     */
1059
-    private $faultstring;
1060
-    /**
1061
-     * The fault detail, typically a string or array of string
1062
-     *
1063
-     * @var mixed
1064
-     * @access private
1065
-     */
1066
-    private $faultdetail;
1067
-
1068
-    /**
1069
-     * constructor
1070
-     *
1071
-     * @param string $faultcode (SOAP-ENV:Client | SOAP-ENV:Server)
1072
-     * @param string $faultactor only used when msg routed between multiple actors
1073
-     * @param string $faultstring human readable error message
1074
-     * @param mixed $faultdetail detail, typically a string or array of string
1075
-     */
1076
-    public function __construct($faultcode, $faultactor = '', $faultstring = '', $faultdetail = '')
1077
-    {
1078
-        parent::__construct();
1079
-        $this->faultcode = $faultcode;
1080
-        $this->faultactor = $faultactor;
1081
-        $this->faultstring = $faultstring;
1082
-        $this->faultdetail = $faultdetail;
1083
-    }
1084
-
1085
-    /**
1086
-     * serialize a fault
1087
-     *
1088
-     * @return    string    The serialization of the fault instance.
1089
-     * @access   public
1090
-     */
1091
-    public function serialize()
1092
-    {
1093
-        $ns_string = '';
1094
-        foreach ($this->namespaces as $k => $v) {
1095
-            $ns_string .= "\n  xmlns:$k=\"$v\"";
1096
-        }
1097
-        $return_msg =
1098
-            '<?xml version="1.0" encoding="' . $this->soap_defencoding . '"?>' .
1099
-            '<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"' . $ns_string . ">\n" .
1100
-            '<SOAP-ENV:Body>' .
1101
-            '<SOAP-ENV:Fault>' .
1102
-            $this->serialize_val($this->faultcode, 'faultcode') .
1103
-            $this->serialize_val($this->faultactor, 'faultactor') .
1104
-            $this->serialize_val($this->faultstring, 'faultstring') .
1105
-            $this->serialize_val($this->faultdetail, 'detail') .
1106
-            '</SOAP-ENV:Fault>' .
1107
-            '</SOAP-ENV:Body>' .
1108
-            '</SOAP-ENV:Envelope>';
1109
-        return $return_msg;
1110
-    }
1039
+	/**
1040
+	 * The fault code (client|server)
1041
+	 *
1042
+	 * @var string
1043
+	 * @access private
1044
+	 */
1045
+	private $faultcode;
1046
+	/**
1047
+	 * The fault actor
1048
+	 *
1049
+	 * @var string
1050
+	 * @access private
1051
+	 */
1052
+	private $faultactor;
1053
+	/**
1054
+	 * The fault string, a description of the fault
1055
+	 *
1056
+	 * @var string
1057
+	 * @access private
1058
+	 */
1059
+	private $faultstring;
1060
+	/**
1061
+	 * The fault detail, typically a string or array of string
1062
+	 *
1063
+	 * @var mixed
1064
+	 * @access private
1065
+	 */
1066
+	private $faultdetail;
1067
+
1068
+	/**
1069
+	 * constructor
1070
+	 *
1071
+	 * @param string $faultcode (SOAP-ENV:Client | SOAP-ENV:Server)
1072
+	 * @param string $faultactor only used when msg routed between multiple actors
1073
+	 * @param string $faultstring human readable error message
1074
+	 * @param mixed $faultdetail detail, typically a string or array of string
1075
+	 */
1076
+	public function __construct($faultcode, $faultactor = '', $faultstring = '', $faultdetail = '')
1077
+	{
1078
+		parent::__construct();
1079
+		$this->faultcode = $faultcode;
1080
+		$this->faultactor = $faultactor;
1081
+		$this->faultstring = $faultstring;
1082
+		$this->faultdetail = $faultdetail;
1083
+	}
1084
+
1085
+	/**
1086
+	 * serialize a fault
1087
+	 *
1088
+	 * @return    string    The serialization of the fault instance.
1089
+	 * @access   public
1090
+	 */
1091
+	public function serialize()
1092
+	{
1093
+		$ns_string = '';
1094
+		foreach ($this->namespaces as $k => $v) {
1095
+			$ns_string .= "\n  xmlns:$k=\"$v\"";
1096
+		}
1097
+		$return_msg =
1098
+			'<?xml version="1.0" encoding="' . $this->soap_defencoding . '"?>' .
1099
+			'<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"' . $ns_string . ">\n" .
1100
+			'<SOAP-ENV:Body>' .
1101
+			'<SOAP-ENV:Fault>' .
1102
+			$this->serialize_val($this->faultcode, 'faultcode') .
1103
+			$this->serialize_val($this->faultactor, 'faultactor') .
1104
+			$this->serialize_val($this->faultstring, 'faultstring') .
1105
+			$this->serialize_val($this->faultdetail, 'detail') .
1106
+			'</SOAP-ENV:Fault>' .
1107
+			'</SOAP-ENV:Body>' .
1108
+			'</SOAP-ENV:Envelope>';
1109
+		return $return_msg;
1110
+	}
1111 1111
 }
1112 1112
 
1113 1113
 
@@ -1131,982 +1131,982 @@  discard block
 block discarded – undo
1131 1131
 class nusoap_xmlschema extends nusoap_base
1132 1132
 {
1133 1133
 
1134
-    // files
1135
-    public $schema = '';
1136
-    public $xml = '';
1137
-    // namespaces
1138
-    public $enclosingNamespaces;
1139
-    // schema info
1140
-    public $schemaInfo = [];
1141
-    public $schemaTargetNamespace = '';
1142
-    // types, elements, attributes defined by the schema
1143
-    public $attributes = [];
1144
-    public $complexTypes = [];
1145
-    public $complexTypeStack = [];
1146
-    public $currentComplexType;
1147
-    public $elements = [];
1148
-    public $elementStack = [];
1149
-    public $currentElement;
1150
-    public $simpleTypes = [];
1151
-    public $simpleTypeStack = [];
1152
-    public $currentSimpleType;
1153
-    // imports
1154
-    public $imports = [];
1155
-    // parser vars
1156
-    public $parser;
1157
-    public $position = 0;
1158
-    public $depth = 0;
1159
-    public $depth_array = [];
1160
-    public $message = [];
1161
-    public $defaultNamespace = [];
1162
-
1163
-    /**
1164
-     * constructor
1165
-     *
1166
-     * @param string $schema     schema document URI
1167
-     * @param string $xml        xml document URI
1168
-     * @param array  $namespaces namespaces defined in enclosing XML
1169
-     * @access   public
1170
-     */
1171
-    public function __construct($schema = '', $xml = '', $namespaces = [])
1172
-    {
1173
-        parent::__construct();
1174
-        $this->debug('nusoap_xmlschema class instantiated, inside constructor');
1175
-        // files
1176
-        $this->schema = $schema;
1177
-        $this->xml = $xml;
1178
-
1179
-        // namespaces
1180
-        $this->enclosingNamespaces = $namespaces;
1181
-        $this->namespaces = array_merge($this->namespaces, $namespaces);
1182
-
1183
-        // parse schema file
1184
-        if ('' != $schema) {
1185
-            $this->debug('initial schema file: ' . $schema);
1186
-            $this->parseFile($schema, 'schema');
1187
-        }
1188
-
1189
-        // parse xml file
1190
-        if ('' != $xml) {
1191
-            $this->debug('initial xml file: ' . $xml);
1192
-            $this->parseFile($xml, 'xml');
1193
-        }
1194
-    }
1195
-
1196
-    /**
1197
-     * parse an XML file
1198
-     *
1199
-     * @param string $xml path/URL to XML file
1200
-     * @param string $type (schema | xml)
1201
-     * @return boolean
1202
-     * @access public
1203
-     */
1204
-    public function parseFile($xml, $type)
1205
-    {
1206
-        // parse xml file
1207
-        if ('' != $xml) {
1208
-            $xmlStr = @file_get_contents($xml);
1209
-            if ('' == $xmlStr) {
1210
-                $msg = 'Error reading XML from ' . $xml;
1211
-                $this->setError($msg);
1212
-                $this->debug($msg);
1213
-                return false;
1214
-            } else {
1215
-                $this->debug("parsing $xml");
1216
-                $this->parseString($xmlStr, $type);
1217
-                $this->debug("done parsing $xml");
1218
-                return true;
1219
-            }
1220
-        }
1221
-        return false;
1222
-    }
1223
-
1224
-    /**
1225
-     * parse an XML string
1226
-     *
1227
-     * @param    string $xml path or URL
1228
-     * @param    string $type (schema|xml)
1229
-     * @access   private
1230
-     */
1231
-    private function parseString($xml, $type)
1232
-    {
1233
-        // parse xml string
1234
-        if ('' != $xml) {
1235
-
1236
-            // Create an XML parser.
1237
-            $this->parser = xml_parser_create();
1238
-            // Set the options for parsing the XML data.
1239
-            xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
1240
-
1241
-            // Set the object for the parser.
1242
-            xml_set_object($this->parser, $this);
1243
-
1244
-            // Set the element handlers for the parser.
1245
-            if ('schema' === $type) {
1246
-                xml_set_element_handler($this->parser, 'schemaStartElement', 'schemaEndElement');
1247
-                xml_set_character_data_handler($this->parser, 'schemaCharacterData');
1248
-            } elseif ('xml' === $type) {
1249
-                xml_set_element_handler($this->parser, 'xmlStartElement', 'xmlEndElement');
1250
-                xml_set_character_data_handler($this->parser, 'xmlCharacterData');
1251
-            }
1252
-
1253
-            // Parse the XML file.
1254
-            if (!xml_parse($this->parser, $xml, true)) {
1255
-                // Display an error message.
1256
-                $errstr = sprintf(
1257
-                    'XML error parsing XML schema on line %d: %s',
1258
-                    xml_get_current_line_number($this->parser),
1259
-                    xml_error_string(xml_get_error_code($this->parser))
1260
-                );
1261
-                $this->debug($errstr);
1262
-                $this->debug("XML payload:\n" . $xml);
1263
-                $this->setError($errstr);
1264
-            }
1265
-
1266
-            xml_parser_free($this->parser);
1267
-            unset($this->parser);
1268
-        } else {
1269
-            $this->debug('no xml passed to parseString()!!');
1270
-            $this->setError('no xml passed to parseString()!!');
1271
-        }
1272
-    }
1273
-
1274
-    /**
1275
-     * gets a type name for an unnamed type
1276
-     *
1277
-     * @param    string    Element name
1278
-     * @return    string    A type name for an unnamed type
1279
-     * @access    private
1280
-     */
1281
-    private function CreateTypeName($ename)
1282
-    {
1283
-        $scope = '';
1284
-        for ($i = 0, $iMax = count($this->complexTypeStack); $i < $iMax; $i++) {
1285
-            $scope .= $this->complexTypeStack[$i] . '_';
1286
-        }
1287
-        return $scope . $ename . '_ContainedType';
1288
-    }
1289
-
1290
-    /**
1291
-     * start-element handler
1292
-     *
1293
-     * @param    string $parser XML parser object
1294
-     * @param    string $name element name
1295
-     * @param    string|array $attrs associative array of attributes
1296
-     * @access   private
1297
-     */
1298
-    public function schemaStartElement($parser, $name, $attrs)
1299
-    {
1300
-
1301
-        // position in the total number of elements, starting from 0
1302
-        $pos = $this->position++;
1303
-        $depth = $this->depth++;
1304
-        // set self as current value for this depth
1305
-        $this->depth_array[$depth] = $pos;
1306
-        $this->message[$pos] = ['cdata' => ''];
1307
-        if ($depth > 0) {
1308
-            $this->defaultNamespace[$pos] = $this->defaultNamespace[$this->depth_array[$depth - 1]];
1309
-        } else {
1310
-            $this->defaultNamespace[$pos] = false;
1311
-        }
1312
-
1313
-        // get element prefix
1314
-        if (false !== ($prefix = $this->getPrefix($name))) {
1315
-            // get unqualified name
1316
-            $name = $this->getLocalPart($name);
1317
-        } else {
1318
-            $prefix = '';
1319
-        }
1320
-
1321
-        // loop thru attributes, expanding, and registering namespace declarations
1322
-        if (is_array($attrs) && count($attrs) > 0) {
1323
-            foreach ($attrs as $k => $v) {
1324
-                // if ns declarations, add to class level array of valid namespaces
1325
-                if (preg_match('/^xmlns/', $k)) {
1326
-                    //$this->xdebug("$k: $v");
1327
-                    //$this->xdebug('ns_prefix: '.$this->getPrefix($k));
1328
-                    if (false !== ($ns_prefix = substr(strrchr($k, ':'), 1))) {
1329
-                        //$this->xdebug("Add namespace[$ns_prefix] = $v");
1330
-                        $this->namespaces[$ns_prefix] = $v;
1331
-                    } else {
1332
-                        $this->defaultNamespace[$pos] = $v;
1333
-                        if (!$this->getPrefixFromNamespace($v)) {
1334
-                            $this->namespaces['ns' . (count($this->namespaces) + 1)] = $v;
1335
-                        }
1336
-                    }
1337
-                    if ('http://www.w3.org/2001/XMLSchema' === $v || 'http://www.w3.org/1999/XMLSchema' === $v || 'http://www.w3.org/2000/10/XMLSchema' === $v) {
1338
-                        $this->XMLSchemaVersion = $v;
1339
-                        $this->namespaces['xsi'] = $v . '-instance';
1340
-                    }
1341
-                }
1342
-            }
1343
-            foreach ($attrs as $k => $v) {
1344
-                // expand each attribute
1345
-                $k = strpos($k, ':') ? $this->expandQname($k) : $k;
1346
-                $v = strpos($v, ':') ? $this->expandQname($v) : $v;
1347
-                $eAttrs[$k] = $v;
1348
-            }
1349
-            $attrs = $eAttrs;
1350
-        } else {
1351
-            $attrs = [];
1352
-        }
1353
-        // find status, register data
1354
-        switch ($name) {
1355
-            case 'all':            // (optional) compositor content for a complexType
1356
-            case 'choice':
1357
-            case 'group':
1358
-            case 'sequence':
1359
-                //$this->xdebug("compositor $name for currentComplexType: $this->currentComplexType and currentElement: $this->currentElement");
1360
-                $this->complexTypes[$this->currentComplexType]['compositor'] = $name;
1361
-                //if($name == 'all' || $name == 'sequence'){
1362
-                //	$this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
1363
-                //}
1364
-                break;
1365
-            case 'attribute':    // complexType attribute
1366
-                //$this->xdebug("parsing attribute $attrs[name] $attrs[ref] of value: ".$attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']);
1367
-                $this->xdebug('parsing attribute:');
1368
-                $this->appendDebug($this->varDump($attrs));
1369
-                if (!isset($attrs['form'])) {
1370
-                    // TODO: handle globals
1371
-                    $attrs['form'] = $this->schemaInfo['attributeFormDefault'];
1372
-                }
1373
-                if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
1374
-                    $v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
1375
-                    if (!strpos($v, ':')) {
1376
-                        // no namespace in arrayType attribute value...
1377
-                        if ($this->defaultNamespace[$pos]) {
1378
-                            // ...so use the default
1379
-                            $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'] = $this->defaultNamespace[$pos] . ':' . $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
1380
-                        }
1381
-                    }
1382
-                }
1383
-                if (isset($attrs['name'])) {
1384
-                    $this->attributes[$attrs['name']] = $attrs;
1385
-                    $aname = $attrs['name'];
1386
-                } elseif (isset($attrs['ref']) && 'http://schemas.xmlsoap.org/soap/encoding/:arrayType' === $attrs['ref']) {
1387
-                    if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
1388
-                        $aname = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
1389
-                    } else {
1390
-                        $aname = '';
1391
-                    }
1392
-                } elseif (isset($attrs['ref'])) {
1393
-                    $aname = $attrs['ref'];
1394
-                    $this->attributes[$attrs['ref']] = $attrs;
1395
-                }
1134
+	// files
1135
+	public $schema = '';
1136
+	public $xml = '';
1137
+	// namespaces
1138
+	public $enclosingNamespaces;
1139
+	// schema info
1140
+	public $schemaInfo = [];
1141
+	public $schemaTargetNamespace = '';
1142
+	// types, elements, attributes defined by the schema
1143
+	public $attributes = [];
1144
+	public $complexTypes = [];
1145
+	public $complexTypeStack = [];
1146
+	public $currentComplexType;
1147
+	public $elements = [];
1148
+	public $elementStack = [];
1149
+	public $currentElement;
1150
+	public $simpleTypes = [];
1151
+	public $simpleTypeStack = [];
1152
+	public $currentSimpleType;
1153
+	// imports
1154
+	public $imports = [];
1155
+	// parser vars
1156
+	public $parser;
1157
+	public $position = 0;
1158
+	public $depth = 0;
1159
+	public $depth_array = [];
1160
+	public $message = [];
1161
+	public $defaultNamespace = [];
1162
+
1163
+	/**
1164
+	 * constructor
1165
+	 *
1166
+	 * @param string $schema     schema document URI
1167
+	 * @param string $xml        xml document URI
1168
+	 * @param array  $namespaces namespaces defined in enclosing XML
1169
+	 * @access   public
1170
+	 */
1171
+	public function __construct($schema = '', $xml = '', $namespaces = [])
1172
+	{
1173
+		parent::__construct();
1174
+		$this->debug('nusoap_xmlschema class instantiated, inside constructor');
1175
+		// files
1176
+		$this->schema = $schema;
1177
+		$this->xml = $xml;
1178
+
1179
+		// namespaces
1180
+		$this->enclosingNamespaces = $namespaces;
1181
+		$this->namespaces = array_merge($this->namespaces, $namespaces);
1182
+
1183
+		// parse schema file
1184
+		if ('' != $schema) {
1185
+			$this->debug('initial schema file: ' . $schema);
1186
+			$this->parseFile($schema, 'schema');
1187
+		}
1396 1188
 
1397
-                if ($this->currentComplexType) {    // This should *always* be
1398
-                    $this->complexTypes[$this->currentComplexType]['attrs'][$aname] = $attrs;
1399
-                }
1400
-                // arrayType attribute
1401
-                if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']) || 'arrayType' === $this->getLocalPart($aname)) {
1402
-                    $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
1403
-                    $prefix = $this->getPrefix($aname);
1404
-                    if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
1405
-                        $v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
1406
-                    } else {
1407
-                        $v = '';
1408
-                    }
1409
-                    if (strpos($v, '[,]')) {
1410
-                        $this->complexTypes[$this->currentComplexType]['multidimensional'] = true;
1411
-                    }
1412
-                    $v = substr($v, 0, strpos($v, '[')); // clip the []
1413
-                    if (!strpos($v, ':') && isset($this->typemap[$this->XMLSchemaVersion][$v])) {
1414
-                        $v = $this->XMLSchemaVersion . ':' . $v;
1415
-                    }
1416
-                    $this->complexTypes[$this->currentComplexType]['arrayType'] = $v;
1417
-                }
1418
-                break;
1419
-            case 'complexContent':    // (optional) content for a complexType
1420
-                $this->xdebug("do nothing for element $name");
1421
-                break;
1422
-            case 'complexType':
1423
-                array_push($this->complexTypeStack, $this->currentComplexType);
1424
-                if (isset($attrs['name'])) {
1425
-                    // TODO: what is the scope of named complexTypes that appear
1426
-                    //       nested within other c complexTypes?
1427
-                    $this->xdebug('processing named complexType ' . $attrs['name']);
1428
-                    //$this->currentElement = false;
1429
-                    $this->currentComplexType = $attrs['name'];
1430
-                    $this->complexTypes[$this->currentComplexType] = $attrs;
1431
-                    $this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType';
1432
-                    // This is for constructs like
1433
-                    //           <complexType name="ListOfString" base="soap:Array">
1434
-                    //                <sequence>
1435
-                    //                    <element name="string" type="xsd:string"
1436
-                    //                        minOccurs="0" maxOccurs="unbounded" />
1437
-                    //                </sequence>
1438
-                    //            </complexType>
1439
-                    if (isset($attrs['base']) && preg_match('/:Array$/', $attrs['base'])) {
1440
-                        $this->xdebug('complexType is unusual array');
1441
-                        $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
1442
-                    } else {
1443
-                        $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
1444
-                    }
1445
-                } else {
1446
-                    $name = $this->CreateTypeName($this->currentElement);
1447
-                    $this->xdebug('processing unnamed complexType for element ' . $this->currentElement . ' named ' . $name);
1448
-                    $this->currentComplexType = $name;
1449
-                    //$this->currentElement = false;
1450
-                    $this->complexTypes[$this->currentComplexType] = $attrs;
1451
-                    $this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType';
1452
-                    // This is for constructs like
1453
-                    //           <complexType name="ListOfString" base="soap:Array">
1454
-                    //                <sequence>
1455
-                    //                    <element name="string" type="xsd:string"
1456
-                    //                        minOccurs="0" maxOccurs="unbounded" />
1457
-                    //                </sequence>
1458
-                    //            </complexType>
1459
-                    if (isset($attrs['base']) && preg_match('/:Array$/', $attrs['base'])) {
1460
-                        $this->xdebug('complexType is unusual array');
1461
-                        $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
1462
-                    } else {
1463
-                        $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
1464
-                    }
1465
-                }
1466
-                $this->complexTypes[$this->currentComplexType]['simpleContent'] = 'false';
1467
-                break;
1468
-            case 'element':
1469
-                array_push($this->elementStack, $this->currentElement);
1470
-                if (!isset($attrs['form'])) {
1471
-                    if ($this->currentComplexType) {
1472
-                        $attrs['form'] = $this->schemaInfo['elementFormDefault'];
1473
-                    } else {
1474
-                        // global
1475
-                        $attrs['form'] = 'qualified';
1476
-                    }
1477
-                }
1478
-                if (isset($attrs['type'])) {
1479
-                    $this->xdebug('processing typed element ' . $attrs['name'] . ' of type ' . $attrs['type']);
1480
-                    if (!$this->getPrefix($attrs['type'])) {
1481
-                        if ($this->defaultNamespace[$pos]) {
1482
-                            $attrs['type'] = $this->defaultNamespace[$pos] . ':' . $attrs['type'];
1483
-                            $this->xdebug('used default namespace to make type ' . $attrs['type']);
1484
-                        }
1485
-                    }
1486
-                    // This is for constructs like
1487
-                    //           <complexType name="ListOfString" base="soap:Array">
1488
-                    //                <sequence>
1489
-                    //                    <element name="string" type="xsd:string"
1490
-                    //                        minOccurs="0" maxOccurs="unbounded" />
1491
-                    //                </sequence>
1492
-                    //            </complexType>
1493
-                    if ($this->currentComplexType && 'array' === $this->complexTypes[$this->currentComplexType]['phpType']) {
1494
-                        $this->xdebug('arrayType for unusual array is ' . $attrs['type']);
1495
-                        $this->complexTypes[$this->currentComplexType]['arrayType'] = $attrs['type'];
1496
-                    }
1497
-                    $this->currentElement = $attrs['name'];
1498
-                    $ename = $attrs['name'];
1499
-                } elseif (isset($attrs['ref'])) {
1500
-                    $this->xdebug('processing element as ref to ' . $attrs['ref']);
1501
-                    $this->currentElement = 'ref to ' . $attrs['ref'];
1502
-                    $ename = $this->getLocalPart($attrs['ref']);
1503
-                } else {
1504
-                    $type = $this->CreateTypeName($this->currentComplexType . '_' . $attrs['name']);
1505
-                    $this->xdebug('processing untyped element ' . $attrs['name'] . ' type ' . $type);
1506
-                    $this->currentElement = $attrs['name'];
1507
-                    $attrs['type'] = $this->schemaTargetNamespace . ':' . $type;
1508
-                    $ename = $attrs['name'];
1509
-                }
1510
-                if (isset($ename) && $this->currentComplexType) {
1511
-                    $this->xdebug("add element $ename to complexType $this->currentComplexType");
1512
-                    $this->complexTypes[$this->currentComplexType]['elements'][$ename] = $attrs;
1513
-                } elseif (!isset($attrs['ref'])) {
1514
-                    $this->xdebug("add element $ename to elements array");
1515
-                    $this->elements[$attrs['name']] = $attrs;
1516
-                    $this->elements[$attrs['name']]['typeClass'] = 'element';
1517
-                }
1518
-                break;
1519
-            case 'enumeration':    //	restriction value list member
1520
-                $this->xdebug('enumeration ' . $attrs['value']);
1521
-                if ($this->currentSimpleType) {
1522
-                    $this->simpleTypes[$this->currentSimpleType]['enumeration'][] = $attrs['value'];
1523
-                } elseif ($this->currentComplexType) {
1524
-                    $this->complexTypes[$this->currentComplexType]['enumeration'][] = $attrs['value'];
1525
-                }
1526
-                break;
1527
-            case 'extension':    // simpleContent or complexContent type extension
1528
-                $this->xdebug('extension ' . $attrs['base']);
1529
-                if ($this->currentComplexType) {
1530
-                    $ns = $this->getPrefix($attrs['base']);
1531
-                    if ('' == $ns) {
1532
-                        $this->complexTypes[$this->currentComplexType]['extensionBase'] = $this->schemaTargetNamespace . ':' . $attrs['base'];
1533
-                    } else {
1534
-                        $this->complexTypes[$this->currentComplexType]['extensionBase'] = $attrs['base'];
1535
-                    }
1536
-                } else {
1537
-                    $this->xdebug('no current complexType to set extensionBase');
1538
-                }
1539
-                break;
1540
-            case 'import':
1541
-                if (isset($attrs['schemaLocation'])) {
1542
-                    $this->xdebug('import namespace ' . $attrs['namespace'] . ' from ' . $attrs['schemaLocation']);
1543
-                    $this->imports[$attrs['namespace']][] = ['location' => $attrs['schemaLocation'], 'loaded' => false];
1544
-                } else {
1545
-                    $this->xdebug('import namespace ' . $attrs['namespace']);
1546
-                    $this->imports[$attrs['namespace']][] = ['location' => '', 'loaded' => true];
1547
-                    if (!$this->getPrefixFromNamespace($attrs['namespace'])) {
1548
-                        $this->namespaces['ns' . (count($this->namespaces) + 1)] = $attrs['namespace'];
1549
-                    }
1550
-                }
1551
-                break;
1552
-            case 'include':
1553
-                if (isset($attrs['schemaLocation'])) {
1554
-                    $this->xdebug('include into namespace ' . $this->schemaTargetNamespace . ' from ' . $attrs['schemaLocation']);
1555
-                    $this->imports[$this->schemaTargetNamespace][] = ['location' => $attrs['schemaLocation'], 'loaded' => false];
1556
-                } else {
1557
-                    $this->xdebug('ignoring invalid XML Schema construct: include without schemaLocation attribute');
1558
-                }
1559
-                break;
1560
-            case 'list':    // simpleType value list
1561
-                $this->xdebug("do nothing for element $name");
1562
-                break;
1563
-            case 'restriction':    // simpleType, simpleContent or complexContent value restriction
1564
-                $this->xdebug('restriction ' . $attrs['base']);
1565
-                if ($this->currentSimpleType) {
1566
-                    $this->simpleTypes[$this->currentSimpleType]['type'] = $attrs['base'];
1567
-                } elseif ($this->currentComplexType) {
1568
-                    $this->complexTypes[$this->currentComplexType]['restrictionBase'] = $attrs['base'];
1569
-                    if (':Array' === strstr($attrs['base'], ':')) {
1570
-                        $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
1571
-                    }
1572
-                }
1573
-                break;
1574
-            case 'schema':
1575
-                $this->schemaInfo = $attrs;
1576
-                $this->schemaInfo['schemaVersion'] = $this->getNamespaceFromPrefix($prefix);
1577
-                if (isset($attrs['targetNamespace'])) {
1578
-                    $this->schemaTargetNamespace = $attrs['targetNamespace'];
1579
-                }
1580
-                if (!isset($attrs['elementFormDefault'])) {
1581
-                    $this->schemaInfo['elementFormDefault'] = 'unqualified';
1582
-                }
1583
-                if (!isset($attrs['attributeFormDefault'])) {
1584
-                    $this->schemaInfo['attributeFormDefault'] = 'unqualified';
1585
-                }
1586
-                break;
1587
-            case 'simpleContent':    // (optional) content for a complexType
1588
-                if ($this->currentComplexType) {    // This should *always* be
1589
-                    $this->complexTypes[$this->currentComplexType]['simpleContent'] = 'true';
1590
-                } else {
1591
-                    $this->xdebug("do nothing for element $name because there is no current complexType");
1592
-                }
1593
-                break;
1594
-            case 'simpleType':
1595
-                array_push($this->simpleTypeStack, $this->currentSimpleType);
1596
-                if (isset($attrs['name'])) {
1597
-                    $this->xdebug('processing simpleType for name ' . $attrs['name']);
1598
-                    $this->currentSimpleType = $attrs['name'];
1599
-                    $this->simpleTypes[$attrs['name']] = $attrs;
1600
-                    $this->simpleTypes[$attrs['name']]['typeClass'] = 'simpleType';
1601
-                    $this->simpleTypes[$attrs['name']]['phpType'] = 'scalar';
1602
-                } else {
1603
-                    $name = $this->CreateTypeName($this->currentComplexType . '_' . $this->currentElement);
1604
-                    $this->xdebug('processing unnamed simpleType for element ' . $this->currentElement . ' named ' . $name);
1605
-                    $this->currentSimpleType = $name;
1606
-                    //$this->currentElement = false;
1607
-                    $this->simpleTypes[$this->currentSimpleType] = $attrs;
1608
-                    $this->simpleTypes[$this->currentSimpleType]['phpType'] = 'scalar';
1609
-                }
1610
-                break;
1611
-            case 'union':    // simpleType type list
1612
-                $this->xdebug("do nothing for element $name");
1613
-                break;
1614
-            default:
1615
-                $this->xdebug("do not have any logic to process element $name");
1616
-        }
1617
-    }
1618
-
1619
-    /**
1620
-     * end-element handler
1621
-     *
1622
-     * @param    string $parser XML parser object
1623
-     * @param    string $name element name
1624
-     * @access   private
1625
-     */
1626
-    private function schemaEndElement($parser, $name)
1627
-    {
1628
-        // bring depth down a notch
1629
-        $this->depth--;
1630
-        // position of current element is equal to the last value left in depth_array for my depth
1631
-        if (isset($this->depth_array[$this->depth])) {
1632
-            $pos = $this->depth_array[$this->depth];
1633
-        }
1634
-        // get element prefix
1635
-        if (false !== ($prefix = $this->getPrefix($name))) {
1636
-            // get unqualified name
1637
-            $name = $this->getLocalPart($name);
1638
-        } else {
1639
-            $prefix = '';
1640
-        }
1641
-        // move on...
1642
-        if ('complexType' === $name) {
1643
-            $this->xdebug('done processing complexType ' . ($this->currentComplexType ?: '(unknown)'));
1644
-            $this->xdebug($this->varDump($this->complexTypes[$this->currentComplexType]));
1645
-            $this->currentComplexType = array_pop($this->complexTypeStack);
1646
-            //$this->currentElement = false;
1647
-        }
1648
-        if ('element' === $name) {
1649
-            $this->xdebug('done processing element ' . ($this->currentElement ?: '(unknown)'));
1650
-            $this->currentElement = array_pop($this->elementStack);
1651
-        }
1652
-        if ('simpleType' === $name) {
1653
-            $this->xdebug('done processing simpleType ' . ($this->currentSimpleType ?: '(unknown)'));
1654
-            $this->xdebug($this->varDump($this->simpleTypes[$this->currentSimpleType]));
1655
-            $this->currentSimpleType = array_pop($this->simpleTypeStack);
1656
-        }
1657
-    }
1658
-
1659
-    /**
1660
-     * element content handler
1661
-     *
1662
-     * @param    string $parser XML parser object
1663
-     * @param    string $data element content
1664
-     * @access   private
1665
-     */
1666
-    private function schemaCharacterData($parser, $data)
1667
-    {
1668
-        $pos = $this->depth_array[$this->depth - 1];
1669
-        $this->message[$pos]['cdata'] .= $data;
1670
-    }
1671
-
1672
-    /**
1673
-     * serialize the schema
1674
-     *
1675
-     * @access   public
1676
-     */
1677
-    public function serializeSchema()
1678
-    {
1679
-        $schemaPrefix = $this->getPrefixFromNamespace($this->XMLSchemaVersion);
1680
-        $xml = '';
1681
-        // imports
1682
-        if (is_array($this->imports) && count($this->imports) > 0) {
1683
-            foreach ($this->imports as $ns => $list) {
1684
-                foreach ($list as $ii) {
1685
-                    if ('' != $ii['location']) {
1686
-                        $xml .= " <$schemaPrefix:import location=\"" . $ii['location'] . '" namespace="' . $ns . "\" />\n";
1687
-                    } else {
1688
-                        $xml .= " <$schemaPrefix:import namespace=\"" . $ns . "\" />\n";
1689
-                    }
1690
-                }
1691
-            }
1692
-        }
1693
-        // complex types
1694
-        foreach ($this->complexTypes as $typeName => $attrs) {
1695
-            $contentStr = '';
1696
-            // serialize child elements
1697
-            if (isset($attrs['elements']) && (count($attrs['elements']) > 0)) {
1698
-                foreach ($attrs['elements'] as $element => $eParts) {
1699
-                    if (isset($eParts['ref'])) {
1700
-                        $contentStr .= "   <$schemaPrefix:element ref=\"$element\"/>\n";
1701
-                    } else {
1702
-                        $contentStr .= "   <$schemaPrefix:element name=\"$element\" type=\"" . $this->contractQName($eParts['type']) . '"';
1703
-                        foreach ($eParts as $aName => $aValue) {
1704
-                            // handle, e.g., abstract, default, form, minOccurs, maxOccurs, nillable
1705
-                            if ('name' !== $aName && 'type' !== $aName) {
1706
-                                $contentStr .= " $aName=\"$aValue\"";
1707
-                            }
1708
-                        }
1709
-                        $contentStr .= "/>\n";
1710
-                    }
1711
-                }
1712
-                // compositor wraps elements
1713
-                if (isset($attrs['compositor']) && ('' != $attrs['compositor'])) {
1714
-                    $contentStr = "  <$schemaPrefix:$attrs[compositor]>\n" . $contentStr . "  </$schemaPrefix:$attrs[compositor]>\n";
1715
-                }
1716
-            }
1717
-            // attributes
1718
-            if (isset($attrs['attrs']) && (count($attrs['attrs']) >= 1)) {
1719
-                foreach ($attrs['attrs'] as $attr => $aParts) {
1720
-                    $contentStr .= "    <$schemaPrefix:attribute";
1721
-                    foreach ($aParts as $a => $v) {
1722
-                        if ('ref' === $a || 'type' === $a) {
1723
-                            $contentStr .= " $a=\"" . $this->contractQName($v) . '"';
1724
-                        } elseif ('http://schemas.xmlsoap.org/wsdl/:arrayType' === $a) {
1725
-                            $this->usedNamespaces['wsdl'] = $this->namespaces['wsdl'];
1726
-                            $contentStr .= ' wsdl:arrayType="' . $this->contractQName($v) . '"';
1727
-                        } else {
1728
-                            $contentStr .= " $a=\"$v\"";
1729
-                        }
1730
-                    }
1731
-                    $contentStr .= "/>\n";
1732
-                }
1733
-            }
1734
-            // if restriction
1735
-            if (isset($attrs['restrictionBase']) && '' != $attrs['restrictionBase']) {
1736
-                $contentStr = "   <$schemaPrefix:restriction base=\"" . $this->contractQName($attrs['restrictionBase']) . "\">\n" . $contentStr . "   </$schemaPrefix:restriction>\n";
1737
-                // complex or simple content
1738
-                if ((isset($attrs['elements']) && count($attrs['elements']) > 0) || (isset($attrs['attrs']) && count($attrs['attrs']) > 0)) {
1739
-                    $contentStr = "  <$schemaPrefix:complexContent>\n" . $contentStr . "  </$schemaPrefix:complexContent>\n";
1740
-                }
1741
-            }
1742
-            // finalize complex type
1743
-            if ('' != $contentStr) {
1744
-                $contentStr = " <$schemaPrefix:complexType name=\"$typeName\">\n" . $contentStr . " </$schemaPrefix:complexType>\n";
1745
-            } else {
1746
-                $contentStr = " <$schemaPrefix:complexType name=\"$typeName\"/>\n";
1747
-            }
1748
-            $xml .= $contentStr;
1749
-        }
1750
-        // simple types
1751
-        if (isset($this->simpleTypes) && count($this->simpleTypes) > 0) {
1752
-            foreach ($this->simpleTypes as $typeName => $eParts) {
1753
-                $xml .= " <$schemaPrefix:simpleType name=\"$typeName\">\n  <$schemaPrefix:restriction base=\"" . $this->contractQName($eParts['type']) . "\">\n";
1754
-                if (isset($eParts['enumeration'])) {
1755
-                    foreach ($eParts['enumeration'] as $e) {
1756
-                        $xml .= "  <$schemaPrefix:enumeration value=\"$e\"/>\n";
1757
-                    }
1758
-                }
1759
-                $xml .= "  </$schemaPrefix:restriction>\n </$schemaPrefix:simpleType>";
1760
-            }
1761
-        }
1762
-        // elements
1763
-        if (isset($this->elements) && count($this->elements) > 0) {
1764
-            foreach ($this->elements as $element => $eParts) {
1765
-                $xml .= " <$schemaPrefix:element name=\"$element\" type=\"" . $this->contractQName($eParts['type']) . "\"/>\n";
1766
-            }
1767
-        }
1768
-        // attributes
1769
-        if (isset($this->attributes) && count($this->attributes) > 0) {
1770
-            foreach ($this->attributes as $attr => $aParts) {
1771
-                $xml .= " <$schemaPrefix:attribute name=\"$attr\" type=\"" . $this->contractQName($aParts['type']) . "\"\n/>";
1772
-            }
1773
-        }
1774
-        // finish 'er up
1775
-        $attr = '';
1776
-        foreach ($this->schemaInfo as $k => $v) {
1777
-            if ('elementFormDefault' === $k || 'attributeFormDefault' === $k) {
1778
-                $attr .= " $k=\"$v\"";
1779
-            }
1780
-        }
1781
-        $el = "<$schemaPrefix:schema$attr targetNamespace=\"$this->schemaTargetNamespace\"\n";
1782
-        foreach (array_diff($this->usedNamespaces, $this->enclosingNamespaces) as $nsp => $ns) {
1783
-            $el .= " xmlns:$nsp=\"$ns\"";
1784
-        }
1785
-        $xml = $el . ">\n" . $xml . "</$schemaPrefix:schema>\n";
1786
-        return $xml;
1787
-    }
1788
-
1789
-    /**
1790
-     * adds debug data to the clas level debug string
1791
-     *
1792
-     * @param    string $string debug data
1793
-     * @access   private
1794
-     */
1795
-    private function xdebug($string)
1796
-    {
1797
-        $this->debug('<' . $this->schemaTargetNamespace . '> ' . $string);
1798
-    }
1799
-
1800
-    /**
1801
-     * get the PHP type of a user defined type in the schema
1802
-     * PHP type is kind of a misnomer since it actually returns 'struct' for assoc. arrays
1803
-     * returns false if no type exists, or not w/ the given namespace
1804
-     * else returns a string that is either a native php type, or 'struct'
1805
-     *
1806
-     * @param string $type name of defined type
1807
-     * @param string $ns namespace of type
1808
-     * @return mixed
1809
-     * @access public
1810
-     * @deprecated
1811
-     */
1812
-    public function getPHPType($type, $ns)
1813
-    {
1814
-        if (isset($this->typemap[$ns][$type])) {
1815
-            //print "found type '$type' and ns $ns in typemap<br>";
1816
-            return $this->typemap[$ns][$type];
1817
-        } elseif (isset($this->complexTypes[$type])) {
1818
-            //print "getting type '$type' and ns $ns from complexTypes array<br>";
1819
-            return $this->complexTypes[$type]['phpType'];
1820
-        }
1821
-        return false;
1822
-    }
1823
-
1824
-    /**
1825
-     * returns an associative array of information about a given type
1826
-     * returns false if no type exists by the given name
1827
-     *
1828
-     *    For a complexType typeDef = array(
1829
-     *    'restrictionBase' => '',
1830
-     *    'phpType' => '',
1831
-     *    'compositor' => '(sequence|all)',
1832
-     *    'elements' => array(), // refs to elements array
1833
-     *    'attrs' => array() // refs to attributes array
1834
-     *    ... and so on (see addComplexType)
1835
-     *    )
1836
-     *
1837
-     *   For simpleType or element, the array has different keys.
1838
-     *
1839
-     * @param string $type
1840
-     * @return mixed
1841
-     * @access public
1842
-     * @see addComplexType
1843
-     * @see addSimpleType
1844
-     * @see addElement
1845
-     */
1846
-    public function getTypeDef($type)
1847
-    {
1848
-        //$this->debug("in getTypeDef for type $type");
1849
-        if ('^' === substr($type, -1)) {
1850
-            $is_element = 1;
1851
-            $type = substr($type, 0, -1);
1852
-        } else {
1853
-            $is_element = 0;
1854
-        }
1855
-
1856
-        if ((!$is_element) && isset($this->complexTypes[$type])) {
1857
-            $this->xdebug("in getTypeDef, found complexType $type");
1858
-            return $this->complexTypes[$type];
1859
-        } elseif ((!$is_element) && isset($this->simpleTypes[$type])) {
1860
-            $this->xdebug("in getTypeDef, found simpleType $type");
1861
-            if (!isset($this->simpleTypes[$type]['phpType'])) {
1862
-                // get info for type to tack onto the simple type
1863
-                // TODO: can this ever really apply (i.e. what is a simpleType really?)
1864
-                $uqType = substr($this->simpleTypes[$type]['type'], strrpos($this->simpleTypes[$type]['type'], ':') + 1);
1865
-                $ns = substr($this->simpleTypes[$type]['type'], 0, strrpos($this->simpleTypes[$type]['type'], ':'));
1866
-                $etype = $this->getTypeDef($uqType);
1867
-                if ($etype) {
1868
-                    $this->xdebug("in getTypeDef, found type for simpleType $type:");
1869
-                    $this->xdebug($this->varDump($etype));
1870
-                    if (isset($etype['phpType'])) {
1871
-                        $this->simpleTypes[$type]['phpType'] = $etype['phpType'];
1872
-                    }
1873
-                    if (isset($etype['elements'])) {
1874
-                        $this->simpleTypes[$type]['elements'] = $etype['elements'];
1875
-                    }
1876
-                }
1877
-            }
1878
-            return $this->simpleTypes[$type];
1879
-        } elseif (isset($this->elements[$type])) {
1880
-            $this->xdebug("in getTypeDef, found element $type");
1881
-            if (!isset($this->elements[$type]['phpType'])) {
1882
-                // get info for type to tack onto the element
1883
-                $uqType = substr($this->elements[$type]['type'], strrpos($this->elements[$type]['type'], ':') + 1);
1884
-                $ns = substr($this->elements[$type]['type'], 0, strrpos($this->elements[$type]['type'], ':'));
1885
-                $etype = $this->getTypeDef($uqType);
1886
-                if ($etype) {
1887
-                    $this->xdebug("in getTypeDef, found type for element $type:");
1888
-                    $this->xdebug($this->varDump($etype));
1889
-                    if (isset($etype['phpType'])) {
1890
-                        $this->elements[$type]['phpType'] = $etype['phpType'];
1891
-                    }
1892
-                    if (isset($etype['elements'])) {
1893
-                        $this->elements[$type]['elements'] = $etype['elements'];
1894
-                    }
1895
-                    if (isset($etype['extensionBase'])) {
1896
-                        $this->elements[$type]['extensionBase'] = $etype['extensionBase'];
1897
-                    }
1898
-                } elseif ('http://www.w3.org/2001/XMLSchema' === $ns) {
1899
-                    $this->xdebug("in getTypeDef, element $type is an XSD type");
1900
-                    $this->elements[$type]['phpType'] = 'scalar';
1901
-                }
1902
-            }
1903
-            return $this->elements[$type];
1904
-        } elseif (isset($this->attributes[$type])) {
1905
-            $this->xdebug("in getTypeDef, found attribute $type");
1906
-            return $this->attributes[$type];
1907
-        } elseif (preg_match('/_ContainedType$/', $type)) {
1908
-            $this->xdebug("in getTypeDef, have an untyped element $type");
1909
-            $typeDef['typeClass'] = 'simpleType';
1910
-            $typeDef['phpType'] = 'scalar';
1911
-            $typeDef['type'] = 'http://www.w3.org/2001/XMLSchema:string';
1912
-            return $typeDef;
1913
-        }
1914
-        $this->xdebug("in getTypeDef, did not find $type");
1915
-        return false;
1916
-    }
1917
-
1918
-    /**
1919
-     * returns a sample serialization of a given type, or false if no type by the given name
1920
-     *
1921
-     * @param string $type name of type
1922
-     * @return mixed
1923
-     * @access public
1924
-     * @deprecated
1925
-     */
1926
-    public function serializeTypeDef($type)
1927
-    {
1928
-        //print "in sTD() for type $type<br>";
1929
-        if (false !== ($typeDef = $this->getTypeDef($type))) {
1930
-            $str .= '<' . $type;
1931
-            if (is_array($typeDef['attrs'])) {
1932
-                foreach ($typeDef['attrs'] as $attName => $data) {
1933
-                    $str .= " $attName=\"{type = " . $data['type'] . '}"';
1934
-                }
1935
-            }
1936
-            $str .= ' xmlns="' . $this->schema['targetNamespace'] . '"';
1937
-            if (is_array($typeDef['elements']) && count($typeDef['elements']) > 0) {
1938
-                $str .= '>';
1939
-                foreach ($typeDef['elements'] as $element => $eData) {
1940
-                    $str .= $this->serializeTypeDef($element);
1941
-                }
1942
-                $str .= "</$type>";
1943
-            } elseif ('element' === $typeDef['typeClass']) {
1944
-                $str .= "></$type>";
1945
-            } else {
1946
-                $str .= '/>';
1947
-            }
1948
-            return $str;
1949
-        }
1950
-        return false;
1951
-    }
1952
-
1953
-    /**
1954
-     * returns HTML form elements that allow a user
1955
-     * to enter values for creating an instance of the given type.
1956
-     *
1957
-     * @param string $name name for type instance
1958
-     * @param string $type name of type
1959
-     * @return string
1960
-     * @access public
1961
-     * @deprecated
1962
-     */
1963
-    public function typeToForm($name, $type)
1964
-    {
1965
-        // get typedef
1966
-        if (false !== ($typeDef = $this->getTypeDef($type))) {
1967
-            // if struct
1968
-            if ('struct' === $typeDef['phpType']) {
1969
-                $buffer .= '<table>';
1970
-                foreach ($typeDef['elements'] as $child => $childDef) {
1971
-                    $buffer .= "
1972
-					<tr><td align='right'>$childDef[name] (type: " . $this->getLocalPart($childDef['type']) . "):</td>
1973
-					<td><input type='text' name='parameters[" . $name . "][$childDef[name]]'></td></tr>";
1974
-                }
1975
-                $buffer .= '</table>';
1976
-            // if array
1977
-            } elseif ('array' === $typeDef['phpType']) {
1978
-                $buffer .= '<table>';
1979
-                for ($i = 0; $i < 3; $i++) {
1980
-                    $buffer .= "
1981
-					<tr><td align='right'>array item (type: $typeDef[arrayType]):</td>
1982
-					<td><input type='text' name='parameters[" . $name . "][]'></td></tr>";
1983
-                }
1984
-                $buffer .= '</table>';
1985
-            // if scalar
1986
-            } else {
1987
-                $buffer .= "<input type='text' name='parameters[$name]'>";
1988
-            }
1989
-        } else {
1990
-            $buffer .= "<input type='text' name='parameters[$name]'>";
1991
-        }
1992
-        return $buffer;
1993
-    }
1994
-
1995
-    /**
1996
-     * adds a complex type to the schema
1997
-     *
1998
-     * example: array
1999
-     *
2000
-     * addType(
2001
-     *    'ArrayOfstring',
2002
-     *    'complexType',
2003
-     *    'array',
2004
-     *    '',
2005
-     *    'SOAP-ENC:Array',
2006
-     *    array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'string[]'),
2007
-     *    'xsd:string'
2008
-     * );
2009
-     *
2010
-     * example: PHP associative array ( SOAP Struct )
2011
-     *
2012
-     * addType(
2013
-     *    'SOAPStruct',
2014
-     *    'complexType',
2015
-     *    'struct',
2016
-     *    'all',
2017
-     *    array('myVar'=> array('name'=>'myVar','type'=>'string')
2018
-     * );
2019
-     *
2020
-     * @param string name
2021
-     * @param string typeClass (complexType|simpleType|attribute)
2022
-     * @param string phpType : currently supported are array and struct (php assoc array)
2023
-     * @param string $compositor (all|sequence|choice)
2024
-     * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
2025
-     * @param array $elements = array ( name = array(name=>'',type=>'') )
2026
-     * @param array $attrs = array(
2027
-     *    array(
2028
-     *        'ref' => "http://schemas.xmlsoap.org/soap/encoding/:arrayType",
2029
-     *        "http://schemas.xmlsoap.org/wsdl/:arrayType" => "string[]"
2030
-     *    )
2031
-     * )
2032
-     * @param string arrayType : namespace:name (http://www.w3.org/2001/XMLSchema:string)
2033
-     * @access public
2034
-     * @see    getTypeDef
2035
-     */
2036
-    public function addComplexType($name, $typeClass = 'complexType', $phpType = 'array', $compositor = '', $restrictionBase = '', $elements = [], $attrs = [], $arrayType = '')
2037
-    {
2038
-        $this->complexTypes[$name] = [
2039
-            'name' => $name,
2040
-            'typeClass' => $typeClass,
2041
-            'phpType' => $phpType,
2042
-            'compositor' => $compositor,
2043
-            'restrictionBase' => $restrictionBase,
2044
-            'elements' => $elements,
2045
-            'attrs' => $attrs,
2046
-            'arrayType' => $arrayType
2047
-        ];
2048
-
2049
-        $this->xdebug("addComplexType $name:");
2050
-        $this->appendDebug($this->varDump($this->complexTypes[$name]));
2051
-    }
2052
-
2053
-    /**
2054
-     * adds a simple type to the schema
2055
-     *
2056
-     * @param string $name
2057
-     * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
2058
-     * @param string $typeClass (should always be simpleType)
2059
-     * @param string $phpType (should always be scalar)
2060
-     * @param array $enumeration array of values
2061
-     * @access public
2062
-     * @see nusoap_xmlschema
2063
-     * @see getTypeDef
2064
-     */
2065
-    public function addSimpleType($name, $restrictionBase = '', $typeClass = 'simpleType', $phpType = 'scalar', $enumeration = [])
2066
-    {
2067
-        $this->simpleTypes[$name] = [
2068
-            'name' => $name,
2069
-            'typeClass' => $typeClass,
2070
-            'phpType' => $phpType,
2071
-            'type' => $restrictionBase,
2072
-            'enumeration' => $enumeration
2073
-        ];
2074
-
2075
-        $this->xdebug("addSimpleType $name:");
2076
-        $this->appendDebug($this->varDump($this->simpleTypes[$name]));
2077
-    }
2078
-
2079
-    /**
2080
-     * adds an element to the schema
2081
-     *
2082
-     * @param array $attrs attributes that must include name and type
2083
-     * @see nusoap_xmlschema
2084
-     * @access public
2085
-     */
2086
-    public function addElement($attrs)
2087
-    {
2088
-        if (!$this->getPrefix($attrs['type'])) {
2089
-            $attrs['type'] = $this->schemaTargetNamespace . ':' . $attrs['type'];
2090
-        }
2091
-        $this->elements[$attrs['name']] = $attrs;
2092
-        $this->elements[$attrs['name']]['typeClass'] = 'element';
2093
-
2094
-        $this->xdebug('addElement ' . $attrs['name']);
2095
-        $this->appendDebug($this->varDump($this->elements[$attrs['name']]));
2096
-    }
2097
-}
1189
+		// parse xml file
1190
+		if ('' != $xml) {
1191
+			$this->debug('initial xml file: ' . $xml);
1192
+			$this->parseFile($xml, 'xml');
1193
+		}
1194
+	}
2098 1195
 
2099
-/**
2100
- * Backward compatibility
2101
- */
2102
-class XMLSchema extends nusoap_xmlschema
2103
-{
2104
-}
1196
+	/**
1197
+	 * parse an XML file
1198
+	 *
1199
+	 * @param string $xml path/URL to XML file
1200
+	 * @param string $type (schema | xml)
1201
+	 * @return boolean
1202
+	 * @access public
1203
+	 */
1204
+	public function parseFile($xml, $type)
1205
+	{
1206
+		// parse xml file
1207
+		if ('' != $xml) {
1208
+			$xmlStr = @file_get_contents($xml);
1209
+			if ('' == $xmlStr) {
1210
+				$msg = 'Error reading XML from ' . $xml;
1211
+				$this->setError($msg);
1212
+				$this->debug($msg);
1213
+				return false;
1214
+			} else {
1215
+				$this->debug("parsing $xml");
1216
+				$this->parseString($xmlStr, $type);
1217
+				$this->debug("done parsing $xml");
1218
+				return true;
1219
+			}
1220
+		}
1221
+		return false;
1222
+	}
2105 1223
 
1224
+	/**
1225
+	 * parse an XML string
1226
+	 *
1227
+	 * @param    string $xml path or URL
1228
+	 * @param    string $type (schema|xml)
1229
+	 * @access   private
1230
+	 */
1231
+	private function parseString($xml, $type)
1232
+	{
1233
+		// parse xml string
1234
+		if ('' != $xml) {
1235
+
1236
+			// Create an XML parser.
1237
+			$this->parser = xml_parser_create();
1238
+			// Set the options for parsing the XML data.
1239
+			xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
1240
+
1241
+			// Set the object for the parser.
1242
+			xml_set_object($this->parser, $this);
1243
+
1244
+			// Set the element handlers for the parser.
1245
+			if ('schema' === $type) {
1246
+				xml_set_element_handler($this->parser, 'schemaStartElement', 'schemaEndElement');
1247
+				xml_set_character_data_handler($this->parser, 'schemaCharacterData');
1248
+			} elseif ('xml' === $type) {
1249
+				xml_set_element_handler($this->parser, 'xmlStartElement', 'xmlEndElement');
1250
+				xml_set_character_data_handler($this->parser, 'xmlCharacterData');
1251
+			}
1252
+
1253
+			// Parse the XML file.
1254
+			if (!xml_parse($this->parser, $xml, true)) {
1255
+				// Display an error message.
1256
+				$errstr = sprintf(
1257
+					'XML error parsing XML schema on line %d: %s',
1258
+					xml_get_current_line_number($this->parser),
1259
+					xml_error_string(xml_get_error_code($this->parser))
1260
+				);
1261
+				$this->debug($errstr);
1262
+				$this->debug("XML payload:\n" . $xml);
1263
+				$this->setError($errstr);
1264
+			}
1265
+
1266
+			xml_parser_free($this->parser);
1267
+			unset($this->parser);
1268
+		} else {
1269
+			$this->debug('no xml passed to parseString()!!');
1270
+			$this->setError('no xml passed to parseString()!!');
1271
+		}
1272
+	}
2106 1273
 
2107
-/**
2108
- * For creating serializable abstractions of native PHP types.  This class
2109
- * allows element name/namespace, XSD type, and XML attributes to be
1274
+	/**
1275
+	 * gets a type name for an unnamed type
1276
+	 *
1277
+	 * @param    string    Element name
1278
+	 * @return    string    A type name for an unnamed type
1279
+	 * @access    private
1280
+	 */
1281
+	private function CreateTypeName($ename)
1282
+	{
1283
+		$scope = '';
1284
+		for ($i = 0, $iMax = count($this->complexTypeStack); $i < $iMax; $i++) {
1285
+			$scope .= $this->complexTypeStack[$i] . '_';
1286
+		}
1287
+		return $scope . $ename . '_ContainedType';
1288
+	}
1289
+
1290
+	/**
1291
+	 * start-element handler
1292
+	 *
1293
+	 * @param    string $parser XML parser object
1294
+	 * @param    string $name element name
1295
+	 * @param    string|array $attrs associative array of attributes
1296
+	 * @access   private
1297
+	 */
1298
+	public function schemaStartElement($parser, $name, $attrs)
1299
+	{
1300
+
1301
+		// position in the total number of elements, starting from 0
1302
+		$pos = $this->position++;
1303
+		$depth = $this->depth++;
1304
+		// set self as current value for this depth
1305
+		$this->depth_array[$depth] = $pos;
1306
+		$this->message[$pos] = ['cdata' => ''];
1307
+		if ($depth > 0) {
1308
+			$this->defaultNamespace[$pos] = $this->defaultNamespace[$this->depth_array[$depth - 1]];
1309
+		} else {
1310
+			$this->defaultNamespace[$pos] = false;
1311
+		}
1312
+
1313
+		// get element prefix
1314
+		if (false !== ($prefix = $this->getPrefix($name))) {
1315
+			// get unqualified name
1316
+			$name = $this->getLocalPart($name);
1317
+		} else {
1318
+			$prefix = '';
1319
+		}
1320
+
1321
+		// loop thru attributes, expanding, and registering namespace declarations
1322
+		if (is_array($attrs) && count($attrs) > 0) {
1323
+			foreach ($attrs as $k => $v) {
1324
+				// if ns declarations, add to class level array of valid namespaces
1325
+				if (preg_match('/^xmlns/', $k)) {
1326
+					//$this->xdebug("$k: $v");
1327
+					//$this->xdebug('ns_prefix: '.$this->getPrefix($k));
1328
+					if (false !== ($ns_prefix = substr(strrchr($k, ':'), 1))) {
1329
+						//$this->xdebug("Add namespace[$ns_prefix] = $v");
1330
+						$this->namespaces[$ns_prefix] = $v;
1331
+					} else {
1332
+						$this->defaultNamespace[$pos] = $v;
1333
+						if (!$this->getPrefixFromNamespace($v)) {
1334
+							$this->namespaces['ns' . (count($this->namespaces) + 1)] = $v;
1335
+						}
1336
+					}
1337
+					if ('http://www.w3.org/2001/XMLSchema' === $v || 'http://www.w3.org/1999/XMLSchema' === $v || 'http://www.w3.org/2000/10/XMLSchema' === $v) {
1338
+						$this->XMLSchemaVersion = $v;
1339
+						$this->namespaces['xsi'] = $v . '-instance';
1340
+					}
1341
+				}
1342
+			}
1343
+			foreach ($attrs as $k => $v) {
1344
+				// expand each attribute
1345
+				$k = strpos($k, ':') ? $this->expandQname($k) : $k;
1346
+				$v = strpos($v, ':') ? $this->expandQname($v) : $v;
1347
+				$eAttrs[$k] = $v;
1348
+			}
1349
+			$attrs = $eAttrs;
1350
+		} else {
1351
+			$attrs = [];
1352
+		}
1353
+		// find status, register data
1354
+		switch ($name) {
1355
+			case 'all':            // (optional) compositor content for a complexType
1356
+			case 'choice':
1357
+			case 'group':
1358
+			case 'sequence':
1359
+				//$this->xdebug("compositor $name for currentComplexType: $this->currentComplexType and currentElement: $this->currentElement");
1360
+				$this->complexTypes[$this->currentComplexType]['compositor'] = $name;
1361
+				//if($name == 'all' || $name == 'sequence'){
1362
+				//	$this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
1363
+				//}
1364
+				break;
1365
+			case 'attribute':    // complexType attribute
1366
+				//$this->xdebug("parsing attribute $attrs[name] $attrs[ref] of value: ".$attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']);
1367
+				$this->xdebug('parsing attribute:');
1368
+				$this->appendDebug($this->varDump($attrs));
1369
+				if (!isset($attrs['form'])) {
1370
+					// TODO: handle globals
1371
+					$attrs['form'] = $this->schemaInfo['attributeFormDefault'];
1372
+				}
1373
+				if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
1374
+					$v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
1375
+					if (!strpos($v, ':')) {
1376
+						// no namespace in arrayType attribute value...
1377
+						if ($this->defaultNamespace[$pos]) {
1378
+							// ...so use the default
1379
+							$attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'] = $this->defaultNamespace[$pos] . ':' . $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
1380
+						}
1381
+					}
1382
+				}
1383
+				if (isset($attrs['name'])) {
1384
+					$this->attributes[$attrs['name']] = $attrs;
1385
+					$aname = $attrs['name'];
1386
+				} elseif (isset($attrs['ref']) && 'http://schemas.xmlsoap.org/soap/encoding/:arrayType' === $attrs['ref']) {
1387
+					if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
1388
+						$aname = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
1389
+					} else {
1390
+						$aname = '';
1391
+					}
1392
+				} elseif (isset($attrs['ref'])) {
1393
+					$aname = $attrs['ref'];
1394
+					$this->attributes[$attrs['ref']] = $attrs;
1395
+				}
1396
+
1397
+				if ($this->currentComplexType) {    // This should *always* be
1398
+					$this->complexTypes[$this->currentComplexType]['attrs'][$aname] = $attrs;
1399
+				}
1400
+				// arrayType attribute
1401
+				if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']) || 'arrayType' === $this->getLocalPart($aname)) {
1402
+					$this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
1403
+					$prefix = $this->getPrefix($aname);
1404
+					if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
1405
+						$v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
1406
+					} else {
1407
+						$v = '';
1408
+					}
1409
+					if (strpos($v, '[,]')) {
1410
+						$this->complexTypes[$this->currentComplexType]['multidimensional'] = true;
1411
+					}
1412
+					$v = substr($v, 0, strpos($v, '[')); // clip the []
1413
+					if (!strpos($v, ':') && isset($this->typemap[$this->XMLSchemaVersion][$v])) {
1414
+						$v = $this->XMLSchemaVersion . ':' . $v;
1415
+					}
1416
+					$this->complexTypes[$this->currentComplexType]['arrayType'] = $v;
1417
+				}
1418
+				break;
1419
+			case 'complexContent':    // (optional) content for a complexType
1420
+				$this->xdebug("do nothing for element $name");
1421
+				break;
1422
+			case 'complexType':
1423
+				array_push($this->complexTypeStack, $this->currentComplexType);
1424
+				if (isset($attrs['name'])) {
1425
+					// TODO: what is the scope of named complexTypes that appear
1426
+					//       nested within other c complexTypes?
1427
+					$this->xdebug('processing named complexType ' . $attrs['name']);
1428
+					//$this->currentElement = false;
1429
+					$this->currentComplexType = $attrs['name'];
1430
+					$this->complexTypes[$this->currentComplexType] = $attrs;
1431
+					$this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType';
1432
+					// This is for constructs like
1433
+					//           <complexType name="ListOfString" base="soap:Array">
1434
+					//                <sequence>
1435
+					//                    <element name="string" type="xsd:string"
1436
+					//                        minOccurs="0" maxOccurs="unbounded" />
1437
+					//                </sequence>
1438
+					//            </complexType>
1439
+					if (isset($attrs['base']) && preg_match('/:Array$/', $attrs['base'])) {
1440
+						$this->xdebug('complexType is unusual array');
1441
+						$this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
1442
+					} else {
1443
+						$this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
1444
+					}
1445
+				} else {
1446
+					$name = $this->CreateTypeName($this->currentElement);
1447
+					$this->xdebug('processing unnamed complexType for element ' . $this->currentElement . ' named ' . $name);
1448
+					$this->currentComplexType = $name;
1449
+					//$this->currentElement = false;
1450
+					$this->complexTypes[$this->currentComplexType] = $attrs;
1451
+					$this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType';
1452
+					// This is for constructs like
1453
+					//           <complexType name="ListOfString" base="soap:Array">
1454
+					//                <sequence>
1455
+					//                    <element name="string" type="xsd:string"
1456
+					//                        minOccurs="0" maxOccurs="unbounded" />
1457
+					//                </sequence>
1458
+					//            </complexType>
1459
+					if (isset($attrs['base']) && preg_match('/:Array$/', $attrs['base'])) {
1460
+						$this->xdebug('complexType is unusual array');
1461
+						$this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
1462
+					} else {
1463
+						$this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
1464
+					}
1465
+				}
1466
+				$this->complexTypes[$this->currentComplexType]['simpleContent'] = 'false';
1467
+				break;
1468
+			case 'element':
1469
+				array_push($this->elementStack, $this->currentElement);
1470
+				if (!isset($attrs['form'])) {
1471
+					if ($this->currentComplexType) {
1472
+						$attrs['form'] = $this->schemaInfo['elementFormDefault'];
1473
+					} else {
1474
+						// global
1475
+						$attrs['form'] = 'qualified';
1476
+					}
1477
+				}
1478
+				if (isset($attrs['type'])) {
1479
+					$this->xdebug('processing typed element ' . $attrs['name'] . ' of type ' . $attrs['type']);
1480
+					if (!$this->getPrefix($attrs['type'])) {
1481
+						if ($this->defaultNamespace[$pos]) {
1482
+							$attrs['type'] = $this->defaultNamespace[$pos] . ':' . $attrs['type'];
1483
+							$this->xdebug('used default namespace to make type ' . $attrs['type']);
1484
+						}
1485
+					}
1486
+					// This is for constructs like
1487
+					//           <complexType name="ListOfString" base="soap:Array">
1488
+					//                <sequence>
1489
+					//                    <element name="string" type="xsd:string"
1490
+					//                        minOccurs="0" maxOccurs="unbounded" />
1491
+					//                </sequence>
1492
+					//            </complexType>
1493
+					if ($this->currentComplexType && 'array' === $this->complexTypes[$this->currentComplexType]['phpType']) {
1494
+						$this->xdebug('arrayType for unusual array is ' . $attrs['type']);
1495
+						$this->complexTypes[$this->currentComplexType]['arrayType'] = $attrs['type'];
1496
+					}
1497
+					$this->currentElement = $attrs['name'];
1498
+					$ename = $attrs['name'];
1499
+				} elseif (isset($attrs['ref'])) {
1500
+					$this->xdebug('processing element as ref to ' . $attrs['ref']);
1501
+					$this->currentElement = 'ref to ' . $attrs['ref'];
1502
+					$ename = $this->getLocalPart($attrs['ref']);
1503
+				} else {
1504
+					$type = $this->CreateTypeName($this->currentComplexType . '_' . $attrs['name']);
1505
+					$this->xdebug('processing untyped element ' . $attrs['name'] . ' type ' . $type);
1506
+					$this->currentElement = $attrs['name'];
1507
+					$attrs['type'] = $this->schemaTargetNamespace . ':' . $type;
1508
+					$ename = $attrs['name'];
1509
+				}
1510
+				if (isset($ename) && $this->currentComplexType) {
1511
+					$this->xdebug("add element $ename to complexType $this->currentComplexType");
1512
+					$this->complexTypes[$this->currentComplexType]['elements'][$ename] = $attrs;
1513
+				} elseif (!isset($attrs['ref'])) {
1514
+					$this->xdebug("add element $ename to elements array");
1515
+					$this->elements[$attrs['name']] = $attrs;
1516
+					$this->elements[$attrs['name']]['typeClass'] = 'element';
1517
+				}
1518
+				break;
1519
+			case 'enumeration':    //	restriction value list member
1520
+				$this->xdebug('enumeration ' . $attrs['value']);
1521
+				if ($this->currentSimpleType) {
1522
+					$this->simpleTypes[$this->currentSimpleType]['enumeration'][] = $attrs['value'];
1523
+				} elseif ($this->currentComplexType) {
1524
+					$this->complexTypes[$this->currentComplexType]['enumeration'][] = $attrs['value'];
1525
+				}
1526
+				break;
1527
+			case 'extension':    // simpleContent or complexContent type extension
1528
+				$this->xdebug('extension ' . $attrs['base']);
1529
+				if ($this->currentComplexType) {
1530
+					$ns = $this->getPrefix($attrs['base']);
1531
+					if ('' == $ns) {
1532
+						$this->complexTypes[$this->currentComplexType]['extensionBase'] = $this->schemaTargetNamespace . ':' . $attrs['base'];
1533
+					} else {
1534
+						$this->complexTypes[$this->currentComplexType]['extensionBase'] = $attrs['base'];
1535
+					}
1536
+				} else {
1537
+					$this->xdebug('no current complexType to set extensionBase');
1538
+				}
1539
+				break;
1540
+			case 'import':
1541
+				if (isset($attrs['schemaLocation'])) {
1542
+					$this->xdebug('import namespace ' . $attrs['namespace'] . ' from ' . $attrs['schemaLocation']);
1543
+					$this->imports[$attrs['namespace']][] = ['location' => $attrs['schemaLocation'], 'loaded' => false];
1544
+				} else {
1545
+					$this->xdebug('import namespace ' . $attrs['namespace']);
1546
+					$this->imports[$attrs['namespace']][] = ['location' => '', 'loaded' => true];
1547
+					if (!$this->getPrefixFromNamespace($attrs['namespace'])) {
1548
+						$this->namespaces['ns' . (count($this->namespaces) + 1)] = $attrs['namespace'];
1549
+					}
1550
+				}
1551
+				break;
1552
+			case 'include':
1553
+				if (isset($attrs['schemaLocation'])) {
1554
+					$this->xdebug('include into namespace ' . $this->schemaTargetNamespace . ' from ' . $attrs['schemaLocation']);
1555
+					$this->imports[$this->schemaTargetNamespace][] = ['location' => $attrs['schemaLocation'], 'loaded' => false];
1556
+				} else {
1557
+					$this->xdebug('ignoring invalid XML Schema construct: include without schemaLocation attribute');
1558
+				}
1559
+				break;
1560
+			case 'list':    // simpleType value list
1561
+				$this->xdebug("do nothing for element $name");
1562
+				break;
1563
+			case 'restriction':    // simpleType, simpleContent or complexContent value restriction
1564
+				$this->xdebug('restriction ' . $attrs['base']);
1565
+				if ($this->currentSimpleType) {
1566
+					$this->simpleTypes[$this->currentSimpleType]['type'] = $attrs['base'];
1567
+				} elseif ($this->currentComplexType) {
1568
+					$this->complexTypes[$this->currentComplexType]['restrictionBase'] = $attrs['base'];
1569
+					if (':Array' === strstr($attrs['base'], ':')) {
1570
+						$this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
1571
+					}
1572
+				}
1573
+				break;
1574
+			case 'schema':
1575
+				$this->schemaInfo = $attrs;
1576
+				$this->schemaInfo['schemaVersion'] = $this->getNamespaceFromPrefix($prefix);
1577
+				if (isset($attrs['targetNamespace'])) {
1578
+					$this->schemaTargetNamespace = $attrs['targetNamespace'];
1579
+				}
1580
+				if (!isset($attrs['elementFormDefault'])) {
1581
+					$this->schemaInfo['elementFormDefault'] = 'unqualified';
1582
+				}
1583
+				if (!isset($attrs['attributeFormDefault'])) {
1584
+					$this->schemaInfo['attributeFormDefault'] = 'unqualified';
1585
+				}
1586
+				break;
1587
+			case 'simpleContent':    // (optional) content for a complexType
1588
+				if ($this->currentComplexType) {    // This should *always* be
1589
+					$this->complexTypes[$this->currentComplexType]['simpleContent'] = 'true';
1590
+				} else {
1591
+					$this->xdebug("do nothing for element $name because there is no current complexType");
1592
+				}
1593
+				break;
1594
+			case 'simpleType':
1595
+				array_push($this->simpleTypeStack, $this->currentSimpleType);
1596
+				if (isset($attrs['name'])) {
1597
+					$this->xdebug('processing simpleType for name ' . $attrs['name']);
1598
+					$this->currentSimpleType = $attrs['name'];
1599
+					$this->simpleTypes[$attrs['name']] = $attrs;
1600
+					$this->simpleTypes[$attrs['name']]['typeClass'] = 'simpleType';
1601
+					$this->simpleTypes[$attrs['name']]['phpType'] = 'scalar';
1602
+				} else {
1603
+					$name = $this->CreateTypeName($this->currentComplexType . '_' . $this->currentElement);
1604
+					$this->xdebug('processing unnamed simpleType for element ' . $this->currentElement . ' named ' . $name);
1605
+					$this->currentSimpleType = $name;
1606
+					//$this->currentElement = false;
1607
+					$this->simpleTypes[$this->currentSimpleType] = $attrs;
1608
+					$this->simpleTypes[$this->currentSimpleType]['phpType'] = 'scalar';
1609
+				}
1610
+				break;
1611
+			case 'union':    // simpleType type list
1612
+				$this->xdebug("do nothing for element $name");
1613
+				break;
1614
+			default:
1615
+				$this->xdebug("do not have any logic to process element $name");
1616
+		}
1617
+	}
1618
+
1619
+	/**
1620
+	 * end-element handler
1621
+	 *
1622
+	 * @param    string $parser XML parser object
1623
+	 * @param    string $name element name
1624
+	 * @access   private
1625
+	 */
1626
+	private function schemaEndElement($parser, $name)
1627
+	{
1628
+		// bring depth down a notch
1629
+		$this->depth--;
1630
+		// position of current element is equal to the last value left in depth_array for my depth
1631
+		if (isset($this->depth_array[$this->depth])) {
1632
+			$pos = $this->depth_array[$this->depth];
1633
+		}
1634
+		// get element prefix
1635
+		if (false !== ($prefix = $this->getPrefix($name))) {
1636
+			// get unqualified name
1637
+			$name = $this->getLocalPart($name);
1638
+		} else {
1639
+			$prefix = '';
1640
+		}
1641
+		// move on...
1642
+		if ('complexType' === $name) {
1643
+			$this->xdebug('done processing complexType ' . ($this->currentComplexType ?: '(unknown)'));
1644
+			$this->xdebug($this->varDump($this->complexTypes[$this->currentComplexType]));
1645
+			$this->currentComplexType = array_pop($this->complexTypeStack);
1646
+			//$this->currentElement = false;
1647
+		}
1648
+		if ('element' === $name) {
1649
+			$this->xdebug('done processing element ' . ($this->currentElement ?: '(unknown)'));
1650
+			$this->currentElement = array_pop($this->elementStack);
1651
+		}
1652
+		if ('simpleType' === $name) {
1653
+			$this->xdebug('done processing simpleType ' . ($this->currentSimpleType ?: '(unknown)'));
1654
+			$this->xdebug($this->varDump($this->simpleTypes[$this->currentSimpleType]));
1655
+			$this->currentSimpleType = array_pop($this->simpleTypeStack);
1656
+		}
1657
+	}
1658
+
1659
+	/**
1660
+	 * element content handler
1661
+	 *
1662
+	 * @param    string $parser XML parser object
1663
+	 * @param    string $data element content
1664
+	 * @access   private
1665
+	 */
1666
+	private function schemaCharacterData($parser, $data)
1667
+	{
1668
+		$pos = $this->depth_array[$this->depth - 1];
1669
+		$this->message[$pos]['cdata'] .= $data;
1670
+	}
1671
+
1672
+	/**
1673
+	 * serialize the schema
1674
+	 *
1675
+	 * @access   public
1676
+	 */
1677
+	public function serializeSchema()
1678
+	{
1679
+		$schemaPrefix = $this->getPrefixFromNamespace($this->XMLSchemaVersion);
1680
+		$xml = '';
1681
+		// imports
1682
+		if (is_array($this->imports) && count($this->imports) > 0) {
1683
+			foreach ($this->imports as $ns => $list) {
1684
+				foreach ($list as $ii) {
1685
+					if ('' != $ii['location']) {
1686
+						$xml .= " <$schemaPrefix:import location=\"" . $ii['location'] . '" namespace="' . $ns . "\" />\n";
1687
+					} else {
1688
+						$xml .= " <$schemaPrefix:import namespace=\"" . $ns . "\" />\n";
1689
+					}
1690
+				}
1691
+			}
1692
+		}
1693
+		// complex types
1694
+		foreach ($this->complexTypes as $typeName => $attrs) {
1695
+			$contentStr = '';
1696
+			// serialize child elements
1697
+			if (isset($attrs['elements']) && (count($attrs['elements']) > 0)) {
1698
+				foreach ($attrs['elements'] as $element => $eParts) {
1699
+					if (isset($eParts['ref'])) {
1700
+						$contentStr .= "   <$schemaPrefix:element ref=\"$element\"/>\n";
1701
+					} else {
1702
+						$contentStr .= "   <$schemaPrefix:element name=\"$element\" type=\"" . $this->contractQName($eParts['type']) . '"';
1703
+						foreach ($eParts as $aName => $aValue) {
1704
+							// handle, e.g., abstract, default, form, minOccurs, maxOccurs, nillable
1705
+							if ('name' !== $aName && 'type' !== $aName) {
1706
+								$contentStr .= " $aName=\"$aValue\"";
1707
+							}
1708
+						}
1709
+						$contentStr .= "/>\n";
1710
+					}
1711
+				}
1712
+				// compositor wraps elements
1713
+				if (isset($attrs['compositor']) && ('' != $attrs['compositor'])) {
1714
+					$contentStr = "  <$schemaPrefix:$attrs[compositor]>\n" . $contentStr . "  </$schemaPrefix:$attrs[compositor]>\n";
1715
+				}
1716
+			}
1717
+			// attributes
1718
+			if (isset($attrs['attrs']) && (count($attrs['attrs']) >= 1)) {
1719
+				foreach ($attrs['attrs'] as $attr => $aParts) {
1720
+					$contentStr .= "    <$schemaPrefix:attribute";
1721
+					foreach ($aParts as $a => $v) {
1722
+						if ('ref' === $a || 'type' === $a) {
1723
+							$contentStr .= " $a=\"" . $this->contractQName($v) . '"';
1724
+						} elseif ('http://schemas.xmlsoap.org/wsdl/:arrayType' === $a) {
1725
+							$this->usedNamespaces['wsdl'] = $this->namespaces['wsdl'];
1726
+							$contentStr .= ' wsdl:arrayType="' . $this->contractQName($v) . '"';
1727
+						} else {
1728
+							$contentStr .= " $a=\"$v\"";
1729
+						}
1730
+					}
1731
+					$contentStr .= "/>\n";
1732
+				}
1733
+			}
1734
+			// if restriction
1735
+			if (isset($attrs['restrictionBase']) && '' != $attrs['restrictionBase']) {
1736
+				$contentStr = "   <$schemaPrefix:restriction base=\"" . $this->contractQName($attrs['restrictionBase']) . "\">\n" . $contentStr . "   </$schemaPrefix:restriction>\n";
1737
+				// complex or simple content
1738
+				if ((isset($attrs['elements']) && count($attrs['elements']) > 0) || (isset($attrs['attrs']) && count($attrs['attrs']) > 0)) {
1739
+					$contentStr = "  <$schemaPrefix:complexContent>\n" . $contentStr . "  </$schemaPrefix:complexContent>\n";
1740
+				}
1741
+			}
1742
+			// finalize complex type
1743
+			if ('' != $contentStr) {
1744
+				$contentStr = " <$schemaPrefix:complexType name=\"$typeName\">\n" . $contentStr . " </$schemaPrefix:complexType>\n";
1745
+			} else {
1746
+				$contentStr = " <$schemaPrefix:complexType name=\"$typeName\"/>\n";
1747
+			}
1748
+			$xml .= $contentStr;
1749
+		}
1750
+		// simple types
1751
+		if (isset($this->simpleTypes) && count($this->simpleTypes) > 0) {
1752
+			foreach ($this->simpleTypes as $typeName => $eParts) {
1753
+				$xml .= " <$schemaPrefix:simpleType name=\"$typeName\">\n  <$schemaPrefix:restriction base=\"" . $this->contractQName($eParts['type']) . "\">\n";
1754
+				if (isset($eParts['enumeration'])) {
1755
+					foreach ($eParts['enumeration'] as $e) {
1756
+						$xml .= "  <$schemaPrefix:enumeration value=\"$e\"/>\n";
1757
+					}
1758
+				}
1759
+				$xml .= "  </$schemaPrefix:restriction>\n </$schemaPrefix:simpleType>";
1760
+			}
1761
+		}
1762
+		// elements
1763
+		if (isset($this->elements) && count($this->elements) > 0) {
1764
+			foreach ($this->elements as $element => $eParts) {
1765
+				$xml .= " <$schemaPrefix:element name=\"$element\" type=\"" . $this->contractQName($eParts['type']) . "\"/>\n";
1766
+			}
1767
+		}
1768
+		// attributes
1769
+		if (isset($this->attributes) && count($this->attributes) > 0) {
1770
+			foreach ($this->attributes as $attr => $aParts) {
1771
+				$xml .= " <$schemaPrefix:attribute name=\"$attr\" type=\"" . $this->contractQName($aParts['type']) . "\"\n/>";
1772
+			}
1773
+		}
1774
+		// finish 'er up
1775
+		$attr = '';
1776
+		foreach ($this->schemaInfo as $k => $v) {
1777
+			if ('elementFormDefault' === $k || 'attributeFormDefault' === $k) {
1778
+				$attr .= " $k=\"$v\"";
1779
+			}
1780
+		}
1781
+		$el = "<$schemaPrefix:schema$attr targetNamespace=\"$this->schemaTargetNamespace\"\n";
1782
+		foreach (array_diff($this->usedNamespaces, $this->enclosingNamespaces) as $nsp => $ns) {
1783
+			$el .= " xmlns:$nsp=\"$ns\"";
1784
+		}
1785
+		$xml = $el . ">\n" . $xml . "</$schemaPrefix:schema>\n";
1786
+		return $xml;
1787
+	}
1788
+
1789
+	/**
1790
+	 * adds debug data to the clas level debug string
1791
+	 *
1792
+	 * @param    string $string debug data
1793
+	 * @access   private
1794
+	 */
1795
+	private function xdebug($string)
1796
+	{
1797
+		$this->debug('<' . $this->schemaTargetNamespace . '> ' . $string);
1798
+	}
1799
+
1800
+	/**
1801
+	 * get the PHP type of a user defined type in the schema
1802
+	 * PHP type is kind of a misnomer since it actually returns 'struct' for assoc. arrays
1803
+	 * returns false if no type exists, or not w/ the given namespace
1804
+	 * else returns a string that is either a native php type, or 'struct'
1805
+	 *
1806
+	 * @param string $type name of defined type
1807
+	 * @param string $ns namespace of type
1808
+	 * @return mixed
1809
+	 * @access public
1810
+	 * @deprecated
1811
+	 */
1812
+	public function getPHPType($type, $ns)
1813
+	{
1814
+		if (isset($this->typemap[$ns][$type])) {
1815
+			//print "found type '$type' and ns $ns in typemap<br>";
1816
+			return $this->typemap[$ns][$type];
1817
+		} elseif (isset($this->complexTypes[$type])) {
1818
+			//print "getting type '$type' and ns $ns from complexTypes array<br>";
1819
+			return $this->complexTypes[$type]['phpType'];
1820
+		}
1821
+		return false;
1822
+	}
1823
+
1824
+	/**
1825
+	 * returns an associative array of information about a given type
1826
+	 * returns false if no type exists by the given name
1827
+	 *
1828
+	 *    For a complexType typeDef = array(
1829
+	 *    'restrictionBase' => '',
1830
+	 *    'phpType' => '',
1831
+	 *    'compositor' => '(sequence|all)',
1832
+	 *    'elements' => array(), // refs to elements array
1833
+	 *    'attrs' => array() // refs to attributes array
1834
+	 *    ... and so on (see addComplexType)
1835
+	 *    )
1836
+	 *
1837
+	 *   For simpleType or element, the array has different keys.
1838
+	 *
1839
+	 * @param string $type
1840
+	 * @return mixed
1841
+	 * @access public
1842
+	 * @see addComplexType
1843
+	 * @see addSimpleType
1844
+	 * @see addElement
1845
+	 */
1846
+	public function getTypeDef($type)
1847
+	{
1848
+		//$this->debug("in getTypeDef for type $type");
1849
+		if ('^' === substr($type, -1)) {
1850
+			$is_element = 1;
1851
+			$type = substr($type, 0, -1);
1852
+		} else {
1853
+			$is_element = 0;
1854
+		}
1855
+
1856
+		if ((!$is_element) && isset($this->complexTypes[$type])) {
1857
+			$this->xdebug("in getTypeDef, found complexType $type");
1858
+			return $this->complexTypes[$type];
1859
+		} elseif ((!$is_element) && isset($this->simpleTypes[$type])) {
1860
+			$this->xdebug("in getTypeDef, found simpleType $type");
1861
+			if (!isset($this->simpleTypes[$type]['phpType'])) {
1862
+				// get info for type to tack onto the simple type
1863
+				// TODO: can this ever really apply (i.e. what is a simpleType really?)
1864
+				$uqType = substr($this->simpleTypes[$type]['type'], strrpos($this->simpleTypes[$type]['type'], ':') + 1);
1865
+				$ns = substr($this->simpleTypes[$type]['type'], 0, strrpos($this->simpleTypes[$type]['type'], ':'));
1866
+				$etype = $this->getTypeDef($uqType);
1867
+				if ($etype) {
1868
+					$this->xdebug("in getTypeDef, found type for simpleType $type:");
1869
+					$this->xdebug($this->varDump($etype));
1870
+					if (isset($etype['phpType'])) {
1871
+						$this->simpleTypes[$type]['phpType'] = $etype['phpType'];
1872
+					}
1873
+					if (isset($etype['elements'])) {
1874
+						$this->simpleTypes[$type]['elements'] = $etype['elements'];
1875
+					}
1876
+				}
1877
+			}
1878
+			return $this->simpleTypes[$type];
1879
+		} elseif (isset($this->elements[$type])) {
1880
+			$this->xdebug("in getTypeDef, found element $type");
1881
+			if (!isset($this->elements[$type]['phpType'])) {
1882
+				// get info for type to tack onto the element
1883
+				$uqType = substr($this->elements[$type]['type'], strrpos($this->elements[$type]['type'], ':') + 1);
1884
+				$ns = substr($this->elements[$type]['type'], 0, strrpos($this->elements[$type]['type'], ':'));
1885
+				$etype = $this->getTypeDef($uqType);
1886
+				if ($etype) {
1887
+					$this->xdebug("in getTypeDef, found type for element $type:");
1888
+					$this->xdebug($this->varDump($etype));
1889
+					if (isset($etype['phpType'])) {
1890
+						$this->elements[$type]['phpType'] = $etype['phpType'];
1891
+					}
1892
+					if (isset($etype['elements'])) {
1893
+						$this->elements[$type]['elements'] = $etype['elements'];
1894
+					}
1895
+					if (isset($etype['extensionBase'])) {
1896
+						$this->elements[$type]['extensionBase'] = $etype['extensionBase'];
1897
+					}
1898
+				} elseif ('http://www.w3.org/2001/XMLSchema' === $ns) {
1899
+					$this->xdebug("in getTypeDef, element $type is an XSD type");
1900
+					$this->elements[$type]['phpType'] = 'scalar';
1901
+				}
1902
+			}
1903
+			return $this->elements[$type];
1904
+		} elseif (isset($this->attributes[$type])) {
1905
+			$this->xdebug("in getTypeDef, found attribute $type");
1906
+			return $this->attributes[$type];
1907
+		} elseif (preg_match('/_ContainedType$/', $type)) {
1908
+			$this->xdebug("in getTypeDef, have an untyped element $type");
1909
+			$typeDef['typeClass'] = 'simpleType';
1910
+			$typeDef['phpType'] = 'scalar';
1911
+			$typeDef['type'] = 'http://www.w3.org/2001/XMLSchema:string';
1912
+			return $typeDef;
1913
+		}
1914
+		$this->xdebug("in getTypeDef, did not find $type");
1915
+		return false;
1916
+	}
1917
+
1918
+	/**
1919
+	 * returns a sample serialization of a given type, or false if no type by the given name
1920
+	 *
1921
+	 * @param string $type name of type
1922
+	 * @return mixed
1923
+	 * @access public
1924
+	 * @deprecated
1925
+	 */
1926
+	public function serializeTypeDef($type)
1927
+	{
1928
+		//print "in sTD() for type $type<br>";
1929
+		if (false !== ($typeDef = $this->getTypeDef($type))) {
1930
+			$str .= '<' . $type;
1931
+			if (is_array($typeDef['attrs'])) {
1932
+				foreach ($typeDef['attrs'] as $attName => $data) {
1933
+					$str .= " $attName=\"{type = " . $data['type'] . '}"';
1934
+				}
1935
+			}
1936
+			$str .= ' xmlns="' . $this->schema['targetNamespace'] . '"';
1937
+			if (is_array($typeDef['elements']) && count($typeDef['elements']) > 0) {
1938
+				$str .= '>';
1939
+				foreach ($typeDef['elements'] as $element => $eData) {
1940
+					$str .= $this->serializeTypeDef($element);
1941
+				}
1942
+				$str .= "</$type>";
1943
+			} elseif ('element' === $typeDef['typeClass']) {
1944
+				$str .= "></$type>";
1945
+			} else {
1946
+				$str .= '/>';
1947
+			}
1948
+			return $str;
1949
+		}
1950
+		return false;
1951
+	}
1952
+
1953
+	/**
1954
+	 * returns HTML form elements that allow a user
1955
+	 * to enter values for creating an instance of the given type.
1956
+	 *
1957
+	 * @param string $name name for type instance
1958
+	 * @param string $type name of type
1959
+	 * @return string
1960
+	 * @access public
1961
+	 * @deprecated
1962
+	 */
1963
+	public function typeToForm($name, $type)
1964
+	{
1965
+		// get typedef
1966
+		if (false !== ($typeDef = $this->getTypeDef($type))) {
1967
+			// if struct
1968
+			if ('struct' === $typeDef['phpType']) {
1969
+				$buffer .= '<table>';
1970
+				foreach ($typeDef['elements'] as $child => $childDef) {
1971
+					$buffer .= "
1972
+					<tr><td align='right'>$childDef[name] (type: " . $this->getLocalPart($childDef['type']) . "):</td>
1973
+					<td><input type='text' name='parameters[" . $name . "][$childDef[name]]'></td></tr>";
1974
+				}
1975
+				$buffer .= '</table>';
1976
+			// if array
1977
+			} elseif ('array' === $typeDef['phpType']) {
1978
+				$buffer .= '<table>';
1979
+				for ($i = 0; $i < 3; $i++) {
1980
+					$buffer .= "
1981
+					<tr><td align='right'>array item (type: $typeDef[arrayType]):</td>
1982
+					<td><input type='text' name='parameters[" . $name . "][]'></td></tr>";
1983
+				}
1984
+				$buffer .= '</table>';
1985
+			// if scalar
1986
+			} else {
1987
+				$buffer .= "<input type='text' name='parameters[$name]'>";
1988
+			}
1989
+		} else {
1990
+			$buffer .= "<input type='text' name='parameters[$name]'>";
1991
+		}
1992
+		return $buffer;
1993
+	}
1994
+
1995
+	/**
1996
+	 * adds a complex type to the schema
1997
+	 *
1998
+	 * example: array
1999
+	 *
2000
+	 * addType(
2001
+	 *    'ArrayOfstring',
2002
+	 *    'complexType',
2003
+	 *    'array',
2004
+	 *    '',
2005
+	 *    'SOAP-ENC:Array',
2006
+	 *    array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'string[]'),
2007
+	 *    'xsd:string'
2008
+	 * );
2009
+	 *
2010
+	 * example: PHP associative array ( SOAP Struct )
2011
+	 *
2012
+	 * addType(
2013
+	 *    'SOAPStruct',
2014
+	 *    'complexType',
2015
+	 *    'struct',
2016
+	 *    'all',
2017
+	 *    array('myVar'=> array('name'=>'myVar','type'=>'string')
2018
+	 * );
2019
+	 *
2020
+	 * @param string name
2021
+	 * @param string typeClass (complexType|simpleType|attribute)
2022
+	 * @param string phpType : currently supported are array and struct (php assoc array)
2023
+	 * @param string $compositor (all|sequence|choice)
2024
+	 * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
2025
+	 * @param array $elements = array ( name = array(name=>'',type=>'') )
2026
+	 * @param array $attrs = array(
2027
+	 *    array(
2028
+	 *        'ref' => "http://schemas.xmlsoap.org/soap/encoding/:arrayType",
2029
+	 *        "http://schemas.xmlsoap.org/wsdl/:arrayType" => "string[]"
2030
+	 *    )
2031
+	 * )
2032
+	 * @param string arrayType : namespace:name (http://www.w3.org/2001/XMLSchema:string)
2033
+	 * @access public
2034
+	 * @see    getTypeDef
2035
+	 */
2036
+	public function addComplexType($name, $typeClass = 'complexType', $phpType = 'array', $compositor = '', $restrictionBase = '', $elements = [], $attrs = [], $arrayType = '')
2037
+	{
2038
+		$this->complexTypes[$name] = [
2039
+			'name' => $name,
2040
+			'typeClass' => $typeClass,
2041
+			'phpType' => $phpType,
2042
+			'compositor' => $compositor,
2043
+			'restrictionBase' => $restrictionBase,
2044
+			'elements' => $elements,
2045
+			'attrs' => $attrs,
2046
+			'arrayType' => $arrayType
2047
+		];
2048
+
2049
+		$this->xdebug("addComplexType $name:");
2050
+		$this->appendDebug($this->varDump($this->complexTypes[$name]));
2051
+	}
2052
+
2053
+	/**
2054
+	 * adds a simple type to the schema
2055
+	 *
2056
+	 * @param string $name
2057
+	 * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
2058
+	 * @param string $typeClass (should always be simpleType)
2059
+	 * @param string $phpType (should always be scalar)
2060
+	 * @param array $enumeration array of values
2061
+	 * @access public
2062
+	 * @see nusoap_xmlschema
2063
+	 * @see getTypeDef
2064
+	 */
2065
+	public function addSimpleType($name, $restrictionBase = '', $typeClass = 'simpleType', $phpType = 'scalar', $enumeration = [])
2066
+	{
2067
+		$this->simpleTypes[$name] = [
2068
+			'name' => $name,
2069
+			'typeClass' => $typeClass,
2070
+			'phpType' => $phpType,
2071
+			'type' => $restrictionBase,
2072
+			'enumeration' => $enumeration
2073
+		];
2074
+
2075
+		$this->xdebug("addSimpleType $name:");
2076
+		$this->appendDebug($this->varDump($this->simpleTypes[$name]));
2077
+	}
2078
+
2079
+	/**
2080
+	 * adds an element to the schema
2081
+	 *
2082
+	 * @param array $attrs attributes that must include name and type
2083
+	 * @see nusoap_xmlschema
2084
+	 * @access public
2085
+	 */
2086
+	public function addElement($attrs)
2087
+	{
2088
+		if (!$this->getPrefix($attrs['type'])) {
2089
+			$attrs['type'] = $this->schemaTargetNamespace . ':' . $attrs['type'];
2090
+		}
2091
+		$this->elements[$attrs['name']] = $attrs;
2092
+		$this->elements[$attrs['name']]['typeClass'] = 'element';
2093
+
2094
+		$this->xdebug('addElement ' . $attrs['name']);
2095
+		$this->appendDebug($this->varDump($this->elements[$attrs['name']]));
2096
+	}
2097
+}
2098
+
2099
+/**
2100
+ * Backward compatibility
2101
+ */
2102
+class XMLSchema extends nusoap_xmlschema
2103
+{
2104
+}
2105
+
2106
+
2107
+/**
2108
+ * For creating serializable abstractions of native PHP types.  This class
2109
+ * allows element name/namespace, XSD type, and XML attributes to be
2110 2110
  * associated with a value.  This is extremely useful when WSDL is not
2111 2111
  * used, but is also useful when WSDL is used with polymorphic types, including
2112 2112
  * xsd:anyType and user-defined types.
@@ -2117,93 +2117,93 @@  discard block
 block discarded – undo
2117 2117
  */
2118 2118
 class soapval extends nusoap_base
2119 2119
 {
2120
-    /**
2121
-     * The XML element name
2122
-     *
2123
-     * @var string
2124
-     * @access private
2125
-     */
2126
-    private $name;
2127
-    /**
2128
-     * The XML type name (string or false)
2129
-     *
2130
-     * @var mixed
2131
-     * @access private
2132
-     */
2133
-    private $type;
2134
-    /**
2135
-     * The PHP value
2136
-     *
2137
-     * @var mixed
2138
-     * @access private
2139
-     */
2140
-    private $value;
2141
-    /**
2142
-     * The XML element namespace (string or false)
2143
-     *
2144
-     * @var mixed
2145
-     * @access private
2146
-     */
2147
-    private $element_ns;
2148
-    /**
2149
-     * The XML type namespace (string or false)
2150
-     *
2151
-     * @var mixed
2152
-     * @access private
2153
-     */
2154
-    private $type_ns;
2155
-    /**
2156
-     * The XML element attributes (array or false)
2157
-     *
2158
-     * @var mixed
2159
-     * @access private
2160
-     */
2161
-    private $attributes;
2162
-
2163
-    /**
2164
-     * constructor
2165
-     *
2166
-     * @param    string $name optional name
2167
-     * @param    mixed $type optional type name
2168
-     * @param    mixed $value optional value
2169
-     * @param    mixed $element_ns optional namespace of value
2170
-     * @param    mixed $type_ns optional namespace of type
2171
-     * @param    mixed $attributes associative array of attributes to add to element serialization
2172
-     * @access   public
2173
-     */
2174
-    public function __construct($name = 'soapval', $type = false, $value = -1, $element_ns = false, $type_ns = false, $attributes = false)
2175
-    {
2176
-        parent::__construct();
2177
-        $this->name = $name;
2178
-        $this->type = $type;
2179
-        $this->value = $value;
2180
-        $this->element_ns = $element_ns;
2181
-        $this->type_ns = $type_ns;
2182
-        $this->attributes = $attributes;
2183
-    }
2184
-
2185
-    /**
2186
-     * return serialized value
2187
-     *
2188
-     * @param    string $use The WSDL use value (encoded|literal)
2189
-     * @return    string XML data
2190
-     * @access   public
2191
-     */
2192
-    public function serialize($use = 'encoded')
2193
-    {
2194
-        return $this->serialize_val($this->value, $this->name, $this->type, $this->element_ns, $this->type_ns, $this->attributes, $use, true);
2195
-    }
2196
-
2197
-    /**
2198
-     * decodes a soapval object into a PHP native type
2199
-     *
2200
-     * @return    mixed
2201
-     * @access   public
2202
-     */
2203
-    public function decode()
2204
-    {
2205
-        return $this->value;
2206
-    }
2120
+	/**
2121
+	 * The XML element name
2122
+	 *
2123
+	 * @var string
2124
+	 * @access private
2125
+	 */
2126
+	private $name;
2127
+	/**
2128
+	 * The XML type name (string or false)
2129
+	 *
2130
+	 * @var mixed
2131
+	 * @access private
2132
+	 */
2133
+	private $type;
2134
+	/**
2135
+	 * The PHP value
2136
+	 *
2137
+	 * @var mixed
2138
+	 * @access private
2139
+	 */
2140
+	private $value;
2141
+	/**
2142
+	 * The XML element namespace (string or false)
2143
+	 *
2144
+	 * @var mixed
2145
+	 * @access private
2146
+	 */
2147
+	private $element_ns;
2148
+	/**
2149
+	 * The XML type namespace (string or false)
2150
+	 *
2151
+	 * @var mixed
2152
+	 * @access private
2153
+	 */
2154
+	private $type_ns;
2155
+	/**
2156
+	 * The XML element attributes (array or false)
2157
+	 *
2158
+	 * @var mixed
2159
+	 * @access private
2160
+	 */
2161
+	private $attributes;
2162
+
2163
+	/**
2164
+	 * constructor
2165
+	 *
2166
+	 * @param    string $name optional name
2167
+	 * @param    mixed $type optional type name
2168
+	 * @param    mixed $value optional value
2169
+	 * @param    mixed $element_ns optional namespace of value
2170
+	 * @param    mixed $type_ns optional namespace of type
2171
+	 * @param    mixed $attributes associative array of attributes to add to element serialization
2172
+	 * @access   public
2173
+	 */
2174
+	public function __construct($name = 'soapval', $type = false, $value = -1, $element_ns = false, $type_ns = false, $attributes = false)
2175
+	{
2176
+		parent::__construct();
2177
+		$this->name = $name;
2178
+		$this->type = $type;
2179
+		$this->value = $value;
2180
+		$this->element_ns = $element_ns;
2181
+		$this->type_ns = $type_ns;
2182
+		$this->attributes = $attributes;
2183
+	}
2184
+
2185
+	/**
2186
+	 * return serialized value
2187
+	 *
2188
+	 * @param    string $use The WSDL use value (encoded|literal)
2189
+	 * @return    string XML data
2190
+	 * @access   public
2191
+	 */
2192
+	public function serialize($use = 'encoded')
2193
+	{
2194
+		return $this->serialize_val($this->value, $this->name, $this->type, $this->element_ns, $this->type_ns, $this->attributes, $use, true);
2195
+	}
2196
+
2197
+	/**
2198
+	 * decodes a soapval object into a PHP native type
2199
+	 *
2200
+	 * @return    mixed
2201
+	 * @access   public
2202
+	 */
2203
+	public function decode()
2204
+	{
2205
+		return $this->value;
2206
+	}
2207 2207
 }
2208 2208
 
2209 2209
 
@@ -2218,1320 +2218,1320 @@  discard block
 block discarded – undo
2218 2218
  */
2219 2219
 class soap_transport_http extends nusoap_base
2220 2220
 {
2221
-    public $url = '';
2222
-    public $uri = '';
2223
-    public $digest_uri = '';
2224
-    public $scheme = '';
2225
-    public $host = '';
2226
-    public $port = '';
2227
-    public $path = '';
2228
-    public $request_method = 'POST';
2229
-    public $protocol_version = '1.0';
2230
-    public $encoding = '';
2231
-    public $outgoing_headers = [];
2232
-    public $incoming_headers = [];
2233
-    public $incoming_cookies = [];
2234
-    public $outgoing_payload = '';
2235
-    public $incoming_payload = '';
2236
-    public $response_status_line;    // HTTP response status line
2237
-    public $useSOAPAction = true;
2238
-    public $persistentConnection = false;
2239
-    public $ch = false;    // cURL handle
2240
-    public $ch_options = [];    // cURL custom options
2241
-    public $use_curl = false;        // force cURL use
2242
-    public $proxy;            // proxy information (associative array)
2243
-    public $username = '';
2244
-    public $password = '';
2245
-    public $authtype = '';
2246
-    public $digestRequest = [];
2247
-    public $certRequest = [];    // keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional)
2248
-    // cainfofile: certificate authority file, e.g. '$pathToPemFiles/rootca.pem'
2249
-    // sslcertfile: SSL certificate file, e.g. '$pathToPemFiles/mycert.pem'
2250
-    // sslkeyfile: SSL key file, e.g. '$pathToPemFiles/mykey.pem'
2251
-    // passphrase: SSL key password/passphrase
2252
-    // certpassword: SSL certificate password
2253
-    // verifypeer: default is 1
2254
-    // verifyhost: default is 1
2255
-
2256
-    /**
2257
-     * constructor
2258
-     *
2259
-     * @param string $url The URL to which to connect
2260
-     * @param array $curl_options User-specified cURL options
2261
-     * @param boolean $use_curl Whether to try to force cURL use
2262
-     * @access public
2263
-     */
2264
-    public function __construct($url, $curl_options = null, $use_curl = false)
2265
-    {
2266
-        parent::__construct();
2267
-        $this->debug("ctor url=$url use_curl=$use_curl curl_options:");
2268
-        $this->appendDebug($this->varDump($curl_options));
2269
-        $this->setURL($url);
2270
-        if (is_array($curl_options)) {
2271
-            $this->ch_options = $curl_options;
2272
-        }
2273
-        $this->use_curl = $use_curl;
2274
-        preg_match('/\$Revisio' . 'n: ([^ ]+)/', $this->revision, $rev);
2275
-        $this->setHeader('User-Agent', $this->title . '/' . $this->version . ' (' . $rev[1] . ')');
2276
-    }
2277
-
2278
-    /**
2279
-     * sets a cURL option
2280
-     *
2281
-     * @param    mixed $option The cURL option (always integer?)
2282
-     * @param    mixed $value The cURL option value
2283
-     * @access   private
2284
-     */
2285
-    private function setCurlOption($option, $value)
2286
-    {
2287
-        $this->debug("setCurlOption option=$option, value=");
2288
-        $this->appendDebug($this->varDump($value));
2289
-        curl_setopt($this->ch, $option, $value);
2290
-    }
2291
-
2292
-    /**
2293
-     * sets an HTTP header
2294
-     *
2295
-     * @param string $name The name of the header
2296
-     * @param string $value The value of the header
2297
-     * @access private
2298
-     */
2299
-    private function setHeader($name, $value)
2300
-    {
2301
-        $this->outgoing_headers[$name] = $value;
2302
-        $this->debug("set header $name: $value");
2303
-    }
2304
-
2305
-    /**
2306
-     * unsets an HTTP header
2307
-     *
2308
-     * @param string $name The name of the header
2309
-     * @access private
2310
-     */
2311
-    private function unsetHeader($name)
2312
-    {
2313
-        if (isset($this->outgoing_headers[$name])) {
2314
-            $this->debug("unset header $name");
2315
-            unset($this->outgoing_headers[$name]);
2316
-        }
2317
-    }
2318
-
2319
-    /**
2320
-     * sets the URL to which to connect
2321
-     *
2322
-     * @param string $url The URL to which to connect
2323
-     * @access private
2324
-     */
2325
-    private function setURL($url)
2326
-    {
2327
-        $this->url = $url;
2328
-
2329
-        $u = parse_url($url);
2330
-        foreach ($u as $k => $v) {
2331
-            $this->debug("parsed URL $k = $v");
2332
-            $this->$k = $v;
2333
-        }
2334
-
2335
-        // add any GET params to path
2336
-        if (isset($u['query']) && '' != $u['query']) {
2337
-            $this->path .= '?' . $u['query'];
2338
-        }
2339
-
2340
-        // set default port
2341
-        if (!isset($u['port'])) {
2342
-            if ('https' === $u['scheme']) {
2343
-                $this->port = 443;
2344
-            } else {
2345
-                $this->port = 80;
2346
-            }
2347
-        }
2348
-
2349
-        $this->uri = $this->path;
2350
-        $this->digest_uri = $this->uri;
2351
-
2352
-        // build headers
2353
-        if (!isset($u['port'])) {
2354
-            $this->setHeader('Host', $this->host);
2355
-        } else {
2356
-            $this->setHeader('Host', $this->host . ':' . $this->port);
2357
-        }
2358
-
2359
-        if (isset($u['user']) && '' != $u['user']) {
2360
-            $this->setCredentials(urldecode($u['user']), isset($u['pass']) ? urldecode($u['pass']) : '');
2361
-        }
2362
-    }
2363
-
2364
-    /**
2365
-     * gets the I/O method to use
2366
-     *
2367
-     * @return    string    I/O method to use (socket|curl|unknown)
2368
-     * @access    private
2369
-     */
2370
-    private function io_method()
2371
-    {
2372
-        if ($this->use_curl || ('https' === $this->scheme) || ('http' === $this->scheme && 'ntlm' === $this->authtype) || ('http' === $this->scheme && is_array($this->proxy) && 'ntlm' === $this->proxy['authtype'])) {
2373
-            return 'curl';
2374
-        }
2375
-        if (('http' === $this->scheme || 'ssl' === $this->scheme) && 'ntlm' !== $this->authtype && (!is_array($this->proxy) || 'ntlm' !== $this->proxy['authtype'])) {
2376
-            return 'socket';
2377
-        }
2378
-        return 'unknown';
2379
-    }
2380
-
2381
-    /**
2382
-     * establish an HTTP connection
2383
-     *
2384
-     * @param int $connection_timeout set connection timeout in seconds
2385
-     * @param int $response_timeout   set response timeout in seconds
2386
-     * @return bool true if connected, false if not
2387
-     * @access private
2388
-     */
2389
-    private function connect($connection_timeout = 0, $response_timeout = 30)
2390
-    {
2391
-        // For PHP 4.3 with OpenSSL, change https scheme to ssl, then treat like
2392
-        // "regular" socket.
2393
-        // TODO: disabled for now because OpenSSL must be *compiled* in (not just
2394
-        //       loaded), and until PHP5 stream_get_wrappers is not available.
2395
-        //	  	if ($this->scheme == 'https') {
2396
-        //		  	if (version_compare(phpversion(), '4.3.0') >= 0) {
2397
-        //		  		if (extension_loaded('openssl')) {
2398
-        //		  			$this->scheme = 'ssl';
2399
-        //		  			$this->debug('Using SSL over OpenSSL');
2400
-        //		  		}
2401
-        //		  	}
2402
-        //		}
2403
-        $this->debug("connect connection_timeout $connection_timeout, response_timeout $response_timeout, scheme $this->scheme, host $this->host, port $this->port");
2404
-        if ('socket' === $this->io_method()) {
2405
-            if (!is_array($this->proxy)) {
2406
-                $host = $this->host;
2407
-                $port = $this->port;
2408
-            } else {
2409
-                $host = $this->proxy['host'];
2410
-                $port = $this->proxy['port'];
2411
-            }
2412
-
2413
-            // use persistent connection
2414
-            if ($this->persistentConnection && isset($this->fp) && is_resource($this->fp)) {
2415
-                if (!feof($this->fp)) {
2416
-                    $this->debug('Re-use persistent connection');
2417
-                    return true;
2418
-                }
2419
-                fclose($this->fp);
2420
-                $this->debug('Closed persistent connection at EOF');
2421
-            }
2422
-
2423
-            // munge host if using OpenSSL
2424
-            if ('ssl' === $this->scheme) {
2425
-                $host = 'ssl://' . $host;
2426
-            }
2427
-            $this->debug('calling fsockopen with host ' . $host . ' connection_timeout ' . $connection_timeout);
2428
-
2429
-            // open socket
2430
-            if ($connection_timeout > 0) {
2431
-                $this->fp = @fsockopen($host, $this->port, $this->errno, $this->error_str, $connection_timeout);
2432
-            } else {
2433
-                $this->fp = @fsockopen($host, $this->port, $this->errno, $this->error_str);
2434
-            }
2435
-
2436
-            // test pointer
2437
-            if (!$this->fp) {
2438
-                $msg = 'Couldn\'t open socket connection to server ' . $this->url;
2439
-                if ($this->errno) {
2440
-                    $msg .= ', Error (' . $this->errno . '): ' . $this->error_str;
2441
-                } else {
2442
-                    $msg .= ' prior to connect().  This is often a problem looking up the host name.';
2443
-                }
2444
-                $this->debug($msg);
2445
-                $this->setError($msg);
2446
-                return false;
2447
-            }
2448
-
2449
-            // set response timeout
2450
-            $this->debug('set response timeout to ' . $response_timeout);
2451
-            stream_set_timeout($this->fp, $response_timeout);
2452
-
2453
-            $this->debug('socket connected');
2454
-            return true;
2455
-        } elseif ('curl' === $this->io_method()) {
2456
-            if (!extension_loaded('curl')) {
2457
-                //			$this->setError('cURL Extension, or OpenSSL extension w/ PHP version >= 4.3 is required for HTTPS');
2458
-                $this->setError('The PHP cURL Extension is required for HTTPS or NLTM.  You will need to re-build or update your PHP to include cURL or change php.ini to load the PHP cURL extension.');
2459
-                return false;
2460
-            }
2461
-            // Avoid warnings when PHP does not have these options
2462
-            if (defined('CURLOPT_CONNECTIONTIMEOUT')) {
2463
-                $CURLOPT_CONNECTIONTIMEOUT = CURLOPT_CONNECTIONTIMEOUT;
2464
-            } else {
2465
-                $CURLOPT_CONNECTIONTIMEOUT = 78;
2466
-            }
2467
-            if (defined('CURLOPT_HTTPAUTH')) {
2468
-                $CURLOPT_HTTPAUTH = CURLOPT_HTTPAUTH;
2469
-            } else {
2470
-                $CURLOPT_HTTPAUTH = 107;
2471
-            }
2472
-            if (defined('CURLOPT_PROXYAUTH')) {
2473
-                $CURLOPT_PROXYAUTH = CURLOPT_PROXYAUTH;
2474
-            } else {
2475
-                $CURLOPT_PROXYAUTH = 111;
2476
-            }
2477
-            if (defined('CURLAUTH_BASIC')) {
2478
-                $CURLAUTH_BASIC = CURLAUTH_BASIC;
2479
-            } else {
2480
-                $CURLAUTH_BASIC = 1;
2481
-            }
2482
-            if (defined('CURLAUTH_DIGEST')) {
2483
-                $CURLAUTH_DIGEST = CURLAUTH_DIGEST;
2484
-            } else {
2485
-                $CURLAUTH_DIGEST = 2;
2486
-            }
2487
-            if (defined('CURLAUTH_NTLM')) {
2488
-                $CURLAUTH_NTLM = CURLAUTH_NTLM;
2489
-            } else {
2490
-                $CURLAUTH_NTLM = 8;
2491
-            }
2492
-
2493
-            $this->debug('connect using cURL');
2494
-            // init CURL
2495
-            $this->ch = curl_init();
2496
-            // set url
2497
-            $hostURL = ('' != $this->port) ? "$this->scheme://$this->host:$this->port" : "$this->scheme://$this->host";
2498
-            // add path
2499
-            $hostURL .= $this->path;
2500
-            $this->setCurlOption(CURLOPT_URL, $hostURL);
2501
-            // follow location headers (re-directs)
2502
-            $this->setCurlOption(CURLOPT_FOLLOWLOCATION, 1);
2503
-            // ask for headers in the response output
2504
-            $this->setCurlOption(CURLOPT_HEADER, 1);
2505
-            // ask for the response output as the return value
2506
-            $this->setCurlOption(CURLOPT_RETURNTRANSFER, 1);
2507
-            // encode
2508
-            // We manage this ourselves through headers and encoding
2509
-            //		if(function_exists('gzuncompress')){
2510
-            //			$this->setCurlOption(CURLOPT_ENCODING, 'deflate');
2511
-            //		}
2512
-            // persistent connection
2513
-            if ($this->persistentConnection) {
2514
-                // I believe the following comment is now bogus, having applied to
2515
-                // the code when it used CURLOPT_CUSTOMREQUEST to send the request.
2516
-                // The way we send data, we cannot use persistent connections, since
2517
-                // there will be some "junk" at the end of our request.
2518
-                //$this->setCurlOption(CURL_HTTP_VERSION_1_1, true);
2519
-                $this->persistentConnection = false;
2520
-                $this->setHeader('Connection', 'close');
2521
-            }
2522
-            // set timeouts
2523
-            if (0 != $connection_timeout) {
2524
-                $this->setCurlOption($CURLOPT_CONNECTIONTIMEOUT, $connection_timeout);
2525
-            }
2526
-            if (0 != $response_timeout) {
2527
-                $this->setCurlOption(CURLOPT_TIMEOUT, $response_timeout);
2528
-            }
2529
-
2530
-            if ('https' === $this->scheme) {
2531
-                $this->debug('set cURL SSL verify options');
2532
-                // recent versions of cURL turn on peer/host checking by default,
2533
-                // while PHP binaries are not compiled with a default location for the
2534
-                // CA cert bundle, so disable peer/host checking.
2535
-                //$this->setCurlOption(CURLOPT_CAINFO, 'f:\php-4.3.2-win32\extensions\curl-ca-bundle.crt');
2536
-                $this->setCurlOption(CURLOPT_SSL_VERIFYPEER, 0);
2537
-                $this->setCurlOption(CURLOPT_SSL_VERIFYHOST, 0);
2538
-
2539
-                // support client certificates (thanks Tobias Boes, Doug Anarino, Eryan Ariobowo)
2540
-                if ('certificate' === $this->authtype) {
2541
-                    $this->debug('set cURL certificate options');
2542
-                    if (isset($this->certRequest['cainfofile'])) {
2543
-                        $this->setCurlOption(CURLOPT_CAINFO, $this->certRequest['cainfofile']);
2544
-                    }
2545
-                    if (isset($this->certRequest['verifypeer'])) {
2546
-                        $this->setCurlOption(CURLOPT_SSL_VERIFYPEER, $this->certRequest['verifypeer']);
2547
-                    } else {
2548
-                        $this->setCurlOption(CURLOPT_SSL_VERIFYPEER, 1);
2549
-                    }
2550
-                    if (isset($this->certRequest['verifyhost'])) {
2551
-                        $this->setCurlOption(CURLOPT_SSL_VERIFYHOST, $this->certRequest['verifyhost']);
2552
-                    } else {
2553
-                        $this->setCurlOption(CURLOPT_SSL_VERIFYHOST, 1);
2554
-                    }
2555
-                    if (isset($this->certRequest['sslcertfile'])) {
2556
-                        $this->setCurlOption(CURLOPT_SSLCERT, $this->certRequest['sslcertfile']);
2557
-                    }
2558
-                    if (isset($this->certRequest['sslkeyfile'])) {
2559
-                        $this->setCurlOption(CURLOPT_SSLKEY, $this->certRequest['sslkeyfile']);
2560
-                    }
2561
-                    if (isset($this->certRequest['passphrase'])) {
2562
-                        $this->setCurlOption(CURLOPT_SSLKEYPASSWD, $this->certRequest['passphrase']);
2563
-                    }
2564
-                    if (isset($this->certRequest['certpassword'])) {
2565
-                        $this->setCurlOption(CURLOPT_SSLCERTPASSWD, $this->certRequest['certpassword']);
2566
-                    }
2567
-                }
2568
-            }
2569
-            if ($this->authtype && ('certificate' !== $this->authtype)) {
2570
-                if ($this->username) {
2571
-                    $this->debug('set cURL username/password');
2572
-                    $this->setCurlOption(CURLOPT_USERPWD, "$this->username:$this->password");
2573
-                }
2574
-                if ('basic' === $this->authtype) {
2575
-                    $this->debug('set cURL for Basic authentication');
2576
-                    $this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_BASIC);
2577
-                }
2578
-                if ('digest' === $this->authtype) {
2579
-                    $this->debug('set cURL for digest authentication');
2580
-                    $this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_DIGEST);
2581
-                }
2582
-                if ('ntlm' === $this->authtype) {
2583
-                    $this->debug('set cURL for NTLM authentication');
2584
-                    $this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_NTLM);
2585
-                }
2586
-            }
2587
-            if (is_array($this->proxy)) {
2588
-                $this->debug('set cURL proxy options');
2589
-                if ('' != $this->proxy['port']) {
2590
-                    $this->setCurlOption(CURLOPT_PROXY, $this->proxy['host'] . ':' . $this->proxy['port']);
2591
-                } else {
2592
-                    $this->setCurlOption(CURLOPT_PROXY, $this->proxy['host']);
2593
-                }
2594
-                if ($this->proxy['username'] || $this->proxy['password']) {
2595
-                    $this->debug('set cURL proxy authentication options');
2596
-                    $this->setCurlOption(CURLOPT_PROXYUSERPWD, $this->proxy['username'] . ':' . $this->proxy['password']);
2597
-                    if ('basic' === $this->proxy['authtype']) {
2598
-                        $this->setCurlOption($CURLOPT_PROXYAUTH, $CURLAUTH_BASIC);
2599
-                    }
2600
-                    if ('ntlm' === $this->proxy['authtype']) {
2601
-                        $this->setCurlOption($CURLOPT_PROXYAUTH, $CURLAUTH_NTLM);
2602
-                    }
2603
-                }
2604
-            }
2605
-            $this->debug('cURL connection set up');
2606
-            return true;
2607
-        } else {
2608
-            $this->setError('Unknown scheme ' . $this->scheme);
2609
-            $this->debug('Unknown scheme ' . $this->scheme);
2610
-            return false;
2611
-        }
2612
-    }
2613
-
2614
-    /**
2615
-     * sends the SOAP request and gets the SOAP response via HTTP[S]
2616
-     *
2617
-     * @param    string $data message data
2618
-     * @param    integer $timeout set connection timeout in seconds
2619
-     * @param    integer $response_timeout set response timeout in seconds
2620
-     * @param    array $cookies cookies to send
2621
-     * @return    string data
2622
-     * @access   public
2623
-     */
2624
-    public function send($data, $timeout = 0, $response_timeout = 30, $cookies = null)
2625
-    {
2626
-        $this->debug('entered send() with data of length: ' . strlen($data));
2627
-
2628
-        $this->tryagain = true;
2629
-        $tries = 0;
2630
-        while ($this->tryagain) {
2631
-            $this->tryagain = false;
2632
-            if ($tries++ < 2) {
2633
-                // make connnection
2634
-                if (!$this->connect($timeout, $response_timeout)) {
2635
-                    return false;
2636
-                }
2221
+	public $url = '';
2222
+	public $uri = '';
2223
+	public $digest_uri = '';
2224
+	public $scheme = '';
2225
+	public $host = '';
2226
+	public $port = '';
2227
+	public $path = '';
2228
+	public $request_method = 'POST';
2229
+	public $protocol_version = '1.0';
2230
+	public $encoding = '';
2231
+	public $outgoing_headers = [];
2232
+	public $incoming_headers = [];
2233
+	public $incoming_cookies = [];
2234
+	public $outgoing_payload = '';
2235
+	public $incoming_payload = '';
2236
+	public $response_status_line;    // HTTP response status line
2237
+	public $useSOAPAction = true;
2238
+	public $persistentConnection = false;
2239
+	public $ch = false;    // cURL handle
2240
+	public $ch_options = [];    // cURL custom options
2241
+	public $use_curl = false;        // force cURL use
2242
+	public $proxy;            // proxy information (associative array)
2243
+	public $username = '';
2244
+	public $password = '';
2245
+	public $authtype = '';
2246
+	public $digestRequest = [];
2247
+	public $certRequest = [];    // keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional)
2248
+	// cainfofile: certificate authority file, e.g. '$pathToPemFiles/rootca.pem'
2249
+	// sslcertfile: SSL certificate file, e.g. '$pathToPemFiles/mycert.pem'
2250
+	// sslkeyfile: SSL key file, e.g. '$pathToPemFiles/mykey.pem'
2251
+	// passphrase: SSL key password/passphrase
2252
+	// certpassword: SSL certificate password
2253
+	// verifypeer: default is 1
2254
+	// verifyhost: default is 1
2255
+
2256
+	/**
2257
+	 * constructor
2258
+	 *
2259
+	 * @param string $url The URL to which to connect
2260
+	 * @param array $curl_options User-specified cURL options
2261
+	 * @param boolean $use_curl Whether to try to force cURL use
2262
+	 * @access public
2263
+	 */
2264
+	public function __construct($url, $curl_options = null, $use_curl = false)
2265
+	{
2266
+		parent::__construct();
2267
+		$this->debug("ctor url=$url use_curl=$use_curl curl_options:");
2268
+		$this->appendDebug($this->varDump($curl_options));
2269
+		$this->setURL($url);
2270
+		if (is_array($curl_options)) {
2271
+			$this->ch_options = $curl_options;
2272
+		}
2273
+		$this->use_curl = $use_curl;
2274
+		preg_match('/\$Revisio' . 'n: ([^ ]+)/', $this->revision, $rev);
2275
+		$this->setHeader('User-Agent', $this->title . '/' . $this->version . ' (' . $rev[1] . ')');
2276
+	}
2637 2277
 
2638
-                // send request
2639
-                if (!$this->sendRequest($data, $cookies)) {
2640
-                    return false;
2641
-                }
2278
+	/**
2279
+	 * sets a cURL option
2280
+	 *
2281
+	 * @param    mixed $option The cURL option (always integer?)
2282
+	 * @param    mixed $value The cURL option value
2283
+	 * @access   private
2284
+	 */
2285
+	private function setCurlOption($option, $value)
2286
+	{
2287
+		$this->debug("setCurlOption option=$option, value=");
2288
+		$this->appendDebug($this->varDump($value));
2289
+		curl_setopt($this->ch, $option, $value);
2290
+	}
2642 2291
 
2643
-                // get response
2644
-                $respdata = $this->getResponse();
2645
-            } else {
2646
-                $this->setError("Too many tries to get an OK response ($this->response_status_line)");
2647
-            }
2648
-        }
2649
-        $this->debug('end of send()');
2650
-        return $respdata;
2651
-    }
2652
-
2653
-
2654
-    /**
2655
-     * sends the SOAP request and gets the SOAP response via HTTPS using CURL
2656
-     *
2657
-     * @param    string $data message data
2658
-     * @param    integer $timeout set connection timeout in seconds
2659
-     * @param    integer $response_timeout set response timeout in seconds
2660
-     * @param    array $cookies cookies to send
2661
-     * @return    string data
2662
-     * @access   public
2663
-     * @deprecated
2664
-     */
2665
-    public function sendHTTPS($data, $timeout = 0, $response_timeout = 30, $cookies)
2666
-    {
2667
-        return $this->send($data, $timeout, $response_timeout, $cookies);
2668
-    }
2669
-
2670
-    /**
2671
-     * if authenticating, set user credentials here
2672
-     *
2673
-     * @param    string $username
2674
-     * @param    string $password
2675
-     * @param    string $authtype (basic|digest|certificate|ntlm)
2676
-     * @param    array $digestRequest (keys must be nonce, nc, realm, qop)
2677
-     * @param    array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs)
2678
-     * @access   public
2679
-     */
2680
-    public function setCredentials($username, $password, $authtype = 'basic', $digestRequest = [], $certRequest = [])
2681
-    {
2682
-        $this->debug("setCredentials username=$username authtype=$authtype digestRequest=");
2683
-        $this->appendDebug($this->varDump($digestRequest));
2684
-        $this->debug('certRequest=');
2685
-        $this->appendDebug($this->varDump($certRequest));
2686
-        // cf. RFC 2617
2687
-        if ('basic' === $authtype) {
2688
-            $this->setHeader('Authorization', 'Basic ' . base64_encode(str_replace(':', '', $username) . ':' . $password));
2689
-        } elseif ('digest' === $authtype) {
2690
-            if (isset($digestRequest['nonce'])) {
2691
-                $digestRequest['nc'] = isset($digestRequest['nc']) ? $digestRequest['nc']++ : 1;
2692
-
2693
-                // calculate the Digest hashes (calculate code based on digest implementation found at: http://www.rassoc.com/gregr/weblog/stories/2002/07/09/webServicesSecurityHttpDigestAuthenticationWithoutActiveDirectory.html)
2694
-
2695
-                // A1 = unq(username-value) ":" unq(realm-value) ":" passwd
2696
-                $A1 = $username . ':' . (isset($digestRequest['realm']) ? $digestRequest['realm'] : '') . ':' . $password;
2697
-
2698
-                // H(A1) = MD5(A1)
2699
-                $HA1 = md5($A1);
2700
-
2701
-                // A2 = Method ":" digest-uri-value
2702
-                $A2 = $this->request_method . ':' . $this->digest_uri;
2703
-
2704
-                // H(A2)
2705
-                $HA2 = md5($A2);
2706
-
2707
-                // KD(secret, data) = H(concat(secret, ":", data))
2708
-                // if qop == auth:
2709
-                // request-digest  = <"> < KD ( H(A1),     unq(nonce-value)
2710
-                //                              ":" nc-value
2711
-                //                              ":" unq(cnonce-value)
2712
-                //                              ":" unq(qop-value)
2713
-                //                              ":" H(A2)
2714
-                //                            ) <">
2715
-                // if qop is missing,
2716
-                // request-digest  = <"> < KD ( H(A1), unq(nonce-value) ":" H(A2) ) > <">
2717
-
2718
-                $unhashedDigest = '';
2719
-                $nonce = isset($digestRequest['nonce']) ? $digestRequest['nonce'] : '';
2720
-                $cnonce = $nonce;
2721
-                if ('' != $digestRequest['qop']) {
2722
-                    $unhashedDigest = $HA1 . ':' . $nonce . ':' . sprintf('%08d', $digestRequest['nc']) . ':' . $cnonce . ':' . $digestRequest['qop'] . ':' . $HA2;
2723
-                } else {
2724
-                    $unhashedDigest = $HA1 . ':' . $nonce . ':' . $HA2;
2725
-                }
2292
+	/**
2293
+	 * sets an HTTP header
2294
+	 *
2295
+	 * @param string $name The name of the header
2296
+	 * @param string $value The value of the header
2297
+	 * @access private
2298
+	 */
2299
+	private function setHeader($name, $value)
2300
+	{
2301
+		$this->outgoing_headers[$name] = $value;
2302
+		$this->debug("set header $name: $value");
2303
+	}
2726 2304
 
2727
-                $hashedDigest = md5($unhashedDigest);
2305
+	/**
2306
+	 * unsets an HTTP header
2307
+	 *
2308
+	 * @param string $name The name of the header
2309
+	 * @access private
2310
+	 */
2311
+	private function unsetHeader($name)
2312
+	{
2313
+		if (isset($this->outgoing_headers[$name])) {
2314
+			$this->debug("unset header $name");
2315
+			unset($this->outgoing_headers[$name]);
2316
+		}
2317
+	}
2728 2318
 
2729
-                $opaque = '';
2730
-                if (isset($digestRequest['opaque'])) {
2731
-                    $opaque = ', opaque="' . $digestRequest['opaque'] . '"';
2732
-                }
2319
+	/**
2320
+	 * sets the URL to which to connect
2321
+	 *
2322
+	 * @param string $url The URL to which to connect
2323
+	 * @access private
2324
+	 */
2325
+	private function setURL($url)
2326
+	{
2327
+		$this->url = $url;
2328
+
2329
+		$u = parse_url($url);
2330
+		foreach ($u as $k => $v) {
2331
+			$this->debug("parsed URL $k = $v");
2332
+			$this->$k = $v;
2333
+		}
2733 2334
 
2734
-                $this->setHeader('Authorization', 'Digest username="' . $username . '", realm="' . $digestRequest['realm'] . '", nonce="' . $nonce . '", uri="' . $this->digest_uri . $opaque . '", cnonce="' . $cnonce . '", nc=' . sprintf('%08x', $digestRequest['nc']) . ', qop="' . $digestRequest['qop'] . '", response="' . $hashedDigest . '"');
2735
-            }
2736
-        } elseif ('certificate' === $authtype) {
2737
-            $this->certRequest = $certRequest;
2738
-            $this->debug('Authorization header not set for certificate');
2739
-        } elseif ('ntlm' === $authtype) {
2740
-            // do nothing
2741
-            $this->debug('Authorization header not set for ntlm');
2742
-        }
2743
-        $this->username = $username;
2744
-        $this->password = $password;
2745
-        $this->authtype = $authtype;
2746
-        $this->digestRequest = $digestRequest;
2747
-    }
2748
-
2749
-    /**
2750
-     * set the soapaction value
2751
-     *
2752
-     * @param    string $soapaction
2753
-     * @access   public
2754
-     */
2755
-    public function setSOAPAction($soapaction)
2756
-    {
2757
-        $this->setHeader('SOAPAction', '"' . $soapaction . '"');
2758
-    }
2759
-
2760
-    /**
2761
-     * use http encoding
2762
-     *
2763
-     * @param    string $enc encoding style. supported values: gzip, deflate, or both
2764
-     * @access   public
2765
-     */
2766
-    public function setEncoding($enc = 'gzip, deflate')
2767
-    {
2768
-        if (function_exists('gzdeflate')) {
2769
-            $this->protocol_version = '1.1';
2770
-            $this->setHeader('Accept-Encoding', $enc);
2771
-            if (!isset($this->outgoing_headers['Connection'])) {
2772
-                $this->setHeader('Connection', 'close');
2773
-                $this->persistentConnection = false;
2774
-            }
2775
-            // deprecated as of PHP 5.3.0
2776
-            //set_magic_quotes_runtime(0);
2777
-            $this->encoding = $enc;
2778
-        }
2779
-    }
2780
-
2781
-    /**
2782
-     * set proxy info here
2783
-     *
2784
-     * @param    bool|string $proxyhost use an empty string to remove proxy
2785
-     * @param    bool|string $proxyport
2786
-     * @param    bool|string $proxyusername
2787
-     * @param    bool|string $proxypassword
2788
-     * @param    bool|string $proxyauthtype (basic|ntlm)
2789
-     * @access   public
2790
-     */
2791
-    public function setProxy($proxyhost, $proxyport, $proxyusername = '', $proxypassword = '', $proxyauthtype = 'basic')
2792
-    {
2793
-        if ($proxyhost) {
2794
-            $this->proxy = [
2795
-                'host' => $proxyhost,
2796
-                'port' => $proxyport,
2797
-                'username' => $proxyusername,
2798
-                'password' => $proxypassword,
2799
-                'authtype' => $proxyauthtype
2800
-            ];
2801
-            if ('' != $proxyusername && '' != $proxypassword && $proxyauthtype = 'basic') {
2802
-                $this->setHeader('Proxy-Authorization', ' Basic ' . base64_encode($proxyusername . ':' . $proxypassword));
2803
-            }
2804
-        } else {
2805
-            $this->debug('remove proxy');
2806
-            $proxy = null;
2807
-            $this->unsetHeader('Proxy-Authorization');
2808
-        }
2809
-    }
2810
-
2811
-    /**
2812
-     * Test if the given string starts with a header that is to be skipped.
2813
-     * Skippable headers result from chunked transfer and proxy requests.
2814
-     *
2815
-     * @param    string $data The string to check.
2816
-     * @returns    boolean    Whether a skippable header was found.
2817
-     * @access    private
2818
-     * @return bool
2819
-     */
2820
-    private function isSkippableCurlHeader(&$data)
2821
-    {
2822
-        $skipHeaders = [
2823
-            'HTTP/1.1 100',
2824
-            'HTTP/1.0 301',
2825
-            'HTTP/1.1 301',
2826
-            'HTTP/1.0 302',
2827
-            'HTTP/1.1 302',
2828
-            'HTTP/1.0 401',
2829
-            'HTTP/1.1 401',
2830
-            'HTTP/1.0 200 Connection established'
2831
-        ];
2832
-        foreach ($skipHeaders as $hd) {
2833
-            $prefix = substr($data, 0, strlen($hd));
2834
-            if ($prefix == $hd) {
2835
-                return true;
2836
-            }
2837
-        }
2838
-
2839
-        return false;
2840
-    }
2841
-
2842
-    /**
2843
-     * decode a string that is encoded w/ "chunked' transfer encoding
2844
-     * as defined in RFC2068 19.4.6
2845
-     *
2846
-     * @param    string $buffer
2847
-     * @param    string $lb
2848
-     * @returns    string
2849
-     * @access   public
2850
-     * @deprecated
2851
-     * @return string
2852
-     */
2853
-    public function decodeChunked($buffer, $lb)
2854
-    {
2855
-        // length := 0
2856
-        $length = 0;
2857
-        $new = '';
2858
-
2859
-        // read chunk-size, chunk-extension (if any) and CRLF
2860
-        // get the position of the linebreak
2861
-        $chunkend = strpos($buffer, $lb);
2862
-        if (false == $chunkend) {
2863
-            $this->debug('no linebreak found in decodeChunked');
2864
-            return $new;
2865
-        }
2866
-        $temp = substr($buffer, 0, $chunkend);
2867
-        $chunk_size = hexdec(trim($temp));
2868
-        $chunkstart = $chunkend + strlen($lb);
2869
-        // while (chunk-size > 0) {
2870
-        while ($chunk_size > 0) {
2871
-            $this->debug("chunkstart: $chunkstart chunk_size: $chunk_size");
2872
-            $chunkend = strpos($buffer, $lb, $chunkstart + $chunk_size);
2873
-
2874
-            // Just in case we got a broken connection
2875
-            if (false == $chunkend) {
2876
-                $chunk = substr($buffer, $chunkstart);
2877
-                // append chunk-data to entity-body
2878
-                $new .= $chunk;
2879
-                $length += strlen($chunk);
2880
-                break;
2881
-            }
2882
-
2883
-            // read chunk-data and CRLF
2884
-            $chunk = substr($buffer, $chunkstart, $chunkend - $chunkstart);
2885
-            // append chunk-data to entity-body
2886
-            $new .= $chunk;
2887
-            // length := length + chunk-size
2888
-            $length += strlen($chunk);
2889
-            // read chunk-size and CRLF
2890
-            $chunkstart = $chunkend + strlen($lb);
2891
-
2892
-            $chunkend = strpos($buffer, $lb, $chunkstart) + strlen($lb);
2893
-            if (false == $chunkend) {
2894
-                break; //Just in case we got a broken connection
2895
-            }
2896
-            $temp = substr($buffer, $chunkstart, $chunkend - $chunkstart);
2897
-            $chunk_size = hexdec(trim($temp));
2898
-            $chunkstart = $chunkend;
2899
-        }
2900
-        return $new;
2901
-    }
2902
-
2903
-    /**
2904
-     * Writes the payload, including HTTP headers, to $this->outgoing_payload.
2905
-     *
2906
-     * @param    string $data HTTP body
2907
-     * @param    string $cookie_str data for HTTP Cookie header
2908
-     * @return    void
2909
-     * @access    private
2910
-     */
2911
-    private function buildPayload($data, $cookie_str = '')
2912
-    {
2913
-        // Note: for cURL connections, $this->outgoing_payload is ignored,
2914
-        // as is the Content-Length header, but these are still created as
2915
-        // debugging guides.
2916
-
2917
-        // add content-length header
2918
-        if ('GET' !== $this->request_method) {
2919
-            $this->setHeader('Content-Length', strlen($data));
2920
-        }
2921
-
2922
-        // start building outgoing payload:
2923
-        if ($this->proxy) {
2924
-            $uri = $this->url;
2925
-        } else {
2926
-            $uri = $this->uri;
2927
-        }
2928
-        $req = "$this->request_method $uri HTTP/$this->protocol_version";
2929
-        $this->debug("HTTP request: $req");
2930
-        $this->outgoing_payload = "$req\r\n";
2931
-
2932
-        // loop thru headers, serializing
2933
-        foreach ($this->outgoing_headers as $k => $v) {
2934
-            $hdr = $k . ': ' . $v;
2935
-            $this->debug("HTTP header: $hdr");
2936
-            $this->outgoing_payload .= "$hdr\r\n";
2937
-        }
2938
-
2939
-        // add any cookies
2940
-        if ('' != $cookie_str) {
2941
-            $hdr = 'Cookie: ' . $cookie_str;
2942
-            $this->debug("HTTP header: $hdr");
2943
-            $this->outgoing_payload .= "$hdr\r\n";
2944
-        }
2945
-
2946
-        // header/body separator
2947
-        $this->outgoing_payload .= "\r\n";
2948
-
2949
-        // add data
2950
-        $this->outgoing_payload .= $data;
2951
-    }
2952
-
2953
-    /**
2954
-     * sends the SOAP request via HTTP[S]
2955
-     *
2956
-     * @param    string $data message data
2957
-     * @param    array $cookies cookies to send
2958
-     * @return    boolean    true if OK, false if problem
2959
-     * @access   private
2960
-     */
2961
-    private function sendRequest($data, $cookies = null)
2962
-    {
2963
-        // build cookie string
2964
-        $cookie_str = $this->getCookiesForRequest($cookies, (('ssl' === $this->scheme) || ('https' === $this->scheme)));
2965
-
2966
-        // build payload
2967
-        $this->buildPayload($data, $cookie_str);
2968
-
2969
-        if ('socket' === $this->io_method()) {
2970
-            // send payload
2971
-            if (!fwrite($this->fp, $this->outgoing_payload, strlen($this->outgoing_payload))) {
2972
-                $this->setError('couldn\'t write message data to socket');
2973
-                $this->debug('couldn\'t write message data to socket');
2974
-                return false;
2975
-            }
2976
-            $this->debug('wrote data to socket, length = ' . strlen($this->outgoing_payload));
2977
-            return true;
2978
-        } elseif ('curl' === $this->io_method()) {
2979
-            // set payload
2980
-            // cURL does say this should only be the verb, and in fact it
2981
-            // turns out that the URI and HTTP version are appended to this, which
2982
-            // some servers refuse to work with (so we no longer use this method!)
2983
-            //$this->setCurlOption(CURLOPT_CUSTOMREQUEST, $this->outgoing_payload);
2984
-            $curl_headers = [];
2985
-            foreach ($this->outgoing_headers as $k => $v) {
2986
-                if ('Connection' === $k || 'Content-Length' === $k || 'Host' === $k || 'Authorization' === $k || 'Proxy-Authorization' === $k) {
2987
-                    $this->debug("Skip cURL header $k: $v");
2988
-                } else {
2989
-                    $curl_headers[] = "$k: $v";
2990
-                }
2991
-            }
2992
-            if ('' != $cookie_str) {
2993
-                $curl_headers[] = 'Cookie: ' . $cookie_str;
2994
-            }
2995
-            $this->setCurlOption(CURLOPT_HTTPHEADER, $curl_headers);
2996
-            $this->debug('set cURL HTTP headers');
2997
-            if ('POST' === $this->request_method) {
2998
-                $this->setCurlOption(CURLOPT_POST, 1);
2999
-                $this->setCurlOption(CURLOPT_POSTFIELDS, $data);
3000
-                $this->debug('set cURL POST data');
3001
-            } else {
3002
-            }
3003
-            // insert custom user-set cURL options
3004
-            foreach ($this->ch_options as $key => $val) {
3005
-                $this->setCurlOption($key, $val);
3006
-            }
3007
-
3008
-            $this->debug('set cURL payload');
3009
-            return true;
3010
-        }
3011
-    }
3012
-
3013
-    /**
3014
-     * gets the SOAP response via HTTP[S]
3015
-     *
3016
-     * @return    string the response (also sets member variables like incoming_payload)
3017
-     * @access   private
3018
-     */
3019
-    private function getResponse()
3020
-    {
3021
-        $this->incoming_payload = '';
3022
-
3023
-        if ('socket' === $this->io_method()) {
3024
-            // loop until headers have been retrieved
3025
-            $data = '';
3026
-            while (!isset($lb)) {
3027
-
3028
-                // We might EOF during header read.
3029
-                if (feof($this->fp)) {
3030
-                    $this->incoming_payload = $data;
3031
-                    $this->debug('found no headers before EOF after length ' . strlen($data));
3032
-                    $this->debug("received before EOF:\n" . $data);
3033
-                    $this->setError('server failed to send headers');
3034
-                    return false;
3035
-                }
2335
+		// add any GET params to path
2336
+		if (isset($u['query']) && '' != $u['query']) {
2337
+			$this->path .= '?' . $u['query'];
2338
+		}
3036 2339
 
3037
-                $tmp = fgets($this->fp, 256);
3038
-                $tmplen = strlen($tmp);
3039
-                $this->debug("read line of $tmplen bytes: " . trim($tmp));
2340
+		// set default port
2341
+		if (!isset($u['port'])) {
2342
+			if ('https' === $u['scheme']) {
2343
+				$this->port = 443;
2344
+			} else {
2345
+				$this->port = 80;
2346
+			}
2347
+		}
3040 2348
 
3041
-                if (0 == $tmplen) {
3042
-                    $this->incoming_payload = $data;
3043
-                    $this->debug('socket read of headers timed out after length ' . strlen($data));
3044
-                    $this->debug('read before timeout: ' . $data);
3045
-                    $this->setError('socket read of headers timed out');
3046
-                    return false;
3047
-                }
2349
+		$this->uri = $this->path;
2350
+		$this->digest_uri = $this->uri;
3048 2351
 
3049
-                $data .= $tmp;
3050
-                $pos = strpos($data, "\r\n\r\n");
3051
-                if ($pos > 1) {
3052
-                    $lb = "\r\n";
3053
-                } else {
3054
-                    $pos = strpos($data, "\n\n");
3055
-                    if ($pos > 1) {
3056
-                        $lb = "\n";
3057
-                    }
3058
-                }
3059
-                // remove 100 headers
3060
-                if (isset($lb) && preg_match('/^HTTP\/1.1 100/', $data)) {
3061
-                    unset($lb);
3062
-                    $data = '';
3063
-                }//
3064
-            }
3065
-            // store header data
3066
-            $this->incoming_payload .= $data;
3067
-            $this->debug('found end of headers after length ' . strlen($data));
3068
-            // process headers
3069
-            $header_data = trim(substr($data, 0, $pos));
3070
-            $header_array = explode($lb, $header_data);
3071
-            $this->incoming_headers = [];
3072
-            $this->incoming_cookies = [];
3073
-            foreach ($header_array as $header_line) {
3074
-                $arr = explode(':', $header_line, 2);
3075
-                if (is_array($arr) && count($arr) > 1) {
3076
-                    $header_name = strtolower(trim($arr[0]));
3077
-                    $this->incoming_headers[$header_name] = trim($arr[1]);
3078
-                    if ('set-cookie' === $header_name) {
3079
-                        // TODO: allow multiple cookies from parseCookie
3080
-                        $cookie = $this->parseCookie(trim($arr[1]));
3081
-                        if ($cookie) {
3082
-                            $this->incoming_cookies[] = $cookie;
3083
-                            $this->debug('found cookie: ' . $cookie['name'] . ' = ' . $cookie['value']);
3084
-                        } else {
3085
-                            $this->debug('did not find cookie in ' . trim($arr[1]));
3086
-                        }
3087
-                    }
3088
-                } elseif (isset($header_name)) {
3089
-                    // append continuation line to previous header
3090
-                    $this->incoming_headers[$header_name] .= $lb . ' ' . $header_line;
3091
-                }
3092
-            }
3093
-
3094
-            // loop until msg has been received
3095
-            if (isset($this->incoming_headers['transfer-encoding']) && 'chunked' === strtolower($this->incoming_headers['transfer-encoding'])) {
3096
-                $content_length = 2147483647;    // ignore any content-length header
3097
-                $chunked = true;
3098
-                $this->debug('want to read chunked content');
3099
-            } elseif (isset($this->incoming_headers['content-length'])) {
3100
-                $content_length = $this->incoming_headers['content-length'];
3101
-                $chunked = false;
3102
-                $this->debug("want to read content of length $content_length");
3103
-            } else {
3104
-                $content_length = 2147483647;
3105
-                $chunked = false;
3106
-                $this->debug('want to read content to EOF');
3107
-            }
3108
-            $data = '';
3109
-            do {
3110
-                if ($chunked) {
3111
-                    $tmp = fgets($this->fp, 256);
3112
-                    $tmplen = strlen($tmp);
3113
-                    $this->debug("read chunk line of $tmplen bytes");
3114
-                    if (0 == $tmplen) {
3115
-                        $this->incoming_payload = $data;
3116
-                        $this->debug('socket read of chunk length timed out after length ' . strlen($data));
3117
-                        $this->debug("read before timeout:\n" . $data);
3118
-                        $this->setError('socket read of chunk length timed out');
3119
-                        return false;
3120
-                    }
3121
-                    $content_length = hexdec(trim($tmp));
3122
-                    $this->debug("chunk length $content_length");
3123
-                }
3124
-                $strlen = 0;
3125
-                while (($strlen < $content_length) && (!feof($this->fp))) {
3126
-                    $readlen = min(8192, $content_length - $strlen);
3127
-                    $tmp = fread($this->fp, $readlen);
3128
-                    $tmplen = strlen($tmp);
3129
-                    $this->debug("read buffer of $tmplen bytes");
3130
-                    if ((0 == $tmplen) && (!feof($this->fp))) {
3131
-                        $this->incoming_payload = $data;
3132
-                        $this->debug('socket read of body timed out after length ' . strlen($data));
3133
-                        $this->debug("read before timeout:\n" . $data);
3134
-                        $this->setError('socket read of body timed out');
3135
-                        return false;
3136
-                    }
3137
-                    $strlen += $tmplen;
3138
-                    $data .= $tmp;
3139
-                }
3140
-                if ($chunked && ($content_length > 0)) {
3141
-                    $tmp = fgets($this->fp, 256);
3142
-                    $tmplen = strlen($tmp);
3143
-                    $this->debug("read chunk terminator of $tmplen bytes");
3144
-                    if (0 == $tmplen) {
3145
-                        $this->incoming_payload = $data;
3146
-                        $this->debug('socket read of chunk terminator timed out after length ' . strlen($data));
3147
-                        $this->debug("read before timeout:\n" . $data);
3148
-                        $this->setError('socket read of chunk terminator timed out');
3149
-                        return false;
3150
-                    }
3151
-                }
3152
-            } while ($chunked && ($content_length > 0) && (!feof($this->fp)));
3153
-            if (feof($this->fp)) {
3154
-                $this->debug('read to EOF');
3155
-            }
3156
-            $this->debug('read body of length ' . strlen($data));
3157
-            $this->incoming_payload .= $data;
3158
-            $this->debug('received a total of ' . strlen($this->incoming_payload) . ' bytes of data from server');
3159
-
3160
-            // close filepointer
3161
-            if (
3162
-                (isset($this->incoming_headers['connection']) && 'close' === strtolower($this->incoming_headers['connection'])) ||
3163
-                (!$this->persistentConnection) || feof($this->fp)
3164
-            ) {
3165
-                fclose($this->fp);
3166
-                $this->fp = false;
3167
-                $this->debug('closed socket');
3168
-            }
3169
-
3170
-            // connection was closed unexpectedly
3171
-            if ('' == $this->incoming_payload) {
3172
-                $this->setError('no response from server');
3173
-                return false;
3174
-            }
3175
-
3176
-            // decode transfer-encoding
2352
+		// build headers
2353
+		if (!isset($u['port'])) {
2354
+			$this->setHeader('Host', $this->host);
2355
+		} else {
2356
+			$this->setHeader('Host', $this->host . ':' . $this->port);
2357
+		}
2358
+
2359
+		if (isset($u['user']) && '' != $u['user']) {
2360
+			$this->setCredentials(urldecode($u['user']), isset($u['pass']) ? urldecode($u['pass']) : '');
2361
+		}
2362
+	}
2363
+
2364
+	/**
2365
+	 * gets the I/O method to use
2366
+	 *
2367
+	 * @return    string    I/O method to use (socket|curl|unknown)
2368
+	 * @access    private
2369
+	 */
2370
+	private function io_method()
2371
+	{
2372
+		if ($this->use_curl || ('https' === $this->scheme) || ('http' === $this->scheme && 'ntlm' === $this->authtype) || ('http' === $this->scheme && is_array($this->proxy) && 'ntlm' === $this->proxy['authtype'])) {
2373
+			return 'curl';
2374
+		}
2375
+		if (('http' === $this->scheme || 'ssl' === $this->scheme) && 'ntlm' !== $this->authtype && (!is_array($this->proxy) || 'ntlm' !== $this->proxy['authtype'])) {
2376
+			return 'socket';
2377
+		}
2378
+		return 'unknown';
2379
+	}
2380
+
2381
+	/**
2382
+	 * establish an HTTP connection
2383
+	 *
2384
+	 * @param int $connection_timeout set connection timeout in seconds
2385
+	 * @param int $response_timeout   set response timeout in seconds
2386
+	 * @return bool true if connected, false if not
2387
+	 * @access private
2388
+	 */
2389
+	private function connect($connection_timeout = 0, $response_timeout = 30)
2390
+	{
2391
+		// For PHP 4.3 with OpenSSL, change https scheme to ssl, then treat like
2392
+		// "regular" socket.
2393
+		// TODO: disabled for now because OpenSSL must be *compiled* in (not just
2394
+		//       loaded), and until PHP5 stream_get_wrappers is not available.
2395
+		//	  	if ($this->scheme == 'https') {
2396
+		//		  	if (version_compare(phpversion(), '4.3.0') >= 0) {
2397
+		//		  		if (extension_loaded('openssl')) {
2398
+		//		  			$this->scheme = 'ssl';
2399
+		//		  			$this->debug('Using SSL over OpenSSL');
2400
+		//		  		}
2401
+		//		  	}
2402
+		//		}
2403
+		$this->debug("connect connection_timeout $connection_timeout, response_timeout $response_timeout, scheme $this->scheme, host $this->host, port $this->port");
2404
+		if ('socket' === $this->io_method()) {
2405
+			if (!is_array($this->proxy)) {
2406
+				$host = $this->host;
2407
+				$port = $this->port;
2408
+			} else {
2409
+				$host = $this->proxy['host'];
2410
+				$port = $this->proxy['port'];
2411
+			}
2412
+
2413
+			// use persistent connection
2414
+			if ($this->persistentConnection && isset($this->fp) && is_resource($this->fp)) {
2415
+				if (!feof($this->fp)) {
2416
+					$this->debug('Re-use persistent connection');
2417
+					return true;
2418
+				}
2419
+				fclose($this->fp);
2420
+				$this->debug('Closed persistent connection at EOF');
2421
+			}
2422
+
2423
+			// munge host if using OpenSSL
2424
+			if ('ssl' === $this->scheme) {
2425
+				$host = 'ssl://' . $host;
2426
+			}
2427
+			$this->debug('calling fsockopen with host ' . $host . ' connection_timeout ' . $connection_timeout);
2428
+
2429
+			// open socket
2430
+			if ($connection_timeout > 0) {
2431
+				$this->fp = @fsockopen($host, $this->port, $this->errno, $this->error_str, $connection_timeout);
2432
+			} else {
2433
+				$this->fp = @fsockopen($host, $this->port, $this->errno, $this->error_str);
2434
+			}
2435
+
2436
+			// test pointer
2437
+			if (!$this->fp) {
2438
+				$msg = 'Couldn\'t open socket connection to server ' . $this->url;
2439
+				if ($this->errno) {
2440
+					$msg .= ', Error (' . $this->errno . '): ' . $this->error_str;
2441
+				} else {
2442
+					$msg .= ' prior to connect().  This is often a problem looking up the host name.';
2443
+				}
2444
+				$this->debug($msg);
2445
+				$this->setError($msg);
2446
+				return false;
2447
+			}
2448
+
2449
+			// set response timeout
2450
+			$this->debug('set response timeout to ' . $response_timeout);
2451
+			stream_set_timeout($this->fp, $response_timeout);
2452
+
2453
+			$this->debug('socket connected');
2454
+			return true;
2455
+		} elseif ('curl' === $this->io_method()) {
2456
+			if (!extension_loaded('curl')) {
2457
+				//			$this->setError('cURL Extension, or OpenSSL extension w/ PHP version >= 4.3 is required for HTTPS');
2458
+				$this->setError('The PHP cURL Extension is required for HTTPS or NLTM.  You will need to re-build or update your PHP to include cURL or change php.ini to load the PHP cURL extension.');
2459
+				return false;
2460
+			}
2461
+			// Avoid warnings when PHP does not have these options
2462
+			if (defined('CURLOPT_CONNECTIONTIMEOUT')) {
2463
+				$CURLOPT_CONNECTIONTIMEOUT = CURLOPT_CONNECTIONTIMEOUT;
2464
+			} else {
2465
+				$CURLOPT_CONNECTIONTIMEOUT = 78;
2466
+			}
2467
+			if (defined('CURLOPT_HTTPAUTH')) {
2468
+				$CURLOPT_HTTPAUTH = CURLOPT_HTTPAUTH;
2469
+			} else {
2470
+				$CURLOPT_HTTPAUTH = 107;
2471
+			}
2472
+			if (defined('CURLOPT_PROXYAUTH')) {
2473
+				$CURLOPT_PROXYAUTH = CURLOPT_PROXYAUTH;
2474
+			} else {
2475
+				$CURLOPT_PROXYAUTH = 111;
2476
+			}
2477
+			if (defined('CURLAUTH_BASIC')) {
2478
+				$CURLAUTH_BASIC = CURLAUTH_BASIC;
2479
+			} else {
2480
+				$CURLAUTH_BASIC = 1;
2481
+			}
2482
+			if (defined('CURLAUTH_DIGEST')) {
2483
+				$CURLAUTH_DIGEST = CURLAUTH_DIGEST;
2484
+			} else {
2485
+				$CURLAUTH_DIGEST = 2;
2486
+			}
2487
+			if (defined('CURLAUTH_NTLM')) {
2488
+				$CURLAUTH_NTLM = CURLAUTH_NTLM;
2489
+			} else {
2490
+				$CURLAUTH_NTLM = 8;
2491
+			}
2492
+
2493
+			$this->debug('connect using cURL');
2494
+			// init CURL
2495
+			$this->ch = curl_init();
2496
+			// set url
2497
+			$hostURL = ('' != $this->port) ? "$this->scheme://$this->host:$this->port" : "$this->scheme://$this->host";
2498
+			// add path
2499
+			$hostURL .= $this->path;
2500
+			$this->setCurlOption(CURLOPT_URL, $hostURL);
2501
+			// follow location headers (re-directs)
2502
+			$this->setCurlOption(CURLOPT_FOLLOWLOCATION, 1);
2503
+			// ask for headers in the response output
2504
+			$this->setCurlOption(CURLOPT_HEADER, 1);
2505
+			// ask for the response output as the return value
2506
+			$this->setCurlOption(CURLOPT_RETURNTRANSFER, 1);
2507
+			// encode
2508
+			// We manage this ourselves through headers and encoding
2509
+			//		if(function_exists('gzuncompress')){
2510
+			//			$this->setCurlOption(CURLOPT_ENCODING, 'deflate');
2511
+			//		}
2512
+			// persistent connection
2513
+			if ($this->persistentConnection) {
2514
+				// I believe the following comment is now bogus, having applied to
2515
+				// the code when it used CURLOPT_CUSTOMREQUEST to send the request.
2516
+				// The way we send data, we cannot use persistent connections, since
2517
+				// there will be some "junk" at the end of our request.
2518
+				//$this->setCurlOption(CURL_HTTP_VERSION_1_1, true);
2519
+				$this->persistentConnection = false;
2520
+				$this->setHeader('Connection', 'close');
2521
+			}
2522
+			// set timeouts
2523
+			if (0 != $connection_timeout) {
2524
+				$this->setCurlOption($CURLOPT_CONNECTIONTIMEOUT, $connection_timeout);
2525
+			}
2526
+			if (0 != $response_timeout) {
2527
+				$this->setCurlOption(CURLOPT_TIMEOUT, $response_timeout);
2528
+			}
2529
+
2530
+			if ('https' === $this->scheme) {
2531
+				$this->debug('set cURL SSL verify options');
2532
+				// recent versions of cURL turn on peer/host checking by default,
2533
+				// while PHP binaries are not compiled with a default location for the
2534
+				// CA cert bundle, so disable peer/host checking.
2535
+				//$this->setCurlOption(CURLOPT_CAINFO, 'f:\php-4.3.2-win32\extensions\curl-ca-bundle.crt');
2536
+				$this->setCurlOption(CURLOPT_SSL_VERIFYPEER, 0);
2537
+				$this->setCurlOption(CURLOPT_SSL_VERIFYHOST, 0);
2538
+
2539
+				// support client certificates (thanks Tobias Boes, Doug Anarino, Eryan Ariobowo)
2540
+				if ('certificate' === $this->authtype) {
2541
+					$this->debug('set cURL certificate options');
2542
+					if (isset($this->certRequest['cainfofile'])) {
2543
+						$this->setCurlOption(CURLOPT_CAINFO, $this->certRequest['cainfofile']);
2544
+					}
2545
+					if (isset($this->certRequest['verifypeer'])) {
2546
+						$this->setCurlOption(CURLOPT_SSL_VERIFYPEER, $this->certRequest['verifypeer']);
2547
+					} else {
2548
+						$this->setCurlOption(CURLOPT_SSL_VERIFYPEER, 1);
2549
+					}
2550
+					if (isset($this->certRequest['verifyhost'])) {
2551
+						$this->setCurlOption(CURLOPT_SSL_VERIFYHOST, $this->certRequest['verifyhost']);
2552
+					} else {
2553
+						$this->setCurlOption(CURLOPT_SSL_VERIFYHOST, 1);
2554
+					}
2555
+					if (isset($this->certRequest['sslcertfile'])) {
2556
+						$this->setCurlOption(CURLOPT_SSLCERT, $this->certRequest['sslcertfile']);
2557
+					}
2558
+					if (isset($this->certRequest['sslkeyfile'])) {
2559
+						$this->setCurlOption(CURLOPT_SSLKEY, $this->certRequest['sslkeyfile']);
2560
+					}
2561
+					if (isset($this->certRequest['passphrase'])) {
2562
+						$this->setCurlOption(CURLOPT_SSLKEYPASSWD, $this->certRequest['passphrase']);
2563
+					}
2564
+					if (isset($this->certRequest['certpassword'])) {
2565
+						$this->setCurlOption(CURLOPT_SSLCERTPASSWD, $this->certRequest['certpassword']);
2566
+					}
2567
+				}
2568
+			}
2569
+			if ($this->authtype && ('certificate' !== $this->authtype)) {
2570
+				if ($this->username) {
2571
+					$this->debug('set cURL username/password');
2572
+					$this->setCurlOption(CURLOPT_USERPWD, "$this->username:$this->password");
2573
+				}
2574
+				if ('basic' === $this->authtype) {
2575
+					$this->debug('set cURL for Basic authentication');
2576
+					$this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_BASIC);
2577
+				}
2578
+				if ('digest' === $this->authtype) {
2579
+					$this->debug('set cURL for digest authentication');
2580
+					$this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_DIGEST);
2581
+				}
2582
+				if ('ntlm' === $this->authtype) {
2583
+					$this->debug('set cURL for NTLM authentication');
2584
+					$this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_NTLM);
2585
+				}
2586
+			}
2587
+			if (is_array($this->proxy)) {
2588
+				$this->debug('set cURL proxy options');
2589
+				if ('' != $this->proxy['port']) {
2590
+					$this->setCurlOption(CURLOPT_PROXY, $this->proxy['host'] . ':' . $this->proxy['port']);
2591
+				} else {
2592
+					$this->setCurlOption(CURLOPT_PROXY, $this->proxy['host']);
2593
+				}
2594
+				if ($this->proxy['username'] || $this->proxy['password']) {
2595
+					$this->debug('set cURL proxy authentication options');
2596
+					$this->setCurlOption(CURLOPT_PROXYUSERPWD, $this->proxy['username'] . ':' . $this->proxy['password']);
2597
+					if ('basic' === $this->proxy['authtype']) {
2598
+						$this->setCurlOption($CURLOPT_PROXYAUTH, $CURLAUTH_BASIC);
2599
+					}
2600
+					if ('ntlm' === $this->proxy['authtype']) {
2601
+						$this->setCurlOption($CURLOPT_PROXYAUTH, $CURLAUTH_NTLM);
2602
+					}
2603
+				}
2604
+			}
2605
+			$this->debug('cURL connection set up');
2606
+			return true;
2607
+		} else {
2608
+			$this->setError('Unknown scheme ' . $this->scheme);
2609
+			$this->debug('Unknown scheme ' . $this->scheme);
2610
+			return false;
2611
+		}
2612
+	}
2613
+
2614
+	/**
2615
+	 * sends the SOAP request and gets the SOAP response via HTTP[S]
2616
+	 *
2617
+	 * @param    string $data message data
2618
+	 * @param    integer $timeout set connection timeout in seconds
2619
+	 * @param    integer $response_timeout set response timeout in seconds
2620
+	 * @param    array $cookies cookies to send
2621
+	 * @return    string data
2622
+	 * @access   public
2623
+	 */
2624
+	public function send($data, $timeout = 0, $response_timeout = 30, $cookies = null)
2625
+	{
2626
+		$this->debug('entered send() with data of length: ' . strlen($data));
2627
+
2628
+		$this->tryagain = true;
2629
+		$tries = 0;
2630
+		while ($this->tryagain) {
2631
+			$this->tryagain = false;
2632
+			if ($tries++ < 2) {
2633
+				// make connnection
2634
+				if (!$this->connect($timeout, $response_timeout)) {
2635
+					return false;
2636
+				}
2637
+
2638
+				// send request
2639
+				if (!$this->sendRequest($data, $cookies)) {
2640
+					return false;
2641
+				}
2642
+
2643
+				// get response
2644
+				$respdata = $this->getResponse();
2645
+			} else {
2646
+				$this->setError("Too many tries to get an OK response ($this->response_status_line)");
2647
+			}
2648
+		}
2649
+		$this->debug('end of send()');
2650
+		return $respdata;
2651
+	}
2652
+
2653
+
2654
+	/**
2655
+	 * sends the SOAP request and gets the SOAP response via HTTPS using CURL
2656
+	 *
2657
+	 * @param    string $data message data
2658
+	 * @param    integer $timeout set connection timeout in seconds
2659
+	 * @param    integer $response_timeout set response timeout in seconds
2660
+	 * @param    array $cookies cookies to send
2661
+	 * @return    string data
2662
+	 * @access   public
2663
+	 * @deprecated
2664
+	 */
2665
+	public function sendHTTPS($data, $timeout = 0, $response_timeout = 30, $cookies)
2666
+	{
2667
+		return $this->send($data, $timeout, $response_timeout, $cookies);
2668
+	}
2669
+
2670
+	/**
2671
+	 * if authenticating, set user credentials here
2672
+	 *
2673
+	 * @param    string $username
2674
+	 * @param    string $password
2675
+	 * @param    string $authtype (basic|digest|certificate|ntlm)
2676
+	 * @param    array $digestRequest (keys must be nonce, nc, realm, qop)
2677
+	 * @param    array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs)
2678
+	 * @access   public
2679
+	 */
2680
+	public function setCredentials($username, $password, $authtype = 'basic', $digestRequest = [], $certRequest = [])
2681
+	{
2682
+		$this->debug("setCredentials username=$username authtype=$authtype digestRequest=");
2683
+		$this->appendDebug($this->varDump($digestRequest));
2684
+		$this->debug('certRequest=');
2685
+		$this->appendDebug($this->varDump($certRequest));
2686
+		// cf. RFC 2617
2687
+		if ('basic' === $authtype) {
2688
+			$this->setHeader('Authorization', 'Basic ' . base64_encode(str_replace(':', '', $username) . ':' . $password));
2689
+		} elseif ('digest' === $authtype) {
2690
+			if (isset($digestRequest['nonce'])) {
2691
+				$digestRequest['nc'] = isset($digestRequest['nc']) ? $digestRequest['nc']++ : 1;
2692
+
2693
+				// calculate the Digest hashes (calculate code based on digest implementation found at: http://www.rassoc.com/gregr/weblog/stories/2002/07/09/webServicesSecurityHttpDigestAuthenticationWithoutActiveDirectory.html)
2694
+
2695
+				// A1 = unq(username-value) ":" unq(realm-value) ":" passwd
2696
+				$A1 = $username . ':' . (isset($digestRequest['realm']) ? $digestRequest['realm'] : '') . ':' . $password;
2697
+
2698
+				// H(A1) = MD5(A1)
2699
+				$HA1 = md5($A1);
2700
+
2701
+				// A2 = Method ":" digest-uri-value
2702
+				$A2 = $this->request_method . ':' . $this->digest_uri;
2703
+
2704
+				// H(A2)
2705
+				$HA2 = md5($A2);
2706
+
2707
+				// KD(secret, data) = H(concat(secret, ":", data))
2708
+				// if qop == auth:
2709
+				// request-digest  = <"> < KD ( H(A1),     unq(nonce-value)
2710
+				//                              ":" nc-value
2711
+				//                              ":" unq(cnonce-value)
2712
+				//                              ":" unq(qop-value)
2713
+				//                              ":" H(A2)
2714
+				//                            ) <">
2715
+				// if qop is missing,
2716
+				// request-digest  = <"> < KD ( H(A1), unq(nonce-value) ":" H(A2) ) > <">
2717
+
2718
+				$unhashedDigest = '';
2719
+				$nonce = isset($digestRequest['nonce']) ? $digestRequest['nonce'] : '';
2720
+				$cnonce = $nonce;
2721
+				if ('' != $digestRequest['qop']) {
2722
+					$unhashedDigest = $HA1 . ':' . $nonce . ':' . sprintf('%08d', $digestRequest['nc']) . ':' . $cnonce . ':' . $digestRequest['qop'] . ':' . $HA2;
2723
+				} else {
2724
+					$unhashedDigest = $HA1 . ':' . $nonce . ':' . $HA2;
2725
+				}
2726
+
2727
+				$hashedDigest = md5($unhashedDigest);
2728
+
2729
+				$opaque = '';
2730
+				if (isset($digestRequest['opaque'])) {
2731
+					$opaque = ', opaque="' . $digestRequest['opaque'] . '"';
2732
+				}
2733
+
2734
+				$this->setHeader('Authorization', 'Digest username="' . $username . '", realm="' . $digestRequest['realm'] . '", nonce="' . $nonce . '", uri="' . $this->digest_uri . $opaque . '", cnonce="' . $cnonce . '", nc=' . sprintf('%08x', $digestRequest['nc']) . ', qop="' . $digestRequest['qop'] . '", response="' . $hashedDigest . '"');
2735
+			}
2736
+		} elseif ('certificate' === $authtype) {
2737
+			$this->certRequest = $certRequest;
2738
+			$this->debug('Authorization header not set for certificate');
2739
+		} elseif ('ntlm' === $authtype) {
2740
+			// do nothing
2741
+			$this->debug('Authorization header not set for ntlm');
2742
+		}
2743
+		$this->username = $username;
2744
+		$this->password = $password;
2745
+		$this->authtype = $authtype;
2746
+		$this->digestRequest = $digestRequest;
2747
+	}
2748
+
2749
+	/**
2750
+	 * set the soapaction value
2751
+	 *
2752
+	 * @param    string $soapaction
2753
+	 * @access   public
2754
+	 */
2755
+	public function setSOAPAction($soapaction)
2756
+	{
2757
+		$this->setHeader('SOAPAction', '"' . $soapaction . '"');
2758
+	}
2759
+
2760
+	/**
2761
+	 * use http encoding
2762
+	 *
2763
+	 * @param    string $enc encoding style. supported values: gzip, deflate, or both
2764
+	 * @access   public
2765
+	 */
2766
+	public function setEncoding($enc = 'gzip, deflate')
2767
+	{
2768
+		if (function_exists('gzdeflate')) {
2769
+			$this->protocol_version = '1.1';
2770
+			$this->setHeader('Accept-Encoding', $enc);
2771
+			if (!isset($this->outgoing_headers['Connection'])) {
2772
+				$this->setHeader('Connection', 'close');
2773
+				$this->persistentConnection = false;
2774
+			}
2775
+			// deprecated as of PHP 5.3.0
2776
+			//set_magic_quotes_runtime(0);
2777
+			$this->encoding = $enc;
2778
+		}
2779
+	}
2780
+
2781
+	/**
2782
+	 * set proxy info here
2783
+	 *
2784
+	 * @param    bool|string $proxyhost use an empty string to remove proxy
2785
+	 * @param    bool|string $proxyport
2786
+	 * @param    bool|string $proxyusername
2787
+	 * @param    bool|string $proxypassword
2788
+	 * @param    bool|string $proxyauthtype (basic|ntlm)
2789
+	 * @access   public
2790
+	 */
2791
+	public function setProxy($proxyhost, $proxyport, $proxyusername = '', $proxypassword = '', $proxyauthtype = 'basic')
2792
+	{
2793
+		if ($proxyhost) {
2794
+			$this->proxy = [
2795
+				'host' => $proxyhost,
2796
+				'port' => $proxyport,
2797
+				'username' => $proxyusername,
2798
+				'password' => $proxypassword,
2799
+				'authtype' => $proxyauthtype
2800
+			];
2801
+			if ('' != $proxyusername && '' != $proxypassword && $proxyauthtype = 'basic') {
2802
+				$this->setHeader('Proxy-Authorization', ' Basic ' . base64_encode($proxyusername . ':' . $proxypassword));
2803
+			}
2804
+		} else {
2805
+			$this->debug('remove proxy');
2806
+			$proxy = null;
2807
+			$this->unsetHeader('Proxy-Authorization');
2808
+		}
2809
+	}
2810
+
2811
+	/**
2812
+	 * Test if the given string starts with a header that is to be skipped.
2813
+	 * Skippable headers result from chunked transfer and proxy requests.
2814
+	 *
2815
+	 * @param    string $data The string to check.
2816
+	 * @returns    boolean    Whether a skippable header was found.
2817
+	 * @access    private
2818
+	 * @return bool
2819
+	 */
2820
+	private function isSkippableCurlHeader(&$data)
2821
+	{
2822
+		$skipHeaders = [
2823
+			'HTTP/1.1 100',
2824
+			'HTTP/1.0 301',
2825
+			'HTTP/1.1 301',
2826
+			'HTTP/1.0 302',
2827
+			'HTTP/1.1 302',
2828
+			'HTTP/1.0 401',
2829
+			'HTTP/1.1 401',
2830
+			'HTTP/1.0 200 Connection established'
2831
+		];
2832
+		foreach ($skipHeaders as $hd) {
2833
+			$prefix = substr($data, 0, strlen($hd));
2834
+			if ($prefix == $hd) {
2835
+				return true;
2836
+			}
2837
+		}
2838
+
2839
+		return false;
2840
+	}
2841
+
2842
+	/**
2843
+	 * decode a string that is encoded w/ "chunked' transfer encoding
2844
+	 * as defined in RFC2068 19.4.6
2845
+	 *
2846
+	 * @param    string $buffer
2847
+	 * @param    string $lb
2848
+	 * @returns    string
2849
+	 * @access   public
2850
+	 * @deprecated
2851
+	 * @return string
2852
+	 */
2853
+	public function decodeChunked($buffer, $lb)
2854
+	{
2855
+		// length := 0
2856
+		$length = 0;
2857
+		$new = '';
2858
+
2859
+		// read chunk-size, chunk-extension (if any) and CRLF
2860
+		// get the position of the linebreak
2861
+		$chunkend = strpos($buffer, $lb);
2862
+		if (false == $chunkend) {
2863
+			$this->debug('no linebreak found in decodeChunked');
2864
+			return $new;
2865
+		}
2866
+		$temp = substr($buffer, 0, $chunkend);
2867
+		$chunk_size = hexdec(trim($temp));
2868
+		$chunkstart = $chunkend + strlen($lb);
2869
+		// while (chunk-size > 0) {
2870
+		while ($chunk_size > 0) {
2871
+			$this->debug("chunkstart: $chunkstart chunk_size: $chunk_size");
2872
+			$chunkend = strpos($buffer, $lb, $chunkstart + $chunk_size);
2873
+
2874
+			// Just in case we got a broken connection
2875
+			if (false == $chunkend) {
2876
+				$chunk = substr($buffer, $chunkstart);
2877
+				// append chunk-data to entity-body
2878
+				$new .= $chunk;
2879
+				$length += strlen($chunk);
2880
+				break;
2881
+			}
2882
+
2883
+			// read chunk-data and CRLF
2884
+			$chunk = substr($buffer, $chunkstart, $chunkend - $chunkstart);
2885
+			// append chunk-data to entity-body
2886
+			$new .= $chunk;
2887
+			// length := length + chunk-size
2888
+			$length += strlen($chunk);
2889
+			// read chunk-size and CRLF
2890
+			$chunkstart = $chunkend + strlen($lb);
2891
+
2892
+			$chunkend = strpos($buffer, $lb, $chunkstart) + strlen($lb);
2893
+			if (false == $chunkend) {
2894
+				break; //Just in case we got a broken connection
2895
+			}
2896
+			$temp = substr($buffer, $chunkstart, $chunkend - $chunkstart);
2897
+			$chunk_size = hexdec(trim($temp));
2898
+			$chunkstart = $chunkend;
2899
+		}
2900
+		return $new;
2901
+	}
2902
+
2903
+	/**
2904
+	 * Writes the payload, including HTTP headers, to $this->outgoing_payload.
2905
+	 *
2906
+	 * @param    string $data HTTP body
2907
+	 * @param    string $cookie_str data for HTTP Cookie header
2908
+	 * @return    void
2909
+	 * @access    private
2910
+	 */
2911
+	private function buildPayload($data, $cookie_str = '')
2912
+	{
2913
+		// Note: for cURL connections, $this->outgoing_payload is ignored,
2914
+		// as is the Content-Length header, but these are still created as
2915
+		// debugging guides.
2916
+
2917
+		// add content-length header
2918
+		if ('GET' !== $this->request_method) {
2919
+			$this->setHeader('Content-Length', strlen($data));
2920
+		}
2921
+
2922
+		// start building outgoing payload:
2923
+		if ($this->proxy) {
2924
+			$uri = $this->url;
2925
+		} else {
2926
+			$uri = $this->uri;
2927
+		}
2928
+		$req = "$this->request_method $uri HTTP/$this->protocol_version";
2929
+		$this->debug("HTTP request: $req");
2930
+		$this->outgoing_payload = "$req\r\n";
2931
+
2932
+		// loop thru headers, serializing
2933
+		foreach ($this->outgoing_headers as $k => $v) {
2934
+			$hdr = $k . ': ' . $v;
2935
+			$this->debug("HTTP header: $hdr");
2936
+			$this->outgoing_payload .= "$hdr\r\n";
2937
+		}
2938
+
2939
+		// add any cookies
2940
+		if ('' != $cookie_str) {
2941
+			$hdr = 'Cookie: ' . $cookie_str;
2942
+			$this->debug("HTTP header: $hdr");
2943
+			$this->outgoing_payload .= "$hdr\r\n";
2944
+		}
2945
+
2946
+		// header/body separator
2947
+		$this->outgoing_payload .= "\r\n";
2948
+
2949
+		// add data
2950
+		$this->outgoing_payload .= $data;
2951
+	}
2952
+
2953
+	/**
2954
+	 * sends the SOAP request via HTTP[S]
2955
+	 *
2956
+	 * @param    string $data message data
2957
+	 * @param    array $cookies cookies to send
2958
+	 * @return    boolean    true if OK, false if problem
2959
+	 * @access   private
2960
+	 */
2961
+	private function sendRequest($data, $cookies = null)
2962
+	{
2963
+		// build cookie string
2964
+		$cookie_str = $this->getCookiesForRequest($cookies, (('ssl' === $this->scheme) || ('https' === $this->scheme)));
2965
+
2966
+		// build payload
2967
+		$this->buildPayload($data, $cookie_str);
2968
+
2969
+		if ('socket' === $this->io_method()) {
2970
+			// send payload
2971
+			if (!fwrite($this->fp, $this->outgoing_payload, strlen($this->outgoing_payload))) {
2972
+				$this->setError('couldn\'t write message data to socket');
2973
+				$this->debug('couldn\'t write message data to socket');
2974
+				return false;
2975
+			}
2976
+			$this->debug('wrote data to socket, length = ' . strlen($this->outgoing_payload));
2977
+			return true;
2978
+		} elseif ('curl' === $this->io_method()) {
2979
+			// set payload
2980
+			// cURL does say this should only be the verb, and in fact it
2981
+			// turns out that the URI and HTTP version are appended to this, which
2982
+			// some servers refuse to work with (so we no longer use this method!)
2983
+			//$this->setCurlOption(CURLOPT_CUSTOMREQUEST, $this->outgoing_payload);
2984
+			$curl_headers = [];
2985
+			foreach ($this->outgoing_headers as $k => $v) {
2986
+				if ('Connection' === $k || 'Content-Length' === $k || 'Host' === $k || 'Authorization' === $k || 'Proxy-Authorization' === $k) {
2987
+					$this->debug("Skip cURL header $k: $v");
2988
+				} else {
2989
+					$curl_headers[] = "$k: $v";
2990
+				}
2991
+			}
2992
+			if ('' != $cookie_str) {
2993
+				$curl_headers[] = 'Cookie: ' . $cookie_str;
2994
+			}
2995
+			$this->setCurlOption(CURLOPT_HTTPHEADER, $curl_headers);
2996
+			$this->debug('set cURL HTTP headers');
2997
+			if ('POST' === $this->request_method) {
2998
+				$this->setCurlOption(CURLOPT_POST, 1);
2999
+				$this->setCurlOption(CURLOPT_POSTFIELDS, $data);
3000
+				$this->debug('set cURL POST data');
3001
+			} else {
3002
+			}
3003
+			// insert custom user-set cURL options
3004
+			foreach ($this->ch_options as $key => $val) {
3005
+				$this->setCurlOption($key, $val);
3006
+			}
3007
+
3008
+			$this->debug('set cURL payload');
3009
+			return true;
3010
+		}
3011
+	}
3012
+
3013
+	/**
3014
+	 * gets the SOAP response via HTTP[S]
3015
+	 *
3016
+	 * @return    string the response (also sets member variables like incoming_payload)
3017
+	 * @access   private
3018
+	 */
3019
+	private function getResponse()
3020
+	{
3021
+		$this->incoming_payload = '';
3022
+
3023
+		if ('socket' === $this->io_method()) {
3024
+			// loop until headers have been retrieved
3025
+			$data = '';
3026
+			while (!isset($lb)) {
3027
+
3028
+				// We might EOF during header read.
3029
+				if (feof($this->fp)) {
3030
+					$this->incoming_payload = $data;
3031
+					$this->debug('found no headers before EOF after length ' . strlen($data));
3032
+					$this->debug("received before EOF:\n" . $data);
3033
+					$this->setError('server failed to send headers');
3034
+					return false;
3035
+				}
3036
+
3037
+				$tmp = fgets($this->fp, 256);
3038
+				$tmplen = strlen($tmp);
3039
+				$this->debug("read line of $tmplen bytes: " . trim($tmp));
3040
+
3041
+				if (0 == $tmplen) {
3042
+					$this->incoming_payload = $data;
3043
+					$this->debug('socket read of headers timed out after length ' . strlen($data));
3044
+					$this->debug('read before timeout: ' . $data);
3045
+					$this->setError('socket read of headers timed out');
3046
+					return false;
3047
+				}
3048
+
3049
+				$data .= $tmp;
3050
+				$pos = strpos($data, "\r\n\r\n");
3051
+				if ($pos > 1) {
3052
+					$lb = "\r\n";
3053
+				} else {
3054
+					$pos = strpos($data, "\n\n");
3055
+					if ($pos > 1) {
3056
+						$lb = "\n";
3057
+					}
3058
+				}
3059
+				// remove 100 headers
3060
+				if (isset($lb) && preg_match('/^HTTP\/1.1 100/', $data)) {
3061
+					unset($lb);
3062
+					$data = '';
3063
+				}//
3064
+			}
3065
+			// store header data
3066
+			$this->incoming_payload .= $data;
3067
+			$this->debug('found end of headers after length ' . strlen($data));
3068
+			// process headers
3069
+			$header_data = trim(substr($data, 0, $pos));
3070
+			$header_array = explode($lb, $header_data);
3071
+			$this->incoming_headers = [];
3072
+			$this->incoming_cookies = [];
3073
+			foreach ($header_array as $header_line) {
3074
+				$arr = explode(':', $header_line, 2);
3075
+				if (is_array($arr) && count($arr) > 1) {
3076
+					$header_name = strtolower(trim($arr[0]));
3077
+					$this->incoming_headers[$header_name] = trim($arr[1]);
3078
+					if ('set-cookie' === $header_name) {
3079
+						// TODO: allow multiple cookies from parseCookie
3080
+						$cookie = $this->parseCookie(trim($arr[1]));
3081
+						if ($cookie) {
3082
+							$this->incoming_cookies[] = $cookie;
3083
+							$this->debug('found cookie: ' . $cookie['name'] . ' = ' . $cookie['value']);
3084
+						} else {
3085
+							$this->debug('did not find cookie in ' . trim($arr[1]));
3086
+						}
3087
+					}
3088
+				} elseif (isset($header_name)) {
3089
+					// append continuation line to previous header
3090
+					$this->incoming_headers[$header_name] .= $lb . ' ' . $header_line;
3091
+				}
3092
+			}
3093
+
3094
+			// loop until msg has been received
3095
+			if (isset($this->incoming_headers['transfer-encoding']) && 'chunked' === strtolower($this->incoming_headers['transfer-encoding'])) {
3096
+				$content_length = 2147483647;    // ignore any content-length header
3097
+				$chunked = true;
3098
+				$this->debug('want to read chunked content');
3099
+			} elseif (isset($this->incoming_headers['content-length'])) {
3100
+				$content_length = $this->incoming_headers['content-length'];
3101
+				$chunked = false;
3102
+				$this->debug("want to read content of length $content_length");
3103
+			} else {
3104
+				$content_length = 2147483647;
3105
+				$chunked = false;
3106
+				$this->debug('want to read content to EOF');
3107
+			}
3108
+			$data = '';
3109
+			do {
3110
+				if ($chunked) {
3111
+					$tmp = fgets($this->fp, 256);
3112
+					$tmplen = strlen($tmp);
3113
+					$this->debug("read chunk line of $tmplen bytes");
3114
+					if (0 == $tmplen) {
3115
+						$this->incoming_payload = $data;
3116
+						$this->debug('socket read of chunk length timed out after length ' . strlen($data));
3117
+						$this->debug("read before timeout:\n" . $data);
3118
+						$this->setError('socket read of chunk length timed out');
3119
+						return false;
3120
+					}
3121
+					$content_length = hexdec(trim($tmp));
3122
+					$this->debug("chunk length $content_length");
3123
+				}
3124
+				$strlen = 0;
3125
+				while (($strlen < $content_length) && (!feof($this->fp))) {
3126
+					$readlen = min(8192, $content_length - $strlen);
3127
+					$tmp = fread($this->fp, $readlen);
3128
+					$tmplen = strlen($tmp);
3129
+					$this->debug("read buffer of $tmplen bytes");
3130
+					if ((0 == $tmplen) && (!feof($this->fp))) {
3131
+						$this->incoming_payload = $data;
3132
+						$this->debug('socket read of body timed out after length ' . strlen($data));
3133
+						$this->debug("read before timeout:\n" . $data);
3134
+						$this->setError('socket read of body timed out');
3135
+						return false;
3136
+					}
3137
+					$strlen += $tmplen;
3138
+					$data .= $tmp;
3139
+				}
3140
+				if ($chunked && ($content_length > 0)) {
3141
+					$tmp = fgets($this->fp, 256);
3142
+					$tmplen = strlen($tmp);
3143
+					$this->debug("read chunk terminator of $tmplen bytes");
3144
+					if (0 == $tmplen) {
3145
+						$this->incoming_payload = $data;
3146
+						$this->debug('socket read of chunk terminator timed out after length ' . strlen($data));
3147
+						$this->debug("read before timeout:\n" . $data);
3148
+						$this->setError('socket read of chunk terminator timed out');
3149
+						return false;
3150
+					}
3151
+				}
3152
+			} while ($chunked && ($content_length > 0) && (!feof($this->fp)));
3153
+			if (feof($this->fp)) {
3154
+				$this->debug('read to EOF');
3155
+			}
3156
+			$this->debug('read body of length ' . strlen($data));
3157
+			$this->incoming_payload .= $data;
3158
+			$this->debug('received a total of ' . strlen($this->incoming_payload) . ' bytes of data from server');
3159
+
3160
+			// close filepointer
3161
+			if (
3162
+				(isset($this->incoming_headers['connection']) && 'close' === strtolower($this->incoming_headers['connection'])) ||
3163
+				(!$this->persistentConnection) || feof($this->fp)
3164
+			) {
3165
+				fclose($this->fp);
3166
+				$this->fp = false;
3167
+				$this->debug('closed socket');
3168
+			}
3169
+
3170
+			// connection was closed unexpectedly
3171
+			if ('' == $this->incoming_payload) {
3172
+				$this->setError('no response from server');
3173
+				return false;
3174
+			}
3175
+
3176
+			// decode transfer-encoding
3177 3177
 //		if(isset($this->incoming_headers['transfer-encoding']) && strtolower($this->incoming_headers['transfer-encoding']) == 'chunked'){
3178 3178
 //			if(!$data = $this->decodeChunked($data, $lb)){
3179 3179
 //				$this->setError('Decoding of chunked data failed');
3180 3180
 //				return false;
3181 3181
 //			}
3182
-            //print "<pre>\nde-chunked:\n---------------\n$data\n\n---------------\n</pre>";
3183
-            // set decoded payload
3182
+			//print "<pre>\nde-chunked:\n---------------\n$data\n\n---------------\n</pre>";
3183
+			// set decoded payload
3184 3184
 //			$this->incoming_payload = $header_data.$lb.$lb.$data;
3185 3185
 //		}
3186
-        } elseif ('curl' === $this->io_method()) {
3187
-            // send and receive
3188
-            $this->debug('send and receive with cURL');
3189
-            $this->incoming_payload = curl_exec($this->ch);
3190
-            $data = $this->incoming_payload;
3191
-
3192
-            $cErr = curl_error($this->ch);
3193
-            if ('' != $cErr) {
3194
-                $err = 'cURL ERROR: ' . curl_errno($this->ch) . ': ' . $cErr . '<br>';
3195
-                // TODO: there is a PHP bug that can cause this to SEGV for CURLINFO_CONTENT_TYPE
3196
-                foreach (curl_getinfo($this->ch) as $k => $v) {
3197
-                    $err .= "$k: $v<br>";
3198
-                }
3199
-                $this->debug($err);
3200
-                $this->setError($err);
3201
-                curl_close($this->ch);
3202
-                return false;
3203
-            } else {
3204
-                //echo '<pre>';
3205
-                //var_dump(curl_getinfo($this->ch));
3206
-                //echo '</pre>';
3207
-            }
3208
-            // close curl
3209
-            $this->debug('No cURL error, closing cURL');
3210
-            curl_close($this->ch);
3211
-
3212
-            // try removing skippable headers
3213
-            $savedata = $data;
3214
-            while ($this->isSkippableCurlHeader($data)) {
3215
-                $this->debug('Found HTTP header to skip');
3216
-                if (false !== ($pos = strpos($data, "\r\n\r\n"))) {
3217
-                    $data = ltrim(substr($data, $pos));
3218
-                } elseif (false !== ($pos = strpos($data, "\n\n"))) {
3219
-                    $data = ltrim(substr($data, $pos));
3220
-                }
3221
-            }
3222
-
3223
-            if ('' == $data) {
3224
-                // have nothing left; just remove 100 header(s)
3225
-                $data = $savedata;
3226
-                while (preg_match('/^HTTP\/1.1 100/', $data)) {
3227
-                    if (false !== ($pos = strpos($data, "\r\n\r\n"))) {
3228
-                        $data = ltrim(substr($data, $pos));
3229
-                    } elseif (false !== ($pos = strpos($data, "\n\n"))) {
3230
-                        $data = ltrim(substr($data, $pos));
3231
-                    }
3232
-                }
3233
-            }
3234
-
3235
-            // separate content from HTTP headers
3236
-            if (false !== ($pos = strpos($data, "\r\n\r\n"))) {
3237
-                $lb = "\r\n";
3238
-            } elseif (false !== ($pos = strpos($data, "\n\n"))) {
3239
-                $lb = "\n";
3240
-            } else {
3241
-                $this->debug('no proper separation of headers and document');
3242
-                $this->setError('no proper separation of headers and document');
3243
-                return false;
3244
-            }
3245
-            $header_data = trim(substr($data, 0, $pos));
3246
-            $header_array = explode($lb, $header_data);
3247
-            $data = ltrim(substr($data, $pos));
3248
-            $this->debug('found proper separation of headers and document');
3249
-            $this->debug('cleaned data, stringlen: ' . strlen($data));
3250
-            // clean headers
3251
-            foreach ($header_array as $header_line) {
3252
-                $arr = explode(':', $header_line, 2);
3253
-                if (is_array($arr) && count($arr) > 1) {
3254
-                    $header_name = strtolower(trim($arr[0]));
3255
-                    $this->incoming_headers[$header_name] = trim($arr[1]);
3256
-                    if ('set-cookie' === $header_name) {
3257
-                        // TODO: allow multiple cookies from parseCookie
3258
-                        $cookie = $this->parseCookie(trim($arr[1]));
3259
-                        if ($cookie) {
3260
-                            $this->incoming_cookies[] = $cookie;
3261
-                            $this->debug('found cookie: ' . $cookie['name'] . ' = ' . $cookie['value']);
3262
-                        } else {
3263
-                            $this->debug('did not find cookie in ' . trim($arr[1]));
3264
-                        }
3265
-                    }
3266
-                } elseif (isset($header_name)) {
3267
-                    // append continuation line to previous header
3268
-                    $this->incoming_headers[$header_name] .= $lb . ' ' . $header_line;
3269
-                }
3270
-            }
3271
-        }
3272
-
3273
-        $this->response_status_line = $header_array[0];
3274
-        $arr = explode(' ', $this->response_status_line, 3);
3275
-        $http_version = $arr[0];
3276
-        $http_status = (int)$arr[1];
3277
-        $http_reason = count($arr) > 2 ? $arr[2] : '';
3278
-
3279
-        // see if we need to resend the request with http digest authentication
3280
-        if (isset($this->incoming_headers['location']) && (301 == $http_status || 302 == $http_status)) {
3281
-            $this->debug("Got $http_status $http_reason with Location: " . $this->incoming_headers['location']);
3282
-            $this->setURL($this->incoming_headers['location']);
3283
-            $this->tryagain = true;
3284
-            return false;
3285
-        }
3286
-
3287
-        // see if we need to resend the request with http digest authentication
3288
-        if (isset($this->incoming_headers['www-authenticate']) && 401 == $http_status) {
3289
-            $this->debug("Got 401 $http_reason with WWW-Authenticate: " . $this->incoming_headers['www-authenticate']);
3290
-            if (false !== strpos($this->incoming_headers['www-authenticate'], 'Digest ')) {
3291
-                $this->debug('Server wants digest authentication');
3292
-                // remove "Digest " from our elements
3293
-                $digestString = str_replace('Digest ', '', $this->incoming_headers['www-authenticate']);
3294
-
3295
-                // parse elements into array
3296
-                $digestElements = explode(',', $digestString);
3297
-                foreach ($digestElements as $val) {
3298
-                    $tempElement = explode('=', trim($val), 2);
3299
-                    $digestRequest[$tempElement[0]] = str_replace('"', '', $tempElement[1]);
3300
-                }
3186
+		} elseif ('curl' === $this->io_method()) {
3187
+			// send and receive
3188
+			$this->debug('send and receive with cURL');
3189
+			$this->incoming_payload = curl_exec($this->ch);
3190
+			$data = $this->incoming_payload;
3191
+
3192
+			$cErr = curl_error($this->ch);
3193
+			if ('' != $cErr) {
3194
+				$err = 'cURL ERROR: ' . curl_errno($this->ch) . ': ' . $cErr . '<br>';
3195
+				// TODO: there is a PHP bug that can cause this to SEGV for CURLINFO_CONTENT_TYPE
3196
+				foreach (curl_getinfo($this->ch) as $k => $v) {
3197
+					$err .= "$k: $v<br>";
3198
+				}
3199
+				$this->debug($err);
3200
+				$this->setError($err);
3201
+				curl_close($this->ch);
3202
+				return false;
3203
+			} else {
3204
+				//echo '<pre>';
3205
+				//var_dump(curl_getinfo($this->ch));
3206
+				//echo '</pre>';
3207
+			}
3208
+			// close curl
3209
+			$this->debug('No cURL error, closing cURL');
3210
+			curl_close($this->ch);
3211
+
3212
+			// try removing skippable headers
3213
+			$savedata = $data;
3214
+			while ($this->isSkippableCurlHeader($data)) {
3215
+				$this->debug('Found HTTP header to skip');
3216
+				if (false !== ($pos = strpos($data, "\r\n\r\n"))) {
3217
+					$data = ltrim(substr($data, $pos));
3218
+				} elseif (false !== ($pos = strpos($data, "\n\n"))) {
3219
+					$data = ltrim(substr($data, $pos));
3220
+				}
3221
+			}
3222
+
3223
+			if ('' == $data) {
3224
+				// have nothing left; just remove 100 header(s)
3225
+				$data = $savedata;
3226
+				while (preg_match('/^HTTP\/1.1 100/', $data)) {
3227
+					if (false !== ($pos = strpos($data, "\r\n\r\n"))) {
3228
+						$data = ltrim(substr($data, $pos));
3229
+					} elseif (false !== ($pos = strpos($data, "\n\n"))) {
3230
+						$data = ltrim(substr($data, $pos));
3231
+					}
3232
+				}
3233
+			}
3234
+
3235
+			// separate content from HTTP headers
3236
+			if (false !== ($pos = strpos($data, "\r\n\r\n"))) {
3237
+				$lb = "\r\n";
3238
+			} elseif (false !== ($pos = strpos($data, "\n\n"))) {
3239
+				$lb = "\n";
3240
+			} else {
3241
+				$this->debug('no proper separation of headers and document');
3242
+				$this->setError('no proper separation of headers and document');
3243
+				return false;
3244
+			}
3245
+			$header_data = trim(substr($data, 0, $pos));
3246
+			$header_array = explode($lb, $header_data);
3247
+			$data = ltrim(substr($data, $pos));
3248
+			$this->debug('found proper separation of headers and document');
3249
+			$this->debug('cleaned data, stringlen: ' . strlen($data));
3250
+			// clean headers
3251
+			foreach ($header_array as $header_line) {
3252
+				$arr = explode(':', $header_line, 2);
3253
+				if (is_array($arr) && count($arr) > 1) {
3254
+					$header_name = strtolower(trim($arr[0]));
3255
+					$this->incoming_headers[$header_name] = trim($arr[1]);
3256
+					if ('set-cookie' === $header_name) {
3257
+						// TODO: allow multiple cookies from parseCookie
3258
+						$cookie = $this->parseCookie(trim($arr[1]));
3259
+						if ($cookie) {
3260
+							$this->incoming_cookies[] = $cookie;
3261
+							$this->debug('found cookie: ' . $cookie['name'] . ' = ' . $cookie['value']);
3262
+						} else {
3263
+							$this->debug('did not find cookie in ' . trim($arr[1]));
3264
+						}
3265
+					}
3266
+				} elseif (isset($header_name)) {
3267
+					// append continuation line to previous header
3268
+					$this->incoming_headers[$header_name] .= $lb . ' ' . $header_line;
3269
+				}
3270
+			}
3271
+		}
3301 3272
 
3302
-                // should have (at least) qop, realm, nonce
3303
-                if (isset($digestRequest['nonce'])) {
3304
-                    $this->setCredentials($this->username, $this->password, 'digest', $digestRequest);
3305
-                    $this->tryagain = true;
3306
-                    return false;
3307
-                }
3308
-            }
3309
-            $this->debug('HTTP authentication failed');
3310
-            $this->setError('HTTP authentication failed');
3311
-            return false;
3312
-        }
3313
-
3314
-        if (
3315
-            ($http_status >= 300 && $http_status <= 307) ||
3316
-            ($http_status >= 400 && $http_status <= 417) ||
3317
-            ($http_status >= 501 && $http_status <= 505)
3318
-        ) {
3319
-            $this->setError("Unsupported HTTP response status $http_status $http_reason (soapclient->response has contents of the response)");
3320
-            return false;
3321
-        }
3322
-
3323
-        // decode content-encoding
3324
-        if (isset($this->incoming_headers['content-encoding']) && '' != $this->incoming_headers['content-encoding']) {
3325
-            if ('deflate' === strtolower($this->incoming_headers['content-encoding']) || 'gzip' === strtolower($this->incoming_headers['content-encoding'])) {
3326
-                // if decoding works, use it. else assume data wasn't gzencoded
3327
-                if (function_exists('gzinflate')) {
3328
-                    //$timer->setMarker('starting decoding of gzip/deflated content');
3329
-                    // IIS 5 requires gzinflate instead of gzuncompress (similar to IE 5 and gzdeflate v. gzcompress)
3330
-                    // this means there are no Zlib headers, although there should be
3331
-                    $this->debug('The gzinflate function exists');
3332
-                    $datalen = strlen($data);
3333
-                    if ('deflate' === $this->incoming_headers['content-encoding']) {
3334
-                        if (false !== ($degzdata = @gzinflate($data))) {
3335
-                            $data = $degzdata;
3336
-                            $this->debug('The payload has been inflated to ' . strlen($data) . ' bytes');
3337
-                            if (strlen($data) < $datalen) {
3338
-                                // test for the case that the payload has been compressed twice
3339
-                                $this->debug('The inflated payload is smaller than the gzipped one; try again');
3340
-                                if (false !== ($degzdata = @gzinflate($data))) {
3341
-                                    $data = $degzdata;
3342
-                                    $this->debug('The payload has been inflated again to ' . strlen($data) . ' bytes');
3343
-                                }
3344
-                            }
3345
-                        } else {
3346
-                            $this->debug('Error using gzinflate to inflate the payload');
3347
-                            $this->setError('Error using gzinflate to inflate the payload');
3348
-                        }
3349
-                    } elseif ('gzip' === $this->incoming_headers['content-encoding']) {
3350
-                        if (false !== ($degzdata = @gzinflate(substr($data, 10)))) {    // do our best
3351
-                            $data = $degzdata;
3352
-                            $this->debug('The payload has been un-gzipped to ' . strlen($data) . ' bytes');
3353
-                            if (strlen($data) < $datalen) {
3354
-                                // test for the case that the payload has been compressed twice
3355
-                                $this->debug('The un-gzipped payload is smaller than the gzipped one; try again');
3356
-                                if (false !== ($degzdata = @gzinflate(substr($data, 10)))) {
3357
-                                    $data = $degzdata;
3358
-                                    $this->debug('The payload has been un-gzipped again to ' . strlen($data) . ' bytes');
3359
-                                }
3360
-                            }
3361
-                        } else {
3362
-                            $this->debug('Error using gzinflate to un-gzip the payload');
3363
-                            $this->setError('Error using gzinflate to un-gzip the payload');
3364
-                        }
3365
-                    }
3366
-                    //$timer->setMarker('finished decoding of gzip/deflated content');
3367
-                    //print "<xmp>\nde-inflated:\n---------------\n$data\n-------------\n</xmp>";
3368
-                    // set decoded payload
3369
-                    $this->incoming_payload = $header_data . $lb . $lb . $data;
3370
-                } else {
3371
-                    $this->debug('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.');
3372
-                    $this->setError('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.');
3373
-                }
3374
-            } else {
3375
-                $this->debug('Unsupported Content-Encoding ' . $this->incoming_headers['content-encoding']);
3376
-                $this->setError('Unsupported Content-Encoding ' . $this->incoming_headers['content-encoding']);
3377
-            }
3378
-        } else {
3379
-            $this->debug('No Content-Encoding header');
3380
-        }
3381
-
3382
-        if (0 == strlen($data)) {
3383
-            $this->debug('no data after headers!');
3384
-            $this->setError('no data present after HTTP headers');
3385
-            return false;
3386
-        }
3387
-
3388
-        return $data;
3389
-    }
3390
-
3391
-    /**
3392
-     * sets the content-type for the SOAP message to be sent
3393
-     *
3394
-     * @param    string $type the content type, MIME style
3395
-     * @param    mixed $charset character set used for encoding (or false)
3396
-     * @access    public
3397
-     */
3398
-    public function setContentType($type, $charset = false)
3399
-    {
3400
-        $this->setHeader('Content-Type', $type . ($charset ? '; charset=' . $charset : ''));
3401
-    }
3402
-
3403
-    /**
3404
-     * specifies that an HTTP persistent connection should be used
3405
-     *
3406
-     * @return    boolean whether the request was honored by this method.
3407
-     * @access    public
3408
-     */
3409
-    public function usePersistentConnection()
3410
-    {
3411
-        if (isset($this->outgoing_headers['Accept-Encoding'])) {
3412
-            return false;
3413
-        }
3414
-        $this->protocol_version = '1.1';
3415
-        $this->persistentConnection = true;
3416
-        $this->setHeader('Connection', 'Keep-Alive');
3417
-        return true;
3418
-    }
3419
-
3420
-    /**
3421
-     * parse an incoming Cookie into it's parts
3422
-     *
3423
-     * @param    string $cookie_str content of cookie
3424
-     * @return    bool|array with data of that cookie
3425
-     * @access    private
3426
-     */
3427
-    /*
3273
+		$this->response_status_line = $header_array[0];
3274
+		$arr = explode(' ', $this->response_status_line, 3);
3275
+		$http_version = $arr[0];
3276
+		$http_status = (int)$arr[1];
3277
+		$http_reason = count($arr) > 2 ? $arr[2] : '';
3278
+
3279
+		// see if we need to resend the request with http digest authentication
3280
+		if (isset($this->incoming_headers['location']) && (301 == $http_status || 302 == $http_status)) {
3281
+			$this->debug("Got $http_status $http_reason with Location: " . $this->incoming_headers['location']);
3282
+			$this->setURL($this->incoming_headers['location']);
3283
+			$this->tryagain = true;
3284
+			return false;
3285
+		}
3286
+
3287
+		// see if we need to resend the request with http digest authentication
3288
+		if (isset($this->incoming_headers['www-authenticate']) && 401 == $http_status) {
3289
+			$this->debug("Got 401 $http_reason with WWW-Authenticate: " . $this->incoming_headers['www-authenticate']);
3290
+			if (false !== strpos($this->incoming_headers['www-authenticate'], 'Digest ')) {
3291
+				$this->debug('Server wants digest authentication');
3292
+				// remove "Digest " from our elements
3293
+				$digestString = str_replace('Digest ', '', $this->incoming_headers['www-authenticate']);
3294
+
3295
+				// parse elements into array
3296
+				$digestElements = explode(',', $digestString);
3297
+				foreach ($digestElements as $val) {
3298
+					$tempElement = explode('=', trim($val), 2);
3299
+					$digestRequest[$tempElement[0]] = str_replace('"', '', $tempElement[1]);
3300
+				}
3301
+
3302
+				// should have (at least) qop, realm, nonce
3303
+				if (isset($digestRequest['nonce'])) {
3304
+					$this->setCredentials($this->username, $this->password, 'digest', $digestRequest);
3305
+					$this->tryagain = true;
3306
+					return false;
3307
+				}
3308
+			}
3309
+			$this->debug('HTTP authentication failed');
3310
+			$this->setError('HTTP authentication failed');
3311
+			return false;
3312
+		}
3313
+
3314
+		if (
3315
+			($http_status >= 300 && $http_status <= 307) ||
3316
+			($http_status >= 400 && $http_status <= 417) ||
3317
+			($http_status >= 501 && $http_status <= 505)
3318
+		) {
3319
+			$this->setError("Unsupported HTTP response status $http_status $http_reason (soapclient->response has contents of the response)");
3320
+			return false;
3321
+		}
3322
+
3323
+		// decode content-encoding
3324
+		if (isset($this->incoming_headers['content-encoding']) && '' != $this->incoming_headers['content-encoding']) {
3325
+			if ('deflate' === strtolower($this->incoming_headers['content-encoding']) || 'gzip' === strtolower($this->incoming_headers['content-encoding'])) {
3326
+				// if decoding works, use it. else assume data wasn't gzencoded
3327
+				if (function_exists('gzinflate')) {
3328
+					//$timer->setMarker('starting decoding of gzip/deflated content');
3329
+					// IIS 5 requires gzinflate instead of gzuncompress (similar to IE 5 and gzdeflate v. gzcompress)
3330
+					// this means there are no Zlib headers, although there should be
3331
+					$this->debug('The gzinflate function exists');
3332
+					$datalen = strlen($data);
3333
+					if ('deflate' === $this->incoming_headers['content-encoding']) {
3334
+						if (false !== ($degzdata = @gzinflate($data))) {
3335
+							$data = $degzdata;
3336
+							$this->debug('The payload has been inflated to ' . strlen($data) . ' bytes');
3337
+							if (strlen($data) < $datalen) {
3338
+								// test for the case that the payload has been compressed twice
3339
+								$this->debug('The inflated payload is smaller than the gzipped one; try again');
3340
+								if (false !== ($degzdata = @gzinflate($data))) {
3341
+									$data = $degzdata;
3342
+									$this->debug('The payload has been inflated again to ' . strlen($data) . ' bytes');
3343
+								}
3344
+							}
3345
+						} else {
3346
+							$this->debug('Error using gzinflate to inflate the payload');
3347
+							$this->setError('Error using gzinflate to inflate the payload');
3348
+						}
3349
+					} elseif ('gzip' === $this->incoming_headers['content-encoding']) {
3350
+						if (false !== ($degzdata = @gzinflate(substr($data, 10)))) {    // do our best
3351
+							$data = $degzdata;
3352
+							$this->debug('The payload has been un-gzipped to ' . strlen($data) . ' bytes');
3353
+							if (strlen($data) < $datalen) {
3354
+								// test for the case that the payload has been compressed twice
3355
+								$this->debug('The un-gzipped payload is smaller than the gzipped one; try again');
3356
+								if (false !== ($degzdata = @gzinflate(substr($data, 10)))) {
3357
+									$data = $degzdata;
3358
+									$this->debug('The payload has been un-gzipped again to ' . strlen($data) . ' bytes');
3359
+								}
3360
+							}
3361
+						} else {
3362
+							$this->debug('Error using gzinflate to un-gzip the payload');
3363
+							$this->setError('Error using gzinflate to un-gzip the payload');
3364
+						}
3365
+					}
3366
+					//$timer->setMarker('finished decoding of gzip/deflated content');
3367
+					//print "<xmp>\nde-inflated:\n---------------\n$data\n-------------\n</xmp>";
3368
+					// set decoded payload
3369
+					$this->incoming_payload = $header_data . $lb . $lb . $data;
3370
+				} else {
3371
+					$this->debug('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.');
3372
+					$this->setError('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.');
3373
+				}
3374
+			} else {
3375
+				$this->debug('Unsupported Content-Encoding ' . $this->incoming_headers['content-encoding']);
3376
+				$this->setError('Unsupported Content-Encoding ' . $this->incoming_headers['content-encoding']);
3377
+			}
3378
+		} else {
3379
+			$this->debug('No Content-Encoding header');
3380
+		}
3381
+
3382
+		if (0 == strlen($data)) {
3383
+			$this->debug('no data after headers!');
3384
+			$this->setError('no data present after HTTP headers');
3385
+			return false;
3386
+		}
3387
+
3388
+		return $data;
3389
+	}
3390
+
3391
+	/**
3392
+	 * sets the content-type for the SOAP message to be sent
3393
+	 *
3394
+	 * @param    string $type the content type, MIME style
3395
+	 * @param    mixed $charset character set used for encoding (or false)
3396
+	 * @access    public
3397
+	 */
3398
+	public function setContentType($type, $charset = false)
3399
+	{
3400
+		$this->setHeader('Content-Type', $type . ($charset ? '; charset=' . $charset : ''));
3401
+	}
3402
+
3403
+	/**
3404
+	 * specifies that an HTTP persistent connection should be used
3405
+	 *
3406
+	 * @return    boolean whether the request was honored by this method.
3407
+	 * @access    public
3408
+	 */
3409
+	public function usePersistentConnection()
3410
+	{
3411
+		if (isset($this->outgoing_headers['Accept-Encoding'])) {
3412
+			return false;
3413
+		}
3414
+		$this->protocol_version = '1.1';
3415
+		$this->persistentConnection = true;
3416
+		$this->setHeader('Connection', 'Keep-Alive');
3417
+		return true;
3418
+	}
3419
+
3420
+	/**
3421
+	 * parse an incoming Cookie into it's parts
3422
+	 *
3423
+	 * @param    string $cookie_str content of cookie
3424
+	 * @return    bool|array with data of that cookie
3425
+	 * @access    private
3426
+	 */
3427
+	/*
3428 3428
      * TODO: allow a Set-Cookie string to be parsed into multiple cookies
3429 3429
      */
3430
-    private function parseCookie($cookie_str)
3431
-    {
3432
-        $cookie_str = str_replace('; ', ';', $cookie_str) . ';';
3433
-        $data = preg_split('/;/', $cookie_str);
3434
-        $value_str = $data[0];
3435
-
3436
-        $cookie_param = 'domain=';
3437
-        $start = strpos($cookie_str, $cookie_param);
3438
-        if ($start > 0) {
3439
-            $domain = substr($cookie_str, $start + strlen($cookie_param));
3440
-            $domain = substr($domain, 0, strpos($domain, ';'));
3441
-        } else {
3442
-            $domain = '';
3443
-        }
3444
-
3445
-        $cookie_param = 'expires=';
3446
-        $start = strpos($cookie_str, $cookie_param);
3447
-        if ($start > 0) {
3448
-            $expires = substr($cookie_str, $start + strlen($cookie_param));
3449
-            $expires = substr($expires, 0, strpos($expires, ';'));
3450
-        } else {
3451
-            $expires = '';
3452
-        }
3453
-
3454
-        $cookie_param = 'path=';
3455
-        $start = strpos($cookie_str, $cookie_param);
3456
-        if ($start > 0) {
3457
-            $path = substr($cookie_str, $start + strlen($cookie_param));
3458
-            $path = substr($path, 0, strpos($path, ';'));
3459
-        } else {
3460
-            $path = '/';
3461
-        }
3462
-
3463
-        $cookie_param = ';secure;';
3464
-        if (false !== strpos($cookie_str, $cookie_param)) {
3465
-            $secure = true;
3466
-        } else {
3467
-            $secure = false;
3468
-        }
3469
-
3470
-        $sep_pos = strpos($value_str, '=');
3471
-
3472
-        if ($sep_pos) {
3473
-            $name = substr($value_str, 0, $sep_pos);
3474
-            $value = substr($value_str, $sep_pos + 1);
3475
-            $cookie = [
3476
-                'name'    => $name,
3477
-                'value'   => $value,
3478
-                'domain'  => $domain,
3479
-                'path'    => $path,
3480
-                'expires' => $expires,
3481
-                'secure'  => $secure
3482
-            ];
3483
-            return $cookie;
3484
-        }
3485
-        return false;
3486
-    }
3487
-
3488
-    /**
3489
-     * sort out cookies for the current request
3490
-     *
3491
-     * @param    array|null $cookies array with all cookies
3492
-     * @param    boolean $secure is the send-content secure or not?
3493
-     * @return    string for Cookie-HTTP-Header
3494
-     * @access    private
3495
-     */
3496
-    private function getCookiesForRequest($cookies, $secure = false)
3497
-    {
3498
-        $cookie_str = '';
3499
-        if ((null !== $cookies) && (is_array($cookies))) {
3500
-            foreach ($cookies as $cookie) {
3501
-                if (!is_array($cookie)) {
3502
-                    continue;
3503
-                }
3504
-                $this->debug('check cookie for validity: ' . $cookie['name'] . '=' . $cookie['value']);
3505
-                if ((isset($cookie['expires'])) && (!empty($cookie['expires']))) {
3506
-                    if (strtotime($cookie['expires']) <= time()) {
3507
-                        $this->debug('cookie has expired');
3508
-                        continue;
3509
-                    }
3510
-                }
3511
-                if ((isset($cookie['domain'])) && (!empty($cookie['domain']))) {
3512
-                    $domain = preg_quote($cookie['domain']);
3513
-                    if (!preg_match("'.*$domain$'i", $this->host)) {
3514
-                        $this->debug('cookie has different domain');
3515
-                        continue;
3516
-                    }
3517
-                }
3518
-                if ((isset($cookie['path'])) && (!empty($cookie['path']))) {
3519
-                    $path = preg_quote($cookie['path']);
3520
-                    if (!preg_match("'^$path.*'i", $this->path)) {
3521
-                        $this->debug('cookie is for a different path');
3522
-                        continue;
3523
-                    }
3524
-                }
3525
-                if ((!$secure) && (isset($cookie['secure'])) && ($cookie['secure'])) {
3526
-                    $this->debug('cookie is secure, transport is not');
3527
-                    continue;
3528
-                }
3529
-                $cookie_str .= $cookie['name'] . '=' . $cookie['value'] . '; ';
3530
-                $this->debug('add cookie to Cookie-String: ' . $cookie['name'] . '=' . $cookie['value']);
3531
-            }
3532
-        }
3533
-        return $cookie_str;
3534
-    }
3430
+	private function parseCookie($cookie_str)
3431
+	{
3432
+		$cookie_str = str_replace('; ', ';', $cookie_str) . ';';
3433
+		$data = preg_split('/;/', $cookie_str);
3434
+		$value_str = $data[0];
3435
+
3436
+		$cookie_param = 'domain=';
3437
+		$start = strpos($cookie_str, $cookie_param);
3438
+		if ($start > 0) {
3439
+			$domain = substr($cookie_str, $start + strlen($cookie_param));
3440
+			$domain = substr($domain, 0, strpos($domain, ';'));
3441
+		} else {
3442
+			$domain = '';
3443
+		}
3444
+
3445
+		$cookie_param = 'expires=';
3446
+		$start = strpos($cookie_str, $cookie_param);
3447
+		if ($start > 0) {
3448
+			$expires = substr($cookie_str, $start + strlen($cookie_param));
3449
+			$expires = substr($expires, 0, strpos($expires, ';'));
3450
+		} else {
3451
+			$expires = '';
3452
+		}
3453
+
3454
+		$cookie_param = 'path=';
3455
+		$start = strpos($cookie_str, $cookie_param);
3456
+		if ($start > 0) {
3457
+			$path = substr($cookie_str, $start + strlen($cookie_param));
3458
+			$path = substr($path, 0, strpos($path, ';'));
3459
+		} else {
3460
+			$path = '/';
3461
+		}
3462
+
3463
+		$cookie_param = ';secure;';
3464
+		if (false !== strpos($cookie_str, $cookie_param)) {
3465
+			$secure = true;
3466
+		} else {
3467
+			$secure = false;
3468
+		}
3469
+
3470
+		$sep_pos = strpos($value_str, '=');
3471
+
3472
+		if ($sep_pos) {
3473
+			$name = substr($value_str, 0, $sep_pos);
3474
+			$value = substr($value_str, $sep_pos + 1);
3475
+			$cookie = [
3476
+				'name'    => $name,
3477
+				'value'   => $value,
3478
+				'domain'  => $domain,
3479
+				'path'    => $path,
3480
+				'expires' => $expires,
3481
+				'secure'  => $secure
3482
+			];
3483
+			return $cookie;
3484
+		}
3485
+		return false;
3486
+	}
3487
+
3488
+	/**
3489
+	 * sort out cookies for the current request
3490
+	 *
3491
+	 * @param    array|null $cookies array with all cookies
3492
+	 * @param    boolean $secure is the send-content secure or not?
3493
+	 * @return    string for Cookie-HTTP-Header
3494
+	 * @access    private
3495
+	 */
3496
+	private function getCookiesForRequest($cookies, $secure = false)
3497
+	{
3498
+		$cookie_str = '';
3499
+		if ((null !== $cookies) && (is_array($cookies))) {
3500
+			foreach ($cookies as $cookie) {
3501
+				if (!is_array($cookie)) {
3502
+					continue;
3503
+				}
3504
+				$this->debug('check cookie for validity: ' . $cookie['name'] . '=' . $cookie['value']);
3505
+				if ((isset($cookie['expires'])) && (!empty($cookie['expires']))) {
3506
+					if (strtotime($cookie['expires']) <= time()) {
3507
+						$this->debug('cookie has expired');
3508
+						continue;
3509
+					}
3510
+				}
3511
+				if ((isset($cookie['domain'])) && (!empty($cookie['domain']))) {
3512
+					$domain = preg_quote($cookie['domain']);
3513
+					if (!preg_match("'.*$domain$'i", $this->host)) {
3514
+						$this->debug('cookie has different domain');
3515
+						continue;
3516
+					}
3517
+				}
3518
+				if ((isset($cookie['path'])) && (!empty($cookie['path']))) {
3519
+					$path = preg_quote($cookie['path']);
3520
+					if (!preg_match("'^$path.*'i", $this->path)) {
3521
+						$this->debug('cookie is for a different path');
3522
+						continue;
3523
+					}
3524
+				}
3525
+				if ((!$secure) && (isset($cookie['secure'])) && ($cookie['secure'])) {
3526
+					$this->debug('cookie is secure, transport is not');
3527
+					continue;
3528
+				}
3529
+				$cookie_str .= $cookie['name'] . '=' . $cookie['value'] . '; ';
3530
+				$this->debug('add cookie to Cookie-String: ' . $cookie['name'] . '=' . $cookie['value']);
3531
+			}
3532
+		}
3533
+		return $cookie_str;
3534
+	}
3535 3535
 }
3536 3536
 
3537 3537
 
@@ -3547,1156 +3547,1156 @@  discard block
 block discarded – undo
3547 3547
  */
3548 3548
 class nusoap_server extends nusoap_base
3549 3549
 {
3550
-    /**
3551
-     * HTTP headers of request
3552
-     *
3553
-     * @var array
3554
-     * @access private
3555
-     */
3556
-    private $headers = [];
3557
-    /**
3558
-     * HTTP request
3559
-     *
3560
-     * @var string
3561
-     * @access private
3562
-     */
3563
-    private $request = '';
3564
-    /**
3565
-     * SOAP headers from request (incomplete namespace resolution; special characters not escaped) (text)
3566
-     *
3567
-     * @var string
3568
-     * @access public
3569
-     */
3570
-    public $requestHeaders = '';
3571
-    /**
3572
-     * SOAP Headers from request (parsed)
3573
-     *
3574
-     * @var mixed
3575
-     * @access public
3576
-     */
3577
-    public $requestHeader;
3578
-    /**
3579
-     * SOAP body request portion (incomplete namespace resolution; special characters not escaped) (text)
3580
-     *
3581
-     * @var string
3582
-     * @access public
3583
-     */
3584
-    public $document = '';
3585
-    /**
3586
-     * SOAP payload for request (text)
3587
-     *
3588
-     * @var string
3589
-     * @access public
3590
-     */
3591
-    public $requestSOAP = '';
3592
-    /**
3593
-     * requested method namespace URI
3594
-     *
3595
-     * @var string
3596
-     * @access private
3597
-     */
3598
-    private $methodURI = '';
3599
-    /**
3600
-     * name of method requested
3601
-     *
3602
-     * @var string
3603
-     * @access private
3604
-     */
3605
-    private $methodname = '';
3606
-    /**
3607
-     * method parameters from request
3608
-     *
3609
-     * @var array
3610
-     * @access private
3611
-     */
3612
-    private $methodparams = [];
3613
-    /**
3614
-     * SOAP Action from request
3615
-     *
3616
-     * @var string
3617
-     * @access private
3618
-     */
3619
-    private $SOAPAction = '';
3620
-    /**
3621
-     * character set encoding of incoming (request) messages
3622
-     *
3623
-     * @var string
3624
-     * @access public
3625
-     */
3626
-    public $xml_encoding = '';
3627
-    /**
3628
-     * toggles whether the parser decodes element content w/ utf8_decode()
3629
-     *
3630
-     * @var boolean
3631
-     * @access public
3632
-     */
3633
-    public $decode_utf8 = true;
3550
+	/**
3551
+	 * HTTP headers of request
3552
+	 *
3553
+	 * @var array
3554
+	 * @access private
3555
+	 */
3556
+	private $headers = [];
3557
+	/**
3558
+	 * HTTP request
3559
+	 *
3560
+	 * @var string
3561
+	 * @access private
3562
+	 */
3563
+	private $request = '';
3564
+	/**
3565
+	 * SOAP headers from request (incomplete namespace resolution; special characters not escaped) (text)
3566
+	 *
3567
+	 * @var string
3568
+	 * @access public
3569
+	 */
3570
+	public $requestHeaders = '';
3571
+	/**
3572
+	 * SOAP Headers from request (parsed)
3573
+	 *
3574
+	 * @var mixed
3575
+	 * @access public
3576
+	 */
3577
+	public $requestHeader;
3578
+	/**
3579
+	 * SOAP body request portion (incomplete namespace resolution; special characters not escaped) (text)
3580
+	 *
3581
+	 * @var string
3582
+	 * @access public
3583
+	 */
3584
+	public $document = '';
3585
+	/**
3586
+	 * SOAP payload for request (text)
3587
+	 *
3588
+	 * @var string
3589
+	 * @access public
3590
+	 */
3591
+	public $requestSOAP = '';
3592
+	/**
3593
+	 * requested method namespace URI
3594
+	 *
3595
+	 * @var string
3596
+	 * @access private
3597
+	 */
3598
+	private $methodURI = '';
3599
+	/**
3600
+	 * name of method requested
3601
+	 *
3602
+	 * @var string
3603
+	 * @access private
3604
+	 */
3605
+	private $methodname = '';
3606
+	/**
3607
+	 * method parameters from request
3608
+	 *
3609
+	 * @var array
3610
+	 * @access private
3611
+	 */
3612
+	private $methodparams = [];
3613
+	/**
3614
+	 * SOAP Action from request
3615
+	 *
3616
+	 * @var string
3617
+	 * @access private
3618
+	 */
3619
+	private $SOAPAction = '';
3620
+	/**
3621
+	 * character set encoding of incoming (request) messages
3622
+	 *
3623
+	 * @var string
3624
+	 * @access public
3625
+	 */
3626
+	public $xml_encoding = '';
3627
+	/**
3628
+	 * toggles whether the parser decodes element content w/ utf8_decode()
3629
+	 *
3630
+	 * @var boolean
3631
+	 * @access public
3632
+	 */
3633
+	public $decode_utf8 = true;
3634
+
3635
+	/**
3636
+	 * HTTP headers of response
3637
+	 *
3638
+	 * @var array
3639
+	 * @access public
3640
+	 */
3641
+	public $outgoing_headers = [];
3642
+	/**
3643
+	 * HTTP response
3644
+	 *
3645
+	 * @var string
3646
+	 * @access private
3647
+	 */
3648
+	private $response = '';
3649
+	/**
3650
+	 * SOAP headers for response (text or array of soapval or associative array)
3651
+	 *
3652
+	 * @var mixed
3653
+	 * @access public
3654
+	 */
3655
+	public $responseHeaders = '';
3656
+	/**
3657
+	 * SOAP payload for response (text)
3658
+	 *
3659
+	 * @var string
3660
+	 * @access private
3661
+	 */
3662
+	private $responseSOAP = '';
3663
+	/**
3664
+	 * method return value to place in response
3665
+	 *
3666
+	 * @var mixed
3667
+	 * @access private
3668
+	 */
3669
+	private $methodreturn = false;
3670
+	/**
3671
+	 * whether $methodreturn is a string of literal XML
3672
+	 *
3673
+	 * @var boolean
3674
+	 * @access public
3675
+	 */
3676
+	public $methodreturnisliteralxml = false;
3677
+	/**
3678
+	 * SOAP fault for response (or false)
3679
+	 *
3680
+	 * @var mixed
3681
+	 * @access private
3682
+	 */
3683
+	private $fault = false;
3684
+	/**
3685
+	 * text indication of result (for debugging)
3686
+	 *
3687
+	 * @var string
3688
+	 * @access private
3689
+	 */
3690
+	private $result = 'successful';
3691
+
3692
+	/**
3693
+	 * assoc array of operations => opData; operations are added by the register()
3694
+	 * method or by parsing an external WSDL definition
3695
+	 *
3696
+	 * @var array
3697
+	 * @access private
3698
+	 */
3699
+	private $operations = [];
3700
+	/**
3701
+	 * wsdl instance (if one)
3702
+	 *
3703
+	 * @var mixed
3704
+	 * @access private
3705
+	 */
3706
+	private $wsdl = false;
3707
+	/**
3708
+	 * URL for WSDL (if one)
3709
+	 *
3710
+	 * @var mixed
3711
+	 * @access private
3712
+	 */
3713
+	private $externalWSDLURL = false;
3714
+	/**
3715
+	 * whether to append debug to response as XML comment
3716
+	 *
3717
+	 * @var boolean
3718
+	 * @access public
3719
+	 */
3720
+	public $debug_flag = false;
3721
+
3722
+
3723
+	/**
3724
+	 * constructor
3725
+	 * the optional parameter is a path to a WSDL file that you'd like to bind the server instance to.
3726
+	 *
3727
+	 * @param mixed $wsdl file path or URL (string), or wsdl instance (object)
3728
+	 * @access   public
3729
+	 */
3730
+	public function __construct($wsdl = false)
3731
+	{
3732
+		parent::__construct();
3733
+		// turn on debugging?
3734
+		global $debug;
3735
+		global $HTTP_SERVER_VARS;
3736
+
3737
+		if (isset($_SERVER)) {
3738
+			$this->debug('_SERVER is defined:');
3739
+			$this->appendDebug($this->varDump($_SERVER));
3740
+		} elseif (isset($HTTP_SERVER_VARS)) {
3741
+			$this->debug('HTTP_SERVER_VARS is defined:');
3742
+			$this->appendDebug($this->varDump($HTTP_SERVER_VARS));
3743
+		} else {
3744
+			$this->debug('Neither _SERVER nor HTTP_SERVER_VARS is defined.');
3745
+		}
3634 3746
 
3635
-    /**
3636
-     * HTTP headers of response
3637
-     *
3638
-     * @var array
3639
-     * @access public
3640
-     */
3641
-    public $outgoing_headers = [];
3642
-    /**
3643
-     * HTTP response
3644
-     *
3645
-     * @var string
3646
-     * @access private
3647
-     */
3648
-    private $response = '';
3649
-    /**
3650
-     * SOAP headers for response (text or array of soapval or associative array)
3651
-     *
3652
-     * @var mixed
3653
-     * @access public
3654
-     */
3655
-    public $responseHeaders = '';
3656
-    /**
3657
-     * SOAP payload for response (text)
3658
-     *
3659
-     * @var string
3660
-     * @access private
3661
-     */
3662
-    private $responseSOAP = '';
3663
-    /**
3664
-     * method return value to place in response
3665
-     *
3666
-     * @var mixed
3667
-     * @access private
3668
-     */
3669
-    private $methodreturn = false;
3670
-    /**
3671
-     * whether $methodreturn is a string of literal XML
3672
-     *
3673
-     * @var boolean
3674
-     * @access public
3675
-     */
3676
-    public $methodreturnisliteralxml = false;
3677
-    /**
3678
-     * SOAP fault for response (or false)
3679
-     *
3680
-     * @var mixed
3681
-     * @access private
3682
-     */
3683
-    private $fault = false;
3684
-    /**
3685
-     * text indication of result (for debugging)
3686
-     *
3687
-     * @var string
3688
-     * @access private
3689
-     */
3690
-    private $result = 'successful';
3691
-
3692
-    /**
3693
-     * assoc array of operations => opData; operations are added by the register()
3694
-     * method or by parsing an external WSDL definition
3695
-     *
3696
-     * @var array
3697
-     * @access private
3698
-     */
3699
-    private $operations = [];
3700
-    /**
3701
-     * wsdl instance (if one)
3702
-     *
3703
-     * @var mixed
3704
-     * @access private
3705
-     */
3706
-    private $wsdl = false;
3707
-    /**
3708
-     * URL for WSDL (if one)
3709
-     *
3710
-     * @var mixed
3711
-     * @access private
3712
-     */
3713
-    private $externalWSDLURL = false;
3714
-    /**
3715
-     * whether to append debug to response as XML comment
3716
-     *
3717
-     * @var boolean
3718
-     * @access public
3719
-     */
3720
-    public $debug_flag = false;
3747
+		if (isset($debug)) {
3748
+			$this->debug("In nusoap_server, set debug_flag=$debug based on global flag");
3749
+			$this->debug_flag = $debug;
3750
+		} elseif (isset($_SERVER['QUERY_STRING'])) {
3751
+			$qs = explode('&', $_SERVER['QUERY_STRING']);
3752
+			foreach ($qs as $v) {
3753
+				if (0 === strpos($v, 'debug=')) {
3754
+					$this->debug('In nusoap_server, set debug_flag=' . substr($v, 6) . ' based on query string #1');
3755
+					$this->debug_flag = substr($v, 6);
3756
+				}
3757
+			}
3758
+		} elseif (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
3759
+			$qs = explode('&', $HTTP_SERVER_VARS['QUERY_STRING']);
3760
+			foreach ($qs as $v) {
3761
+				if (0 === strpos($v, 'debug=')) {
3762
+					$this->debug('In nusoap_server, set debug_flag=' . substr($v, 6) . ' based on query string #2');
3763
+					$this->debug_flag = substr($v, 6);
3764
+				}
3765
+			}
3766
+		}
3721 3767
 
3768
+		// wsdl
3769
+		if ($wsdl) {
3770
+			$this->debug('In nusoap_server, WSDL is specified');
3771
+			if (is_object($wsdl) && ('wsdl' === get_class($wsdl))) {
3772
+				$this->wsdl = $wsdl;
3773
+				$this->externalWSDLURL = $this->wsdl->wsdl;
3774
+				$this->debug('Use existing wsdl instance from ' . $this->externalWSDLURL);
3775
+			} else {
3776
+				$this->debug('Create wsdl from ' . $wsdl);
3777
+				$this->wsdl = new wsdl($wsdl);
3778
+				$this->externalWSDLURL = $wsdl;
3779
+			}
3780
+			$this->appendDebug($this->wsdl->getDebug());
3781
+			$this->wsdl->clearDebug();
3782
+			if (false !== ($err = $this->wsdl->getError())) {
3783
+				die('WSDL ERROR: ' . $err);
3784
+			}
3785
+		}
3786
+	}
3722 3787
 
3723
-    /**
3724
-     * constructor
3725
-     * the optional parameter is a path to a WSDL file that you'd like to bind the server instance to.
3726
-     *
3727
-     * @param mixed $wsdl file path or URL (string), or wsdl instance (object)
3728
-     * @access   public
3729
-     */
3730
-    public function __construct($wsdl = false)
3731
-    {
3732
-        parent::__construct();
3733
-        // turn on debugging?
3734
-        global $debug;
3735
-        global $HTTP_SERVER_VARS;
3736
-
3737
-        if (isset($_SERVER)) {
3738
-            $this->debug('_SERVER is defined:');
3739
-            $this->appendDebug($this->varDump($_SERVER));
3740
-        } elseif (isset($HTTP_SERVER_VARS)) {
3741
-            $this->debug('HTTP_SERVER_VARS is defined:');
3742
-            $this->appendDebug($this->varDump($HTTP_SERVER_VARS));
3743
-        } else {
3744
-            $this->debug('Neither _SERVER nor HTTP_SERVER_VARS is defined.');
3745
-        }
3746
-
3747
-        if (isset($debug)) {
3748
-            $this->debug("In nusoap_server, set debug_flag=$debug based on global flag");
3749
-            $this->debug_flag = $debug;
3750
-        } elseif (isset($_SERVER['QUERY_STRING'])) {
3751
-            $qs = explode('&', $_SERVER['QUERY_STRING']);
3752
-            foreach ($qs as $v) {
3753
-                if (0 === strpos($v, 'debug=')) {
3754
-                    $this->debug('In nusoap_server, set debug_flag=' . substr($v, 6) . ' based on query string #1');
3755
-                    $this->debug_flag = substr($v, 6);
3756
-                }
3757
-            }
3758
-        } elseif (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
3759
-            $qs = explode('&', $HTTP_SERVER_VARS['QUERY_STRING']);
3760
-            foreach ($qs as $v) {
3761
-                if (0 === strpos($v, 'debug=')) {
3762
-                    $this->debug('In nusoap_server, set debug_flag=' . substr($v, 6) . ' based on query string #2');
3763
-                    $this->debug_flag = substr($v, 6);
3764
-                }
3765
-            }
3766
-        }
3767
-
3768
-        // wsdl
3769
-        if ($wsdl) {
3770
-            $this->debug('In nusoap_server, WSDL is specified');
3771
-            if (is_object($wsdl) && ('wsdl' === get_class($wsdl))) {
3772
-                $this->wsdl = $wsdl;
3773
-                $this->externalWSDLURL = $this->wsdl->wsdl;
3774
-                $this->debug('Use existing wsdl instance from ' . $this->externalWSDLURL);
3775
-            } else {
3776
-                $this->debug('Create wsdl from ' . $wsdl);
3777
-                $this->wsdl = new wsdl($wsdl);
3778
-                $this->externalWSDLURL = $wsdl;
3779
-            }
3780
-            $this->appendDebug($this->wsdl->getDebug());
3781
-            $this->wsdl->clearDebug();
3782
-            if (false !== ($err = $this->wsdl->getError())) {
3783
-                die('WSDL ERROR: ' . $err);
3784
-            }
3785
-        }
3786
-    }
3787
-
3788
-    /**
3789
-     * processes request and returns response
3790
-     *
3791
-     * @param    string $data usually is the value of $HTTP_RAW_POST_DATA
3792
-     * @access   public
3793
-     */
3794
-    public function service($data)
3795
-    {
3796
-        global $HTTP_SERVER_VARS;
3797
-
3798
-        if (isset($_SERVER['REQUEST_METHOD'])) {
3799
-            $rm = $_SERVER['REQUEST_METHOD'];
3800
-        } elseif (isset($HTTP_SERVER_VARS['REQUEST_METHOD'])) {
3801
-            $rm = $HTTP_SERVER_VARS['REQUEST_METHOD'];
3802
-        } else {
3803
-            $rm = '';
3804
-        }
3805
-
3806
-        if (isset($_SERVER['QUERY_STRING'])) {
3807
-            $qs = $_SERVER['QUERY_STRING'];
3808
-        } elseif (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
3809
-            $qs = $HTTP_SERVER_VARS['QUERY_STRING'];
3810
-        } else {
3811
-            $qs = '';
3812
-        }
3813
-        $this->debug("In service, request method=$rm query string=$qs strlen(\$data)=" . strlen($data));
3814
-
3815
-        if ('POST' === $rm) {
3816
-            $this->debug('In service, invoke the request');
3817
-            $this->parse_request($data);
3818
-            if (!$this->fault) {
3819
-                $this->invoke_method();
3820
-            }
3821
-            if (!$this->fault) {
3822
-                $this->serialize_return();
3823
-            }
3824
-            $this->send_response();
3825
-        } elseif (preg_match('/wsdl/', $qs)) {
3826
-            $this->debug('In service, this is a request for WSDL');
3827
-            if ($this->externalWSDLURL) {
3828
-                if (false !== strpos($this->externalWSDLURL, 'http://')) { // assume URL
3829
-                    $this->debug('In service, re-direct for WSDL');
3830
-                    header('Location: ' . $this->externalWSDLURL);
3831
-                } else { // assume file
3832
-                    $this->debug('In service, use file passthru for WSDL');
3833
-                    header("Content-Type: text/xml\r\n");
3834
-                    $pos = strpos($this->externalWSDLURL, 'file://');
3835
-                    if (false === $pos) {
3836
-                        $filename = $this->externalWSDLURL;
3837
-                    } else {
3838
-                        $filename = substr($this->externalWSDLURL, $pos + 7);
3839
-                    }
3840
-                    $fp = fopen($this->externalWSDLURL, 'r');
3841
-                    fpassthru($fp);
3842
-                }
3843
-            } elseif ($this->wsdl) {
3844
-                $this->debug('In service, serialize WSDL');
3845
-                header("Content-Type: text/xml; charset=ISO-8859-1\r\n");
3846
-                print $this->wsdl->serialize($this->debug_flag);
3847
-                if ($this->debug_flag) {
3848
-                    $this->debug('wsdl:');
3849
-                    $this->appendDebug($this->varDump($this->wsdl));
3850
-                    print $this->getDebugAsXMLComment();
3851
-                }
3852
-            } else {
3853
-                $this->debug('In service, there is no WSDL');
3854
-                header("Content-Type: text/html; charset=ISO-8859-1\r\n");
3855
-                print 'This service does not provide WSDL';
3856
-            }
3857
-        } elseif ($this->wsdl) {
3858
-            $this->debug('In service, return Web description');
3859
-            print $this->wsdl->webDescription();
3860
-        } else {
3861
-            $this->debug('In service, no Web description');
3862
-            header("Content-Type: text/html; charset=ISO-8859-1\r\n");
3863
-            print 'This service does not provide a Web description';
3864
-        }
3865
-    }
3866
-
3867
-    /**
3868
-     * parses HTTP request headers.
3869
-     *
3870
-     * The following fields are set by this function (when successful)
3871
-     *
3872
-     * headers
3873
-     * request
3874
-     * xml_encoding
3875
-     * SOAPAction
3876
-     *
3877
-     * @access   private
3878
-     */
3879
-    private function parse_http_headers()
3880
-    {
3881
-        global $HTTP_SERVER_VARS;
3882
-
3883
-        $this->request = '';
3884
-        $this->SOAPAction = '';
3885
-        if (function_exists('getallheaders')) {
3886
-            $this->debug('In parse_http_headers, use getallheaders');
3887
-            $headers = getallheaders();
3888
-            foreach ($headers as $k => $v) {
3889
-                $k = strtolower($k);
3890
-                $this->headers[$k] = $v;
3891
-                $this->request .= "$k: $v\r\n";
3892
-                $this->debug("$k: $v");
3893
-            }
3894
-            // get SOAPAction header
3895
-            if (isset($this->headers['soapaction'])) {
3896
-                $this->SOAPAction = str_replace('"', '', $this->headers['soapaction']);
3897
-            }
3898
-            // get the character encoding of the incoming request
3899
-            if (isset($this->headers['content-type']) && strpos($this->headers['content-type'], '=')) {
3900
-                $enc = str_replace('"', '', substr(strstr($this->headers['content-type'], '='), 1));
3901
-                if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i', $enc)) {
3902
-                    $this->xml_encoding = strtoupper($enc);
3903
-                } else {
3904
-                    $this->xml_encoding = 'US-ASCII';
3905
-                }
3906
-            } else {
3907
-                // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
3908
-                $this->xml_encoding = 'ISO-8859-1';
3909
-            }
3910
-        } elseif (isset($_SERVER) && is_array($_SERVER)) {
3911
-            $this->debug('In parse_http_headers, use _SERVER');
3912
-            foreach ($_SERVER as $k => $v) {
3913
-                if (0 === strpos($k, 'HTTP_')) {
3914
-                    $k = str_replace(' ', '-', strtolower(str_replace('_', ' ', substr($k, 5))));
3915
-                } else {
3916
-                    $k = str_replace(' ', '-', strtolower(str_replace('_', ' ', $k)));
3917
-                }
3918
-                if ('soapaction' === $k) {
3919
-                    // get SOAPAction header
3920
-                    $k = 'SOAPAction';
3921
-                    $v = str_replace('"', '', $v);
3922
-                    $v = str_replace('\\', '', $v);
3923
-                    $this->SOAPAction = $v;
3924
-                } elseif ('content-type' === $k) {
3925
-                    // get the character encoding of the incoming request
3926
-                    if (strpos($v, '=')) {
3927
-                        $enc = substr(strstr($v, '='), 1);
3928
-                        $enc = str_replace('"', '', $enc);
3929
-                        $enc = str_replace('\\', '', $enc);
3930
-                        if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i', $enc)) {
3931
-                            $this->xml_encoding = strtoupper($enc);
3932
-                        } else {
3933
-                            $this->xml_encoding = 'US-ASCII';
3934
-                        }
3935
-                    } else {
3936
-                        // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
3937
-                        $this->xml_encoding = 'ISO-8859-1';
3938
-                    }
3939
-                }
3940
-                $this->headers[$k] = $v;
3941
-                $this->request .= "$k: $v\r\n";
3942
-                $this->debug("$k: $v");
3943
-            }
3944
-        } elseif (is_array($HTTP_SERVER_VARS)) {
3945
-            $this->debug('In parse_http_headers, use HTTP_SERVER_VARS');
3946
-            foreach ($HTTP_SERVER_VARS as $k => $v) {
3947
-                if (0 === strpos($k, 'HTTP_')) {
3948
-                    $k = str_replace(' ', '-', strtolower(str_replace('_', ' ', substr($k, 5))));
3949
-                    $k = strtolower(substr($k, 5));
3950
-                } else {
3951
-                    $k = str_replace(' ', '-', strtolower(str_replace('_', ' ', $k)));
3952
-                    $k = strtolower($k);
3953
-                }
3954
-                if ('soapaction' === $k) {
3955
-                    // get SOAPAction header
3956
-                    $k = 'SOAPAction';
3957
-                    $v = str_replace('"', '', $v);
3958
-                    $v = str_replace('\\', '', $v);
3959
-                    $this->SOAPAction = $v;
3960
-                } elseif ('content-type' === $k) {
3961
-                    // get the character encoding of the incoming request
3962
-                    if (strpos($v, '=')) {
3963
-                        $enc = substr(strstr($v, '='), 1);
3964
-                        $enc = str_replace('"', '', $enc);
3965
-                        $enc = str_replace('\\', '', $enc);
3966
-                        if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i', $enc)) {
3967
-                            $this->xml_encoding = strtoupper($enc);
3968
-                        } else {
3969
-                            $this->xml_encoding = 'US-ASCII';
3970
-                        }
3971
-                    } else {
3972
-                        // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
3973
-                        $this->xml_encoding = 'ISO-8859-1';
3974
-                    }
3975
-                }
3976
-                $this->headers[$k] = $v;
3977
-                $this->request .= "$k: $v\r\n";
3978
-                $this->debug("$k: $v");
3979
-            }
3980
-        } else {
3981
-            $this->debug('In parse_http_headers, HTTP headers not accessible');
3982
-            $this->setError('HTTP headers not accessible');
3983
-        }
3984
-    }
3985
-
3986
-    /**
3987
-     * parses a request
3988
-     *
3989
-     * The following fields are set by this function (when successful)
3990
-     *
3991
-     * headers
3992
-     * request
3993
-     * xml_encoding
3994
-     * SOAPAction
3995
-     * request
3996
-     * requestSOAP
3997
-     * methodURI
3998
-     * methodname
3999
-     * methodparams
4000
-     * requestHeaders
4001
-     * document
4002
-     *
4003
-     * This sets the fault field on error
4004
-     *
4005
-     * @param    string $data XML string
4006
-     * @access   private
4007
-     */
4008
-    private function parse_request($data = '')
4009
-    {
4010
-        $this->debug('entering parse_request()');
4011
-        $this->parse_http_headers();
4012
-        $this->debug('got character encoding: ' . $this->xml_encoding);
4013
-        // uncompress if necessary
4014
-        if (isset($this->headers['content-encoding']) && '' != $this->headers['content-encoding']) {
4015
-            $this->debug('got content encoding: ' . $this->headers['content-encoding']);
4016
-            if ('deflate' === $this->headers['content-encoding'] || 'gzip' === $this->headers['content-encoding']) {
4017
-                // if decoding works, use it. else assume data wasn't gzencoded
4018
-                if (function_exists('gzuncompress')) {
4019
-                    if ('deflate' === $this->headers['content-encoding'] && $degzdata = @gzuncompress($data)) {
4020
-                        $data = $degzdata;
4021
-                    } elseif ('gzip' === $this->headers['content-encoding'] && $degzdata = gzinflate(substr($data, 10))) {
4022
-                        $data = $degzdata;
4023
-                    } else {
4024
-                        $this->fault('SOAP-ENV:Client', 'Errors occurred when trying to decode the data');
4025
-                        return;
4026
-                    }
4027
-                } else {
4028
-                    $this->fault('SOAP-ENV:Client', 'This Server does not support compressed data');
4029
-                    return;
4030
-                }
4031
-            }
4032
-        }
4033
-        $this->request .= "\r\n" . $data;
4034
-        $data = $this->parseRequest($this->headers, $data);
4035
-        $this->requestSOAP = $data;
4036
-        $this->debug('leaving parse_request');
4037
-    }
4038
-
4039
-    /**
4040
-     * invokes a PHP function for the requested SOAP method
4041
-     *
4042
-     * The following fields are set by this function (when successful)
4043
-     *
4044
-     * methodreturn
4045
-     *
4046
-     * Note that the PHP function that is called may also set the following
4047
-     * fields to affect the response sent to the client
4048
-     *
4049
-     * responseHeaders
4050
-     * outgoing_headers
4051
-     *
4052
-     * This sets the fault field on error
4053
-     *
4054
-     * @access   private
4055
-     */
4056
-    private function invoke_method()
4057
-    {
4058
-        $this->debug('in invoke_method, methodname=' . $this->methodname . ' methodURI=' . $this->methodURI . ' SOAPAction=' . $this->SOAPAction);
4059
-
4060
-        //
4061
-        // if you are debugging in this area of the code, your service uses a class to implement methods,
4062
-        // you use SOAP RPC, and the client is .NET, please be aware of the following...
4063
-        // when the .NET wsdl.exe utility generates a proxy, it will remove the '.' or '..' from the
4064
-        // method name.  that is fine for naming the .NET methods.  it is not fine for properly constructing
4065
-        // the XML request and reading the XML response.  you need to add the RequestElementName and
4066
-        // ResponseElementName to the System.Web.Services.Protocols.SoapRpcMethodAttribute that wsdl.exe
4067
-        // generates for the method.  these parameters are used to specify the correct XML element names
4068
-        // for .NET to use, i.e. the names with the '.' in them.
4069
-        //
4070
-        $orig_methodname = $this->methodname;
4071
-        if ($this->wsdl) {
4072
-            if (false !== ($this->opData = $this->wsdl->getOperationData($this->methodname))) {
4073
-                $this->debug('in invoke_method, found WSDL operation=' . $this->methodname);
4074
-                $this->appendDebug('opData=' . $this->varDump($this->opData));
4075
-            } elseif (false !== ($this->opData = $this->wsdl->getOperationDataForSoapAction($this->SOAPAction))) {
4076
-                // Note: hopefully this case will only be used for doc/lit, since rpc services should have wrapper element
4077
-                $this->debug('in invoke_method, found WSDL soapAction=' . $this->SOAPAction . ' for operation=' . $this->opData['name']);
4078
-                $this->appendDebug('opData=' . $this->varDump($this->opData));
4079
-                $this->methodname = $this->opData['name'];
4080
-            } else {
4081
-                $this->debug('in invoke_method, no WSDL for operation=' . $this->methodname);
4082
-                $this->fault('SOAP-ENV:Client', "Operation '" . $this->methodname . "' is not defined in the WSDL for this service");
4083
-                return;
4084
-            }
4085
-        } else {
4086
-            $this->debug('in invoke_method, no WSDL to validate method');
4087
-        }
4088
-
4089
-        // if a . is present in $this->methodname, we see if there is a class in scope,
4090
-        // which could be referred to. We will also distinguish between two deliminators,
4091
-        // to allow methods to be called a the class or an instance
4092
-        if (strpos($this->methodname, '..') > 0) {
4093
-            $delim = '..';
4094
-        } elseif (strpos($this->methodname, '.') > 0) {
4095
-            $delim = '.';
4096
-        } else {
4097
-            $delim = '';
4098
-        }
4099
-        $this->debug("in invoke_method, delim=$delim");
4100
-
4101
-        $class = '';
4102
-        $method = '';
4103
-        if (strlen($delim) > 0 && 1 == substr_count($this->methodname, $delim)) {
4104
-            $try_class = substr($this->methodname, 0, strpos($this->methodname, $delim));
4105
-            if (class_exists($try_class)) {
4106
-                // get the class and method name
4107
-                $class = $try_class;
4108
-                $method = substr($this->methodname, strpos($this->methodname, $delim) + strlen($delim));
4109
-                $this->debug("in invoke_method, class=$class method=$method delim=$delim");
4110
-            } else {
4111
-                $this->debug("in invoke_method, class=$try_class not found");
4112
-            }
4113
-        } elseif (strlen($delim) > 0 && substr_count($this->methodname, $delim) > 1) {
4114
-            $split = explode($delim, $this->methodname);
4115
-            $method = array_pop($split);
4116
-            $class = implode('\\', $split);
4117
-        } else {
4118
-            $try_class = '';
4119
-            $this->debug('in invoke_method, no class to try');
4120
-        }
4121
-
4122
-        // does method exist?
4123
-        if ('' == $class) {
4124
-            if (!function_exists($this->methodname)) {
4125
-                $this->debug("in invoke_method, function '$this->methodname' not found!");
4126
-                $this->result = 'fault: method not found';
4127
-                $this->fault('SOAP-ENV:Client', "method '$this->methodname'('$orig_methodname') not defined in service('$try_class' '$delim')");
4128
-                return;
4129
-            }
4130
-        } else {
4131
-            $method_to_compare = (0 === strpos(phpversion(), '4.')) ? strtolower($method) : $method;
4132
-            if (!in_array($method_to_compare, get_class_methods($class))) {
4133
-                $this->debug("in invoke_method, method '$this->methodname' not found in class '$class'!");
4134
-                $this->result = 'fault: method not found';
4135
-                $this->fault('SOAP-ENV:Client', "method '$this->methodname'/'$method_to_compare'('$orig_methodname') not defined in service/'$class'('$try_class' '$delim')");
4136
-                return;
4137
-            }
4138
-        }
4139
-
4140
-        // evaluate message, getting back parameters
4141
-        // verify that request parameters match the method's signature
4142
-        if (!$this->verify_method($this->methodname, $this->methodparams)) {
4143
-            // debug
4144
-            $this->debug('ERROR: request not verified against method signature');
4145
-            $this->result = 'fault: request failed validation against method signature';
4146
-            // return fault
4147
-            $this->fault('SOAP-ENV:Client', "Operation '$this->methodname' not defined in service.");
4148
-            return;
4149
-        }
4150
-
4151
-        // if there are parameters to pass
4152
-        $this->debug('in invoke_method, params:');
4153
-        $this->appendDebug($this->varDump($this->methodparams));
4154
-        $this->debug("in invoke_method, calling '$this->methodname'");
4155
-        if (!function_exists('call_user_func_array')) {
4156
-            if ('' == $class) {
4157
-                $this->debug('in invoke_method, calling function using eval()');
4158
-                $funcCall = "\$this->methodreturn = $this->methodname(";
4159
-            } else {
4160
-                if ('..' === $delim) {
4161
-                    $this->debug('in invoke_method, calling class method using eval()');
4162
-                    $funcCall = '$this->methodreturn = ' . $class . '::' . $method . '(';
4163
-                } else {
4164
-                    $this->debug('in invoke_method, calling instance method using eval()');
4165
-                    // generate unique instance name
4166
-                    $instname = '$inst_' . time();
4167
-                    $funcCall = $instname . ' = new ' . $class . '(); ';
4168
-                    $funcCall .= '$this->methodreturn = ' . $instname . '->' . $method . '(';
4169
-                }
4170
-            }
4171
-            if ($this->methodparams) {
4172
-                foreach ($this->methodparams as $param) {
4173
-                    if (is_array($param) || is_object($param)) {
4174
-                        $this->fault('SOAP-ENV:Client', 'NuSOAP does not handle complexType parameters correctly when using eval; call_user_func_array must be available');
4175
-                        return;
4176
-                    }
4177
-                    $funcCall .= "\"$param\",";
4178
-                }
4179
-                $funcCall = substr($funcCall, 0, -1);
4180
-            }
4181
-            $funcCall .= ');';
4182
-            $this->debug('in invoke_method, function call: ' . $funcCall);
4183
-            @eval($funcCall);
4184
-        } else {
4185
-            if ('' == $class) {
4186
-                $this->debug('in invoke_method, calling function using call_user_func_array()');
4187
-                $call_arg = $this->methodname;    // straight assignment changes $this->methodname to lower case after call_user_func_array()
4188
-            } elseif ('..' === $delim) {
4189
-                $this->debug('in invoke_method, calling class method using call_user_func_array()');
4190
-                $call_arg = [$class, $method];
4191
-            } else {
4192
-                $this->debug('in invoke_method, calling instance method using call_user_func_array()');
4193
-                $instance = new $class();
4194
-                $call_arg = [&$instance, $method];
4195
-            }
4196
-            if (is_array($this->methodparams)) {
4197
-                $this->methodreturn = call_user_func_array($call_arg, array_values($this->methodparams));
4198
-            } else {
4199
-                $this->methodreturn = call_user_func_array($call_arg, []);
4200
-            }
4201
-        }
4202
-        $this->debug('in invoke_method, methodreturn:');
4203
-        $this->appendDebug($this->varDump($this->methodreturn));
4204
-        $this->debug("in invoke_method, called method $this->methodname, received data of type " . gettype($this->methodreturn));
4205
-    }
4206
-
4207
-    /**
4208
-     * serializes the return value from a PHP function into a full SOAP Envelope
4209
-     *
4210
-     * The following fields are set by this function (when successful)
4211
-     *
4212
-     * responseSOAP
4213
-     *
4214
-     * This sets the fault field on error
4215
-     *
4216
-     * @access   private
4217
-     */
4218
-    private function serialize_return()
4219
-    {
4220
-        $this->debug('Entering serialize_return methodname: ' . $this->methodname . ' methodURI: ' . $this->methodURI);
4221
-        // if fault
4222
-        if (isset($this->methodreturn) && is_object($this->methodreturn) && (('soap_fault' === get_class($this->methodreturn)) || ('nusoap_fault' === get_class($this->methodreturn)))) {
4223
-            $this->debug('got a fault object from method');
4224
-            $this->fault = $this->methodreturn;
4225
-            return;
4226
-        } elseif ($this->methodreturnisliteralxml) {
4227
-            $return_val = $this->methodreturn;
4228
-        // returned value(s)
4229
-        } else {
4230
-            $this->debug('got a(n) ' . gettype($this->methodreturn) . ' from method');
4231
-            $this->debug('serializing return value');
4232
-            if ($this->wsdl) {
4233
-                if (is_array($this->opData['output']['parts']) && count($this->opData['output']['parts']) > 1) {
4234
-                    $this->debug('more than one output part, so use the method return unchanged');
4235
-                    $opParams = $this->methodreturn;
4236
-                } elseif (1 == count($this->opData['output']['parts'])) {
4237
-                    $this->debug('exactly one output part, so wrap the method return in a simple array');
4238
-                    // TODO: verify that it is not already wrapped!
4239
-                    //foreach ($this->opData['output']['parts'] as $name => $type) {
4240
-                    //	$this->debug('wrap in element named ' . $name);
4241
-                    //}
4242
-                    $opParams = [$this->methodreturn];
4243
-                }
4244
-                $return_val = $this->wsdl->serializeRPCParameters($this->methodname, 'output', $opParams);
4245
-                $this->appendDebug($this->wsdl->getDebug());
4246
-                $this->wsdl->clearDebug();
4247
-                if (false !== ($errstr = $this->wsdl->getError())) {
4248
-                    $this->debug('got wsdl error: ' . $errstr);
4249
-                    $this->fault('SOAP-ENV:Server', 'unable to serialize result');
4250
-                    return;
4251
-                }
4252
-            } else {
4253
-                if (isset($this->methodreturn)) {
4254
-                    $return_val = $this->serialize_val($this->methodreturn, 'return');
4255
-                } else {
4256
-                    $return_val = '';
4257
-                    $this->debug('in absence of WSDL, assume void return for backward compatibility');
4258
-                }
4259
-            }
4260
-        }
4261
-        $this->debug('return value:');
4262
-        $this->appendDebug($this->varDump($return_val));
4263
-
4264
-        $this->debug('serializing response');
4265
-        if ($this->wsdl) {
4266
-            $this->debug('have WSDL for serialization: style is ' . $this->opData['style']);
4267
-            if ('rpc' === $this->opData['style']) {
4268
-                $this->debug('style is rpc for serialization: use is ' . $this->opData['output']['use']);
4269
-                if ('literal' === $this->opData['output']['use']) {
4270
-                    // http://www.ws-i.org/Profiles/BasicProfile-1.1-2004-08-24.html R2735 says rpc/literal accessor elements should not be in a namespace
4271
-                    if ($this->methodURI) {
4272
-                        $payload = '<ns1:' . $this->methodname . 'Response xmlns:ns1="' . $this->methodURI . '">' . $return_val . '</ns1:' . $this->methodname . 'Response>';
4273
-                    } else {
4274
-                        $payload = '<' . $this->methodname . 'Response>' . $return_val . '</' . $this->methodname . 'Response>';
4275
-                    }
4276
-                } else {
4277
-                    if ($this->methodURI) {
4278
-                        $payload = '<ns1:' . $this->methodname . 'Response xmlns:ns1="' . $this->methodURI . '">' . $return_val . '</ns1:' . $this->methodname . 'Response>';
4279
-                    } else {
4280
-                        $payload = '<' . $this->methodname . 'Response>' . $return_val . '</' . $this->methodname . 'Response>';
4281
-                    }
4282
-                }
4283
-            } else {
4284
-                $this->debug('style is not rpc for serialization: assume document');
4285
-                $payload = $return_val;
4286
-            }
4287
-        } else {
4288
-            $this->debug('do not have WSDL for serialization: assume rpc/encoded');
4289
-            $payload = '<ns1:' . $this->methodname . 'Response xmlns:ns1="' . $this->methodURI . '">' . $return_val . '</ns1:' . $this->methodname . 'Response>';
4290
-        }
4291
-        $this->result = 'successful';
4292
-        if ($this->wsdl) {
4293
-            //if($this->debug_flag){
4294
-            $this->appendDebug($this->wsdl->getDebug());
4295
-            //	}
4296
-            if (isset($this->opData['output']['encodingStyle'])) {
4297
-                $encodingStyle = $this->opData['output']['encodingStyle'];
4298
-            } else {
4299
-                $encodingStyle = '';
4300
-            }
4301
-            // Added: In case we use a WSDL, return a serialized env. WITH the usedNamespaces.
4302
-            $this->responseSOAP = $this->serializeEnvelope($payload, $this->responseHeaders, $this->wsdl->usedNamespaces, $this->opData['style'], $this->opData['output']['use'], $encodingStyle);
4303
-        } else {
4304
-            $this->responseSOAP = $this->serializeEnvelope($payload, $this->responseHeaders);
4305
-        }
4306
-        $this->debug('Leaving serialize_return');
4307
-    }
4308
-
4309
-    /**
4310
-     * sends an HTTP response
4311
-     *
4312
-     * The following fields are set by this function (when successful)
4313
-     *
4314
-     * outgoing_headers
4315
-     * response
4316
-     *
4317
-     * @access   private
4318
-     */
4319
-    private function send_response()
4320
-    {
4321
-        $this->debug('Enter send_response');
4322
-        if ($this->fault) {
4323
-            $payload = $this->fault->serialize();
4324
-            $this->outgoing_headers[] = 'HTTP/1.0 500 Internal Server Error';
4325
-            $this->outgoing_headers[] = 'Status: 500 Internal Server Error';
4326
-        } else {
4327
-            $payload = $this->responseSOAP;
4328
-            // Some combinations of PHP+Web server allow the Status
4329
-            // to come through as a header.  Since OK is the default
4330
-            // just do nothing.
4331
-            // $this->outgoing_headers[] = "HTTP/1.0 200 OK";
4332
-            // $this->outgoing_headers[] = "Status: 200 OK";
4333
-        }
4334
-        // add debug data if in debug mode
4335
-        if (isset($this->debug_flag) && $this->debug_flag) {
4336
-            $payload .= $this->getDebugAsXMLComment();
4337
-        }
4338
-        $this->outgoing_headers[] = "Server: $this->title Server v$this->version";
4339
-        preg_match('/\$Revisio' . 'n: ([^ ]+)/', $this->revision, $rev);
4340
-        $this->outgoing_headers[] = "X-SOAP-Server: $this->title/$this->version (" . $rev[1] . ')';
4341
-        // Let the Web server decide about this
4342
-        //$this->outgoing_headers[] = "Connection: Close\r\n";
4343
-        $payload = $this->getHTTPBody($payload);
4344
-        $type = $this->getHTTPContentType();
4345
-        $charset = $this->getHTTPContentTypeCharset();
4346
-        $this->outgoing_headers[] = "Content-Type: $type" . ($charset ? '; charset=' . $charset : '');
4347
-        //begin code to compress payload - by John
4348
-        // NOTE: there is no way to know whether the Web server will also compress
4349
-        // this data.
4350
-        if (strlen($payload) > 1024 && isset($this->headers) && isset($this->headers['accept-encoding'])) {
4351
-            if (false !== strpos($this->headers['accept-encoding'], 'gzip')) {
4352
-                if (function_exists('gzencode')) {
4353
-                    if (isset($this->debug_flag) && $this->debug_flag) {
4354
-                        $payload .= '<!-- Content being gzipped -->';
4355
-                    }
4356
-                    $this->outgoing_headers[] = 'Content-Encoding: gzip';
4357
-                    $payload = gzencode($payload);
4358
-                } else {
4359
-                    if (isset($this->debug_flag) && $this->debug_flag) {
4360
-                        $payload .= '<!-- Content will not be gzipped: no gzencode -->';
4361
-                    }
4362
-                }
4363
-            } elseif (false !== strpos($this->headers['accept-encoding'], 'deflate')) {
4364
-                // Note: MSIE requires gzdeflate output (no Zlib header and checksum),
4365
-                // instead of gzcompress output,
4366
-                // which conflicts with HTTP 1.1 spec (http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.5)
4367
-                if (function_exists('gzdeflate')) {
4368
-                    if (isset($this->debug_flag) && $this->debug_flag) {
4369
-                        $payload .= '<!-- Content being deflated -->';
4370
-                    }
4371
-                    $this->outgoing_headers[] = 'Content-Encoding: deflate';
4372
-                    $payload = gzdeflate($payload);
4373
-                } else {
4374
-                    if (isset($this->debug_flag) && $this->debug_flag) {
4375
-                        $payload .= '<!-- Content will not be deflated: no gzcompress -->';
4376
-                    }
4377
-                }
4378
-            }
4379
-        }
4380
-        //end code
4381
-        $this->outgoing_headers[] = 'Content-Length: ' . strlen($payload);
4382
-        reset($this->outgoing_headers);
4383
-        foreach ($this->outgoing_headers as $hdr) {
4384
-            header($hdr, false);
4385
-        }
4386
-        print $payload;
4387
-        $this->response = implode("\r\n", $this->outgoing_headers) . "\r\n\r\n" . $payload;
4388
-    }
4389
-
4390
-    /**
4391
-     * takes the value that was created by parsing the request
4392
-     * and compares to the method's signature, if available.
4393
-     *
4394
-     * @param    string $operation The operation to be invoked
4395
-     * @param    array $request The array of parameter values
4396
-     * @return    boolean    Whether the operation was found
4397
-     * @access   private
4398
-     */
4399
-    private function verify_method($operation, $request)
4400
-    {
4401
-        if (isset($this->wsdl) && is_object($this->wsdl)) {
4402
-            if ($this->wsdl->getOperationData($operation)) {
4403
-                return true;
4404
-            }
4405
-        } elseif (isset($this->operations[$operation])) {
4406
-            return true;
4407
-        }
4408
-        return false;
4409
-    }
4410
-
4411
-    /**
4412
-     * processes SOAP message received from client
4413
-     *
4414
-     * @param    array $headers The HTTP headers
4415
-     * @param    string $data unprocessed request data from client
4416
-     * @return    mixed    value of the message, decoded into a PHP type
4417
-     * @access   private
4418
-     */
4419
-    private function parseRequest($headers, $data)
4420
-    {
4421
-        $this->debug('Entering parseRequest() for data of length ' . strlen($data) . ' headers:');
4422
-        $this->appendDebug($this->varDump($headers));
4423
-        if (!isset($headers['content-type'])) {
4424
-            $this->setError('Request not of type text/xml (no content-type header)');
4425
-            return false;
4426
-        }
4427
-        if (false === strpos($headers['content-type'], 'text/xml')) {
4428
-            $this->setError('Request not of type text/xml');
4429
-            return false;
4430
-        }
4431
-        if (strpos($headers['content-type'], '=')) {
4432
-            $enc = str_replace('"', '', substr(strstr($headers['content-type'], '='), 1));
4433
-            $this->debug('Got response encoding: ' . $enc);
4434
-            if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i', $enc)) {
4435
-                $this->xml_encoding = strtoupper($enc);
4436
-            } else {
4437
-                $this->xml_encoding = 'US-ASCII';
4438
-            }
4439
-        } else {
4440
-            // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
4441
-            $this->xml_encoding = 'ISO-8859-1';
4442
-        }
4443
-        $this->debug('Use encoding: ' . $this->xml_encoding . ' when creating nusoap_parser');
4444
-        // parse response, get soap parser obj
4445
-        $parser = new nusoap_parser($data, $this->xml_encoding, '', $this->decode_utf8);
4446
-        // parser debug
4447
-        $this->debug("parser debug: \n" . $parser->getDebug());
4448
-        // if fault occurred during message parsing
4449
-        if (false !== ($err = $parser->getError())) {
4450
-            $this->result = 'fault: error in msg parsing: ' . $err;
4451
-            $this->fault('SOAP-ENV:Client', "error in msg parsing:\n" . $err);
4452
-        // else successfully parsed request into soapval object
4453
-        } else {
4454
-            // get/set methodname
4455
-            $this->methodURI = $parser->root_struct_namespace;
4456
-            $this->methodname = $parser->root_struct_name;
4457
-            $this->debug('methodname: ' . $this->methodname . ' methodURI: ' . $this->methodURI);
4458
-            $this->debug('calling parser->get_soapbody()');
4459
-            $this->methodparams = $parser->get_soapbody();
4460
-            // get SOAP headers
4461
-            $this->requestHeaders = $parser->getHeaders();
4462
-            // get SOAP Header
4463
-            $this->requestHeader = $parser->get_soapheader();
4464
-            // add document for doclit support
4465
-            $this->document = $parser->document;
4466
-        }
4467
-    }
4468
-
4469
-    /**
4470
-     * gets the HTTP body for the current response.
4471
-     *
4472
-     * @param string $soapmsg The SOAP payload
4473
-     * @return string The HTTP body, which includes the SOAP payload
4474
-     * @access private
4475
-     */
4476
-    private function getHTTPBody($soapmsg)
4477
-    {
4478
-        return $soapmsg;
4479
-    }
4480
-
4481
-    /**
4482
-     * gets the HTTP content type for the current response.
4483
-     *
4484
-     * Note: getHTTPBody must be called before this.
4485
-     *
4486
-     * @return string the HTTP content type for the current response.
4487
-     * @access private
4488
-     */
4489
-    private function getHTTPContentType()
4490
-    {
4491
-        return 'text/xml';
4492
-    }
4493
-
4494
-    /**
4495
-     * gets the HTTP content type charset for the current response.
4496
-     * returns false for non-text content types.
4497
-     *
4498
-     * Note: getHTTPBody must be called before this.
4499
-     *
4500
-     * @return string the HTTP content type charset for the current response.
4501
-     * @access private
4502
-     */
4503
-    private function getHTTPContentTypeCharset()
4504
-    {
4505
-        return $this->soap_defencoding;
4506
-    }
4507
-
4508
-    /**
4509
-     * add a method to the dispatch map (this has been replaced by the register method)
4510
-     *
4511
-     * @param    string $methodname
4512
-     * @param    string $in array of input values
4513
-     * @param    string $out array of output values
4514
-     * @access   public
4515
-     * @deprecated
4516
-     */
4517
-    public function add_to_map($methodname, $in, $out)
4518
-    {
4519
-        $this->operations[$methodname] = ['name' => $methodname, 'in' => $in, 'out' => $out];
4520
-    }
4521
-
4522
-    /**
4523
-     * register a service function with the server
4524
-     *
4525
-     * @param    string $name          the name of the PHP function, class.method or class..method
4526
-     * @param    array  $in            assoc array of input values: key = param name, value = param type
4527
-     * @param    array  $out           assoc array of output values: key = param name, value = param type
4528
-     * @param    mixed  $namespace     the element namespace for the method or false
4529
-     * @param    mixed  $soapaction    the soapaction for the method or false
4530
-     * @param    mixed  $style         optional (rpc|document) or false Note: when 'document' is specified, parameter and return wrappers are created for you automatically
4531
-     * @param    mixed  $use           optional (encoded|literal) or false
4532
-     * @param    string $documentation optional Description to include in WSDL
4533
-     * @param    string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
4534
-     * @access   public
4535
-     * @return bool
4536
-     */
4537
-    public function register($name, $in = [], $out = [], $namespace = false, $soapaction = false, $style = false, $use = false, $documentation = '', $encodingStyle = '')
4538
-    {
4539
-        global $HTTP_SERVER_VARS;
4540
-
4541
-        if ($this->externalWSDLURL) {
4542
-            die('You cannot bind to an external WSDL file, and register methods outside of it! Please choose either WSDL or no WSDL.');
4543
-        }
4544
-        if (!$name) {
4545
-            die('You must specify a name when you register an operation');
4546
-        }
4547
-        if (!is_array($in)) {
4548
-            die('You must provide an array for operation inputs');
4549
-        }
4550
-        if (!is_array($out)) {
4551
-            die('You must provide an array for operation outputs');
4552
-        }
4553
-        if (false == $namespace) {
4554
-        }
4555
-        if (false == $soapaction) {
4556
-            if (isset($_SERVER)) {
4557
-                $SERVER_NAME = $_SERVER['SERVER_NAME'];
4558
-                $SCRIPT_NAME = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
4559
-                $HTTPS = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : (isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off');
4560
-            } elseif (isset($HTTP_SERVER_VARS)) {
4561
-                $SERVER_NAME = $HTTP_SERVER_VARS['SERVER_NAME'];
4562
-                $SCRIPT_NAME = isset($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : $HTTP_SERVER_VARS['SCRIPT_NAME'];
4563
-                $HTTPS = isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off';
4564
-            } else {
4565
-                $this->setError('Neither _SERVER nor HTTP_SERVER_VARS is available');
4566
-            }
4567
-            if ('1' == $HTTPS || 'on' === $HTTPS) {
4568
-                $SCHEME = 'https';
4569
-            } else {
4570
-                $SCHEME = 'http';
4571
-            }
4572
-            $soapaction = "$SCHEME://$SERVER_NAME$SCRIPT_NAME/$name";
4573
-        }
4574
-        if (false == $style) {
4575
-            $style = 'rpc';
4576
-        }
4577
-        if (false == $use) {
4578
-            $use = 'encoded';
4579
-        }
4580
-        if ('encoded' === $use && '' == $encodingStyle) {
4581
-            $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
4582
-        }
4583
-
4584
-        $this->operations[$name] = [
4585
-            'name' => $name,
4586
-            'in' => $in,
4587
-            'out' => $out,
4588
-            'namespace' => $namespace,
4589
-            'soapaction' => $soapaction,
4590
-            'style' => $style
4591
-        ];
4592
-        if ($this->wsdl) {
4593
-            $this->wsdl->addOperation($name, $in, $out, $namespace, $soapaction, $style, $use, $documentation, $encodingStyle);
4594
-        }
4595
-        return true;
4596
-    }
4597
-
4598
-    /**
4599
-     * Specify a fault to be returned to the client.
4600
-     * This also acts as a flag to the server that a fault has occured.
4601
-     *
4602
-     * @param    string $faultcode
4603
-     * @param    string $faultstring
4604
-     * @param    string $faultactor
4605
-     * @param    string $faultdetail
4606
-     * @access   public
4607
-     */
4608
-    public function fault($faultcode, $faultstring, $faultactor = '', $faultdetail = '')
4609
-    {
4610
-        if ('' == $faultdetail && $this->debug_flag) {
4611
-            $faultdetail = $this->getDebug();
4612
-        }
4613
-        $this->fault = new nusoap_fault($faultcode, $faultactor, $faultstring, $faultdetail);
4614
-        $this->fault->soap_defencoding = $this->soap_defencoding;
4615
-    }
4616
-
4617
-    /**
4618
-     * Sets up wsdl object.
4619
-     * Acts as a flag to enable internal WSDL generation
4620
-     *
4621
-     * @param string $serviceName , name of the service
4622
-     * @param mixed $namespace optional 'tns' service namespace or false
4623
-     * @param mixed $endpoint optional URL of service endpoint or false
4624
-     * @param string $style optional (rpc|document) WSDL style (also specified by operation)
4625
-     * @param string $transport optional SOAP transport
4626
-     * @param mixed $schemaTargetNamespace optional 'types' targetNamespace for service schema or false
4627
-     */
4628
-    public function configureWSDL($serviceName, $namespace = false, $endpoint = false, $style = 'rpc', $transport = 'http://schemas.xmlsoap.org/soap/http', $schemaTargetNamespace = false)
4629
-    {
4630
-        global $HTTP_SERVER_VARS;
4631
-
4632
-        if (isset($_SERVER)) {
4633
-            $SERVER_NAME = $_SERVER['SERVER_NAME'];
4634
-            $SERVER_PORT = $_SERVER['SERVER_PORT'];
4635
-            $SCRIPT_NAME = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
4636
-            $HTTPS = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : (isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off');
4637
-        } elseif (isset($HTTP_SERVER_VARS)) {
4638
-            $SERVER_NAME = $HTTP_SERVER_VARS['SERVER_NAME'];
4639
-            $SERVER_PORT = $HTTP_SERVER_VARS['SERVER_PORT'];
4640
-            $SCRIPT_NAME = isset($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : $HTTP_SERVER_VARS['SCRIPT_NAME'];
4641
-            $HTTPS = isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off';
4642
-        } else {
4643
-            $this->setError('Neither _SERVER nor HTTP_SERVER_VARS is available');
4644
-        }
4645
-        // If server name has port number attached then strip it (else port number gets duplicated in WSDL output) (occurred using lighttpd and FastCGI)
4646
-        $colon = strpos($SERVER_NAME, ':');
4647
-        if ($colon) {
4648
-            $SERVER_NAME = substr($SERVER_NAME, 0, $colon);
4649
-        }
4650
-        if (80 == $SERVER_PORT) {
4651
-            $SERVER_PORT = '';
4652
-        } else {
4653
-            $SERVER_PORT = ':' . $SERVER_PORT;
4654
-        }
4655
-        if (false == $namespace) {
4656
-            $namespace = "http://$SERVER_NAME/soap/$serviceName";
4657
-        }
4658
-
4659
-        if (false == $endpoint) {
4660
-            if ('1' == $HTTPS || 'on' === $HTTPS) {
4661
-                $SCHEME = 'https';
4662
-            } else {
4663
-                $SCHEME = 'http';
4664
-            }
4665
-            $endpoint = "$SCHEME://$SERVER_NAME$SERVER_PORT$SCRIPT_NAME";
4666
-        }
4667
-
4668
-        if (false == $schemaTargetNamespace) {
4669
-            $schemaTargetNamespace = $namespace;
4670
-        }
4671
-
4672
-        $this->wsdl = new wsdl;
4673
-        $this->wsdl->serviceName = $serviceName;
4674
-        $this->wsdl->endpoint = $endpoint;
4675
-        $this->wsdl->namespaces['tns'] = $namespace;
4676
-        $this->wsdl->namespaces['soap'] = 'http://schemas.xmlsoap.org/wsdl/soap/';
4677
-        $this->wsdl->namespaces['wsdl'] = 'http://schemas.xmlsoap.org/wsdl/';
4678
-        if ($schemaTargetNamespace != $namespace) {
4679
-            $this->wsdl->namespaces['types'] = $schemaTargetNamespace;
4680
-        }
4681
-        $this->wsdl->schemas[$schemaTargetNamespace][0] = new nusoap_xmlschema('', '', $this->wsdl->namespaces);
4682
-        if ('document' === $style) {
4683
-            $this->wsdl->schemas[$schemaTargetNamespace][0]->schemaInfo['elementFormDefault'] = 'qualified';
4684
-        }
4685
-        $this->wsdl->schemas[$schemaTargetNamespace][0]->schemaTargetNamespace = $schemaTargetNamespace;
4686
-        $this->wsdl->schemas[$schemaTargetNamespace][0]->imports['http://schemas.xmlsoap.org/soap/encoding/'][0] = ['location' => '', 'loaded' => true];
4687
-        $this->wsdl->schemas[$schemaTargetNamespace][0]->imports['http://schemas.xmlsoap.org/wsdl/'][0] = ['location' => '', 'loaded' => true];
4688
-        $this->wsdl->bindings[$serviceName . 'Binding'] = [
4689
-            'name' => $serviceName . 'Binding',
4690
-            'style' => $style,
4691
-            'transport' => $transport,
4692
-            'portType' => $serviceName . 'PortType'
4693
-        ];
4694
-        $this->wsdl->ports[$serviceName . 'Port'] = [
4695
-            'binding' => $serviceName . 'Binding',
4696
-            'location' => $endpoint,
4697
-            'bindingType' => 'http://schemas.xmlsoap.org/wsdl/soap/'
4698
-        ];
4699
-    }
3788
+	/**
3789
+	 * processes request and returns response
3790
+	 *
3791
+	 * @param    string $data usually is the value of $HTTP_RAW_POST_DATA
3792
+	 * @access   public
3793
+	 */
3794
+	public function service($data)
3795
+	{
3796
+		global $HTTP_SERVER_VARS;
3797
+
3798
+		if (isset($_SERVER['REQUEST_METHOD'])) {
3799
+			$rm = $_SERVER['REQUEST_METHOD'];
3800
+		} elseif (isset($HTTP_SERVER_VARS['REQUEST_METHOD'])) {
3801
+			$rm = $HTTP_SERVER_VARS['REQUEST_METHOD'];
3802
+		} else {
3803
+			$rm = '';
3804
+		}
3805
+
3806
+		if (isset($_SERVER['QUERY_STRING'])) {
3807
+			$qs = $_SERVER['QUERY_STRING'];
3808
+		} elseif (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
3809
+			$qs = $HTTP_SERVER_VARS['QUERY_STRING'];
3810
+		} else {
3811
+			$qs = '';
3812
+		}
3813
+		$this->debug("In service, request method=$rm query string=$qs strlen(\$data)=" . strlen($data));
3814
+
3815
+		if ('POST' === $rm) {
3816
+			$this->debug('In service, invoke the request');
3817
+			$this->parse_request($data);
3818
+			if (!$this->fault) {
3819
+				$this->invoke_method();
3820
+			}
3821
+			if (!$this->fault) {
3822
+				$this->serialize_return();
3823
+			}
3824
+			$this->send_response();
3825
+		} elseif (preg_match('/wsdl/', $qs)) {
3826
+			$this->debug('In service, this is a request for WSDL');
3827
+			if ($this->externalWSDLURL) {
3828
+				if (false !== strpos($this->externalWSDLURL, 'http://')) { // assume URL
3829
+					$this->debug('In service, re-direct for WSDL');
3830
+					header('Location: ' . $this->externalWSDLURL);
3831
+				} else { // assume file
3832
+					$this->debug('In service, use file passthru for WSDL');
3833
+					header("Content-Type: text/xml\r\n");
3834
+					$pos = strpos($this->externalWSDLURL, 'file://');
3835
+					if (false === $pos) {
3836
+						$filename = $this->externalWSDLURL;
3837
+					} else {
3838
+						$filename = substr($this->externalWSDLURL, $pos + 7);
3839
+					}
3840
+					$fp = fopen($this->externalWSDLURL, 'r');
3841
+					fpassthru($fp);
3842
+				}
3843
+			} elseif ($this->wsdl) {
3844
+				$this->debug('In service, serialize WSDL');
3845
+				header("Content-Type: text/xml; charset=ISO-8859-1\r\n");
3846
+				print $this->wsdl->serialize($this->debug_flag);
3847
+				if ($this->debug_flag) {
3848
+					$this->debug('wsdl:');
3849
+					$this->appendDebug($this->varDump($this->wsdl));
3850
+					print $this->getDebugAsXMLComment();
3851
+				}
3852
+			} else {
3853
+				$this->debug('In service, there is no WSDL');
3854
+				header("Content-Type: text/html; charset=ISO-8859-1\r\n");
3855
+				print 'This service does not provide WSDL';
3856
+			}
3857
+		} elseif ($this->wsdl) {
3858
+			$this->debug('In service, return Web description');
3859
+			print $this->wsdl->webDescription();
3860
+		} else {
3861
+			$this->debug('In service, no Web description');
3862
+			header("Content-Type: text/html; charset=ISO-8859-1\r\n");
3863
+			print 'This service does not provide a Web description';
3864
+		}
3865
+	}
3866
+
3867
+	/**
3868
+	 * parses HTTP request headers.
3869
+	 *
3870
+	 * The following fields are set by this function (when successful)
3871
+	 *
3872
+	 * headers
3873
+	 * request
3874
+	 * xml_encoding
3875
+	 * SOAPAction
3876
+	 *
3877
+	 * @access   private
3878
+	 */
3879
+	private function parse_http_headers()
3880
+	{
3881
+		global $HTTP_SERVER_VARS;
3882
+
3883
+		$this->request = '';
3884
+		$this->SOAPAction = '';
3885
+		if (function_exists('getallheaders')) {
3886
+			$this->debug('In parse_http_headers, use getallheaders');
3887
+			$headers = getallheaders();
3888
+			foreach ($headers as $k => $v) {
3889
+				$k = strtolower($k);
3890
+				$this->headers[$k] = $v;
3891
+				$this->request .= "$k: $v\r\n";
3892
+				$this->debug("$k: $v");
3893
+			}
3894
+			// get SOAPAction header
3895
+			if (isset($this->headers['soapaction'])) {
3896
+				$this->SOAPAction = str_replace('"', '', $this->headers['soapaction']);
3897
+			}
3898
+			// get the character encoding of the incoming request
3899
+			if (isset($this->headers['content-type']) && strpos($this->headers['content-type'], '=')) {
3900
+				$enc = str_replace('"', '', substr(strstr($this->headers['content-type'], '='), 1));
3901
+				if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i', $enc)) {
3902
+					$this->xml_encoding = strtoupper($enc);
3903
+				} else {
3904
+					$this->xml_encoding = 'US-ASCII';
3905
+				}
3906
+			} else {
3907
+				// should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
3908
+				$this->xml_encoding = 'ISO-8859-1';
3909
+			}
3910
+		} elseif (isset($_SERVER) && is_array($_SERVER)) {
3911
+			$this->debug('In parse_http_headers, use _SERVER');
3912
+			foreach ($_SERVER as $k => $v) {
3913
+				if (0 === strpos($k, 'HTTP_')) {
3914
+					$k = str_replace(' ', '-', strtolower(str_replace('_', ' ', substr($k, 5))));
3915
+				} else {
3916
+					$k = str_replace(' ', '-', strtolower(str_replace('_', ' ', $k)));
3917
+				}
3918
+				if ('soapaction' === $k) {
3919
+					// get SOAPAction header
3920
+					$k = 'SOAPAction';
3921
+					$v = str_replace('"', '', $v);
3922
+					$v = str_replace('\\', '', $v);
3923
+					$this->SOAPAction = $v;
3924
+				} elseif ('content-type' === $k) {
3925
+					// get the character encoding of the incoming request
3926
+					if (strpos($v, '=')) {
3927
+						$enc = substr(strstr($v, '='), 1);
3928
+						$enc = str_replace('"', '', $enc);
3929
+						$enc = str_replace('\\', '', $enc);
3930
+						if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i', $enc)) {
3931
+							$this->xml_encoding = strtoupper($enc);
3932
+						} else {
3933
+							$this->xml_encoding = 'US-ASCII';
3934
+						}
3935
+					} else {
3936
+						// should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
3937
+						$this->xml_encoding = 'ISO-8859-1';
3938
+					}
3939
+				}
3940
+				$this->headers[$k] = $v;
3941
+				$this->request .= "$k: $v\r\n";
3942
+				$this->debug("$k: $v");
3943
+			}
3944
+		} elseif (is_array($HTTP_SERVER_VARS)) {
3945
+			$this->debug('In parse_http_headers, use HTTP_SERVER_VARS');
3946
+			foreach ($HTTP_SERVER_VARS as $k => $v) {
3947
+				if (0 === strpos($k, 'HTTP_')) {
3948
+					$k = str_replace(' ', '-', strtolower(str_replace('_', ' ', substr($k, 5))));
3949
+					$k = strtolower(substr($k, 5));
3950
+				} else {
3951
+					$k = str_replace(' ', '-', strtolower(str_replace('_', ' ', $k)));
3952
+					$k = strtolower($k);
3953
+				}
3954
+				if ('soapaction' === $k) {
3955
+					// get SOAPAction header
3956
+					$k = 'SOAPAction';
3957
+					$v = str_replace('"', '', $v);
3958
+					$v = str_replace('\\', '', $v);
3959
+					$this->SOAPAction = $v;
3960
+				} elseif ('content-type' === $k) {
3961
+					// get the character encoding of the incoming request
3962
+					if (strpos($v, '=')) {
3963
+						$enc = substr(strstr($v, '='), 1);
3964
+						$enc = str_replace('"', '', $enc);
3965
+						$enc = str_replace('\\', '', $enc);
3966
+						if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i', $enc)) {
3967
+							$this->xml_encoding = strtoupper($enc);
3968
+						} else {
3969
+							$this->xml_encoding = 'US-ASCII';
3970
+						}
3971
+					} else {
3972
+						// should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
3973
+						$this->xml_encoding = 'ISO-8859-1';
3974
+					}
3975
+				}
3976
+				$this->headers[$k] = $v;
3977
+				$this->request .= "$k: $v\r\n";
3978
+				$this->debug("$k: $v");
3979
+			}
3980
+		} else {
3981
+			$this->debug('In parse_http_headers, HTTP headers not accessible');
3982
+			$this->setError('HTTP headers not accessible');
3983
+		}
3984
+	}
3985
+
3986
+	/**
3987
+	 * parses a request
3988
+	 *
3989
+	 * The following fields are set by this function (when successful)
3990
+	 *
3991
+	 * headers
3992
+	 * request
3993
+	 * xml_encoding
3994
+	 * SOAPAction
3995
+	 * request
3996
+	 * requestSOAP
3997
+	 * methodURI
3998
+	 * methodname
3999
+	 * methodparams
4000
+	 * requestHeaders
4001
+	 * document
4002
+	 *
4003
+	 * This sets the fault field on error
4004
+	 *
4005
+	 * @param    string $data XML string
4006
+	 * @access   private
4007
+	 */
4008
+	private function parse_request($data = '')
4009
+	{
4010
+		$this->debug('entering parse_request()');
4011
+		$this->parse_http_headers();
4012
+		$this->debug('got character encoding: ' . $this->xml_encoding);
4013
+		// uncompress if necessary
4014
+		if (isset($this->headers['content-encoding']) && '' != $this->headers['content-encoding']) {
4015
+			$this->debug('got content encoding: ' . $this->headers['content-encoding']);
4016
+			if ('deflate' === $this->headers['content-encoding'] || 'gzip' === $this->headers['content-encoding']) {
4017
+				// if decoding works, use it. else assume data wasn't gzencoded
4018
+				if (function_exists('gzuncompress')) {
4019
+					if ('deflate' === $this->headers['content-encoding'] && $degzdata = @gzuncompress($data)) {
4020
+						$data = $degzdata;
4021
+					} elseif ('gzip' === $this->headers['content-encoding'] && $degzdata = gzinflate(substr($data, 10))) {
4022
+						$data = $degzdata;
4023
+					} else {
4024
+						$this->fault('SOAP-ENV:Client', 'Errors occurred when trying to decode the data');
4025
+						return;
4026
+					}
4027
+				} else {
4028
+					$this->fault('SOAP-ENV:Client', 'This Server does not support compressed data');
4029
+					return;
4030
+				}
4031
+			}
4032
+		}
4033
+		$this->request .= "\r\n" . $data;
4034
+		$data = $this->parseRequest($this->headers, $data);
4035
+		$this->requestSOAP = $data;
4036
+		$this->debug('leaving parse_request');
4037
+	}
4038
+
4039
+	/**
4040
+	 * invokes a PHP function for the requested SOAP method
4041
+	 *
4042
+	 * The following fields are set by this function (when successful)
4043
+	 *
4044
+	 * methodreturn
4045
+	 *
4046
+	 * Note that the PHP function that is called may also set the following
4047
+	 * fields to affect the response sent to the client
4048
+	 *
4049
+	 * responseHeaders
4050
+	 * outgoing_headers
4051
+	 *
4052
+	 * This sets the fault field on error
4053
+	 *
4054
+	 * @access   private
4055
+	 */
4056
+	private function invoke_method()
4057
+	{
4058
+		$this->debug('in invoke_method, methodname=' . $this->methodname . ' methodURI=' . $this->methodURI . ' SOAPAction=' . $this->SOAPAction);
4059
+
4060
+		//
4061
+		// if you are debugging in this area of the code, your service uses a class to implement methods,
4062
+		// you use SOAP RPC, and the client is .NET, please be aware of the following...
4063
+		// when the .NET wsdl.exe utility generates a proxy, it will remove the '.' or '..' from the
4064
+		// method name.  that is fine for naming the .NET methods.  it is not fine for properly constructing
4065
+		// the XML request and reading the XML response.  you need to add the RequestElementName and
4066
+		// ResponseElementName to the System.Web.Services.Protocols.SoapRpcMethodAttribute that wsdl.exe
4067
+		// generates for the method.  these parameters are used to specify the correct XML element names
4068
+		// for .NET to use, i.e. the names with the '.' in them.
4069
+		//
4070
+		$orig_methodname = $this->methodname;
4071
+		if ($this->wsdl) {
4072
+			if (false !== ($this->opData = $this->wsdl->getOperationData($this->methodname))) {
4073
+				$this->debug('in invoke_method, found WSDL operation=' . $this->methodname);
4074
+				$this->appendDebug('opData=' . $this->varDump($this->opData));
4075
+			} elseif (false !== ($this->opData = $this->wsdl->getOperationDataForSoapAction($this->SOAPAction))) {
4076
+				// Note: hopefully this case will only be used for doc/lit, since rpc services should have wrapper element
4077
+				$this->debug('in invoke_method, found WSDL soapAction=' . $this->SOAPAction . ' for operation=' . $this->opData['name']);
4078
+				$this->appendDebug('opData=' . $this->varDump($this->opData));
4079
+				$this->methodname = $this->opData['name'];
4080
+			} else {
4081
+				$this->debug('in invoke_method, no WSDL for operation=' . $this->methodname);
4082
+				$this->fault('SOAP-ENV:Client', "Operation '" . $this->methodname . "' is not defined in the WSDL for this service");
4083
+				return;
4084
+			}
4085
+		} else {
4086
+			$this->debug('in invoke_method, no WSDL to validate method');
4087
+		}
4088
+
4089
+		// if a . is present in $this->methodname, we see if there is a class in scope,
4090
+		// which could be referred to. We will also distinguish between two deliminators,
4091
+		// to allow methods to be called a the class or an instance
4092
+		if (strpos($this->methodname, '..') > 0) {
4093
+			$delim = '..';
4094
+		} elseif (strpos($this->methodname, '.') > 0) {
4095
+			$delim = '.';
4096
+		} else {
4097
+			$delim = '';
4098
+		}
4099
+		$this->debug("in invoke_method, delim=$delim");
4100
+
4101
+		$class = '';
4102
+		$method = '';
4103
+		if (strlen($delim) > 0 && 1 == substr_count($this->methodname, $delim)) {
4104
+			$try_class = substr($this->methodname, 0, strpos($this->methodname, $delim));
4105
+			if (class_exists($try_class)) {
4106
+				// get the class and method name
4107
+				$class = $try_class;
4108
+				$method = substr($this->methodname, strpos($this->methodname, $delim) + strlen($delim));
4109
+				$this->debug("in invoke_method, class=$class method=$method delim=$delim");
4110
+			} else {
4111
+				$this->debug("in invoke_method, class=$try_class not found");
4112
+			}
4113
+		} elseif (strlen($delim) > 0 && substr_count($this->methodname, $delim) > 1) {
4114
+			$split = explode($delim, $this->methodname);
4115
+			$method = array_pop($split);
4116
+			$class = implode('\\', $split);
4117
+		} else {
4118
+			$try_class = '';
4119
+			$this->debug('in invoke_method, no class to try');
4120
+		}
4121
+
4122
+		// does method exist?
4123
+		if ('' == $class) {
4124
+			if (!function_exists($this->methodname)) {
4125
+				$this->debug("in invoke_method, function '$this->methodname' not found!");
4126
+				$this->result = 'fault: method not found';
4127
+				$this->fault('SOAP-ENV:Client', "method '$this->methodname'('$orig_methodname') not defined in service('$try_class' '$delim')");
4128
+				return;
4129
+			}
4130
+		} else {
4131
+			$method_to_compare = (0 === strpos(phpversion(), '4.')) ? strtolower($method) : $method;
4132
+			if (!in_array($method_to_compare, get_class_methods($class))) {
4133
+				$this->debug("in invoke_method, method '$this->methodname' not found in class '$class'!");
4134
+				$this->result = 'fault: method not found';
4135
+				$this->fault('SOAP-ENV:Client', "method '$this->methodname'/'$method_to_compare'('$orig_methodname') not defined in service/'$class'('$try_class' '$delim')");
4136
+				return;
4137
+			}
4138
+		}
4139
+
4140
+		// evaluate message, getting back parameters
4141
+		// verify that request parameters match the method's signature
4142
+		if (!$this->verify_method($this->methodname, $this->methodparams)) {
4143
+			// debug
4144
+			$this->debug('ERROR: request not verified against method signature');
4145
+			$this->result = 'fault: request failed validation against method signature';
4146
+			// return fault
4147
+			$this->fault('SOAP-ENV:Client', "Operation '$this->methodname' not defined in service.");
4148
+			return;
4149
+		}
4150
+
4151
+		// if there are parameters to pass
4152
+		$this->debug('in invoke_method, params:');
4153
+		$this->appendDebug($this->varDump($this->methodparams));
4154
+		$this->debug("in invoke_method, calling '$this->methodname'");
4155
+		if (!function_exists('call_user_func_array')) {
4156
+			if ('' == $class) {
4157
+				$this->debug('in invoke_method, calling function using eval()');
4158
+				$funcCall = "\$this->methodreturn = $this->methodname(";
4159
+			} else {
4160
+				if ('..' === $delim) {
4161
+					$this->debug('in invoke_method, calling class method using eval()');
4162
+					$funcCall = '$this->methodreturn = ' . $class . '::' . $method . '(';
4163
+				} else {
4164
+					$this->debug('in invoke_method, calling instance method using eval()');
4165
+					// generate unique instance name
4166
+					$instname = '$inst_' . time();
4167
+					$funcCall = $instname . ' = new ' . $class . '(); ';
4168
+					$funcCall .= '$this->methodreturn = ' . $instname . '->' . $method . '(';
4169
+				}
4170
+			}
4171
+			if ($this->methodparams) {
4172
+				foreach ($this->methodparams as $param) {
4173
+					if (is_array($param) || is_object($param)) {
4174
+						$this->fault('SOAP-ENV:Client', 'NuSOAP does not handle complexType parameters correctly when using eval; call_user_func_array must be available');
4175
+						return;
4176
+					}
4177
+					$funcCall .= "\"$param\",";
4178
+				}
4179
+				$funcCall = substr($funcCall, 0, -1);
4180
+			}
4181
+			$funcCall .= ');';
4182
+			$this->debug('in invoke_method, function call: ' . $funcCall);
4183
+			@eval($funcCall);
4184
+		} else {
4185
+			if ('' == $class) {
4186
+				$this->debug('in invoke_method, calling function using call_user_func_array()');
4187
+				$call_arg = $this->methodname;    // straight assignment changes $this->methodname to lower case after call_user_func_array()
4188
+			} elseif ('..' === $delim) {
4189
+				$this->debug('in invoke_method, calling class method using call_user_func_array()');
4190
+				$call_arg = [$class, $method];
4191
+			} else {
4192
+				$this->debug('in invoke_method, calling instance method using call_user_func_array()');
4193
+				$instance = new $class();
4194
+				$call_arg = [&$instance, $method];
4195
+			}
4196
+			if (is_array($this->methodparams)) {
4197
+				$this->methodreturn = call_user_func_array($call_arg, array_values($this->methodparams));
4198
+			} else {
4199
+				$this->methodreturn = call_user_func_array($call_arg, []);
4200
+			}
4201
+		}
4202
+		$this->debug('in invoke_method, methodreturn:');
4203
+		$this->appendDebug($this->varDump($this->methodreturn));
4204
+		$this->debug("in invoke_method, called method $this->methodname, received data of type " . gettype($this->methodreturn));
4205
+	}
4206
+
4207
+	/**
4208
+	 * serializes the return value from a PHP function into a full SOAP Envelope
4209
+	 *
4210
+	 * The following fields are set by this function (when successful)
4211
+	 *
4212
+	 * responseSOAP
4213
+	 *
4214
+	 * This sets the fault field on error
4215
+	 *
4216
+	 * @access   private
4217
+	 */
4218
+	private function serialize_return()
4219
+	{
4220
+		$this->debug('Entering serialize_return methodname: ' . $this->methodname . ' methodURI: ' . $this->methodURI);
4221
+		// if fault
4222
+		if (isset($this->methodreturn) && is_object($this->methodreturn) && (('soap_fault' === get_class($this->methodreturn)) || ('nusoap_fault' === get_class($this->methodreturn)))) {
4223
+			$this->debug('got a fault object from method');
4224
+			$this->fault = $this->methodreturn;
4225
+			return;
4226
+		} elseif ($this->methodreturnisliteralxml) {
4227
+			$return_val = $this->methodreturn;
4228
+		// returned value(s)
4229
+		} else {
4230
+			$this->debug('got a(n) ' . gettype($this->methodreturn) . ' from method');
4231
+			$this->debug('serializing return value');
4232
+			if ($this->wsdl) {
4233
+				if (is_array($this->opData['output']['parts']) && count($this->opData['output']['parts']) > 1) {
4234
+					$this->debug('more than one output part, so use the method return unchanged');
4235
+					$opParams = $this->methodreturn;
4236
+				} elseif (1 == count($this->opData['output']['parts'])) {
4237
+					$this->debug('exactly one output part, so wrap the method return in a simple array');
4238
+					// TODO: verify that it is not already wrapped!
4239
+					//foreach ($this->opData['output']['parts'] as $name => $type) {
4240
+					//	$this->debug('wrap in element named ' . $name);
4241
+					//}
4242
+					$opParams = [$this->methodreturn];
4243
+				}
4244
+				$return_val = $this->wsdl->serializeRPCParameters($this->methodname, 'output', $opParams);
4245
+				$this->appendDebug($this->wsdl->getDebug());
4246
+				$this->wsdl->clearDebug();
4247
+				if (false !== ($errstr = $this->wsdl->getError())) {
4248
+					$this->debug('got wsdl error: ' . $errstr);
4249
+					$this->fault('SOAP-ENV:Server', 'unable to serialize result');
4250
+					return;
4251
+				}
4252
+			} else {
4253
+				if (isset($this->methodreturn)) {
4254
+					$return_val = $this->serialize_val($this->methodreturn, 'return');
4255
+				} else {
4256
+					$return_val = '';
4257
+					$this->debug('in absence of WSDL, assume void return for backward compatibility');
4258
+				}
4259
+			}
4260
+		}
4261
+		$this->debug('return value:');
4262
+		$this->appendDebug($this->varDump($return_val));
4263
+
4264
+		$this->debug('serializing response');
4265
+		if ($this->wsdl) {
4266
+			$this->debug('have WSDL for serialization: style is ' . $this->opData['style']);
4267
+			if ('rpc' === $this->opData['style']) {
4268
+				$this->debug('style is rpc for serialization: use is ' . $this->opData['output']['use']);
4269
+				if ('literal' === $this->opData['output']['use']) {
4270
+					// http://www.ws-i.org/Profiles/BasicProfile-1.1-2004-08-24.html R2735 says rpc/literal accessor elements should not be in a namespace
4271
+					if ($this->methodURI) {
4272
+						$payload = '<ns1:' . $this->methodname . 'Response xmlns:ns1="' . $this->methodURI . '">' . $return_val . '</ns1:' . $this->methodname . 'Response>';
4273
+					} else {
4274
+						$payload = '<' . $this->methodname . 'Response>' . $return_val . '</' . $this->methodname . 'Response>';
4275
+					}
4276
+				} else {
4277
+					if ($this->methodURI) {
4278
+						$payload = '<ns1:' . $this->methodname . 'Response xmlns:ns1="' . $this->methodURI . '">' . $return_val . '</ns1:' . $this->methodname . 'Response>';
4279
+					} else {
4280
+						$payload = '<' . $this->methodname . 'Response>' . $return_val . '</' . $this->methodname . 'Response>';
4281
+					}
4282
+				}
4283
+			} else {
4284
+				$this->debug('style is not rpc for serialization: assume document');
4285
+				$payload = $return_val;
4286
+			}
4287
+		} else {
4288
+			$this->debug('do not have WSDL for serialization: assume rpc/encoded');
4289
+			$payload = '<ns1:' . $this->methodname . 'Response xmlns:ns1="' . $this->methodURI . '">' . $return_val . '</ns1:' . $this->methodname . 'Response>';
4290
+		}
4291
+		$this->result = 'successful';
4292
+		if ($this->wsdl) {
4293
+			//if($this->debug_flag){
4294
+			$this->appendDebug($this->wsdl->getDebug());
4295
+			//	}
4296
+			if (isset($this->opData['output']['encodingStyle'])) {
4297
+				$encodingStyle = $this->opData['output']['encodingStyle'];
4298
+			} else {
4299
+				$encodingStyle = '';
4300
+			}
4301
+			// Added: In case we use a WSDL, return a serialized env. WITH the usedNamespaces.
4302
+			$this->responseSOAP = $this->serializeEnvelope($payload, $this->responseHeaders, $this->wsdl->usedNamespaces, $this->opData['style'], $this->opData['output']['use'], $encodingStyle);
4303
+		} else {
4304
+			$this->responseSOAP = $this->serializeEnvelope($payload, $this->responseHeaders);
4305
+		}
4306
+		$this->debug('Leaving serialize_return');
4307
+	}
4308
+
4309
+	/**
4310
+	 * sends an HTTP response
4311
+	 *
4312
+	 * The following fields are set by this function (when successful)
4313
+	 *
4314
+	 * outgoing_headers
4315
+	 * response
4316
+	 *
4317
+	 * @access   private
4318
+	 */
4319
+	private function send_response()
4320
+	{
4321
+		$this->debug('Enter send_response');
4322
+		if ($this->fault) {
4323
+			$payload = $this->fault->serialize();
4324
+			$this->outgoing_headers[] = 'HTTP/1.0 500 Internal Server Error';
4325
+			$this->outgoing_headers[] = 'Status: 500 Internal Server Error';
4326
+		} else {
4327
+			$payload = $this->responseSOAP;
4328
+			// Some combinations of PHP+Web server allow the Status
4329
+			// to come through as a header.  Since OK is the default
4330
+			// just do nothing.
4331
+			// $this->outgoing_headers[] = "HTTP/1.0 200 OK";
4332
+			// $this->outgoing_headers[] = "Status: 200 OK";
4333
+		}
4334
+		// add debug data if in debug mode
4335
+		if (isset($this->debug_flag) && $this->debug_flag) {
4336
+			$payload .= $this->getDebugAsXMLComment();
4337
+		}
4338
+		$this->outgoing_headers[] = "Server: $this->title Server v$this->version";
4339
+		preg_match('/\$Revisio' . 'n: ([^ ]+)/', $this->revision, $rev);
4340
+		$this->outgoing_headers[] = "X-SOAP-Server: $this->title/$this->version (" . $rev[1] . ')';
4341
+		// Let the Web server decide about this
4342
+		//$this->outgoing_headers[] = "Connection: Close\r\n";
4343
+		$payload = $this->getHTTPBody($payload);
4344
+		$type = $this->getHTTPContentType();
4345
+		$charset = $this->getHTTPContentTypeCharset();
4346
+		$this->outgoing_headers[] = "Content-Type: $type" . ($charset ? '; charset=' . $charset : '');
4347
+		//begin code to compress payload - by John
4348
+		// NOTE: there is no way to know whether the Web server will also compress
4349
+		// this data.
4350
+		if (strlen($payload) > 1024 && isset($this->headers) && isset($this->headers['accept-encoding'])) {
4351
+			if (false !== strpos($this->headers['accept-encoding'], 'gzip')) {
4352
+				if (function_exists('gzencode')) {
4353
+					if (isset($this->debug_flag) && $this->debug_flag) {
4354
+						$payload .= '<!-- Content being gzipped -->';
4355
+					}
4356
+					$this->outgoing_headers[] = 'Content-Encoding: gzip';
4357
+					$payload = gzencode($payload);
4358
+				} else {
4359
+					if (isset($this->debug_flag) && $this->debug_flag) {
4360
+						$payload .= '<!-- Content will not be gzipped: no gzencode -->';
4361
+					}
4362
+				}
4363
+			} elseif (false !== strpos($this->headers['accept-encoding'], 'deflate')) {
4364
+				// Note: MSIE requires gzdeflate output (no Zlib header and checksum),
4365
+				// instead of gzcompress output,
4366
+				// which conflicts with HTTP 1.1 spec (http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.5)
4367
+				if (function_exists('gzdeflate')) {
4368
+					if (isset($this->debug_flag) && $this->debug_flag) {
4369
+						$payload .= '<!-- Content being deflated -->';
4370
+					}
4371
+					$this->outgoing_headers[] = 'Content-Encoding: deflate';
4372
+					$payload = gzdeflate($payload);
4373
+				} else {
4374
+					if (isset($this->debug_flag) && $this->debug_flag) {
4375
+						$payload .= '<!-- Content will not be deflated: no gzcompress -->';
4376
+					}
4377
+				}
4378
+			}
4379
+		}
4380
+		//end code
4381
+		$this->outgoing_headers[] = 'Content-Length: ' . strlen($payload);
4382
+		reset($this->outgoing_headers);
4383
+		foreach ($this->outgoing_headers as $hdr) {
4384
+			header($hdr, false);
4385
+		}
4386
+		print $payload;
4387
+		$this->response = implode("\r\n", $this->outgoing_headers) . "\r\n\r\n" . $payload;
4388
+	}
4389
+
4390
+	/**
4391
+	 * takes the value that was created by parsing the request
4392
+	 * and compares to the method's signature, if available.
4393
+	 *
4394
+	 * @param    string $operation The operation to be invoked
4395
+	 * @param    array $request The array of parameter values
4396
+	 * @return    boolean    Whether the operation was found
4397
+	 * @access   private
4398
+	 */
4399
+	private function verify_method($operation, $request)
4400
+	{
4401
+		if (isset($this->wsdl) && is_object($this->wsdl)) {
4402
+			if ($this->wsdl->getOperationData($operation)) {
4403
+				return true;
4404
+			}
4405
+		} elseif (isset($this->operations[$operation])) {
4406
+			return true;
4407
+		}
4408
+		return false;
4409
+	}
4410
+
4411
+	/**
4412
+	 * processes SOAP message received from client
4413
+	 *
4414
+	 * @param    array $headers The HTTP headers
4415
+	 * @param    string $data unprocessed request data from client
4416
+	 * @return    mixed    value of the message, decoded into a PHP type
4417
+	 * @access   private
4418
+	 */
4419
+	private function parseRequest($headers, $data)
4420
+	{
4421
+		$this->debug('Entering parseRequest() for data of length ' . strlen($data) . ' headers:');
4422
+		$this->appendDebug($this->varDump($headers));
4423
+		if (!isset($headers['content-type'])) {
4424
+			$this->setError('Request not of type text/xml (no content-type header)');
4425
+			return false;
4426
+		}
4427
+		if (false === strpos($headers['content-type'], 'text/xml')) {
4428
+			$this->setError('Request not of type text/xml');
4429
+			return false;
4430
+		}
4431
+		if (strpos($headers['content-type'], '=')) {
4432
+			$enc = str_replace('"', '', substr(strstr($headers['content-type'], '='), 1));
4433
+			$this->debug('Got response encoding: ' . $enc);
4434
+			if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i', $enc)) {
4435
+				$this->xml_encoding = strtoupper($enc);
4436
+			} else {
4437
+				$this->xml_encoding = 'US-ASCII';
4438
+			}
4439
+		} else {
4440
+			// should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
4441
+			$this->xml_encoding = 'ISO-8859-1';
4442
+		}
4443
+		$this->debug('Use encoding: ' . $this->xml_encoding . ' when creating nusoap_parser');
4444
+		// parse response, get soap parser obj
4445
+		$parser = new nusoap_parser($data, $this->xml_encoding, '', $this->decode_utf8);
4446
+		// parser debug
4447
+		$this->debug("parser debug: \n" . $parser->getDebug());
4448
+		// if fault occurred during message parsing
4449
+		if (false !== ($err = $parser->getError())) {
4450
+			$this->result = 'fault: error in msg parsing: ' . $err;
4451
+			$this->fault('SOAP-ENV:Client', "error in msg parsing:\n" . $err);
4452
+		// else successfully parsed request into soapval object
4453
+		} else {
4454
+			// get/set methodname
4455
+			$this->methodURI = $parser->root_struct_namespace;
4456
+			$this->methodname = $parser->root_struct_name;
4457
+			$this->debug('methodname: ' . $this->methodname . ' methodURI: ' . $this->methodURI);
4458
+			$this->debug('calling parser->get_soapbody()');
4459
+			$this->methodparams = $parser->get_soapbody();
4460
+			// get SOAP headers
4461
+			$this->requestHeaders = $parser->getHeaders();
4462
+			// get SOAP Header
4463
+			$this->requestHeader = $parser->get_soapheader();
4464
+			// add document for doclit support
4465
+			$this->document = $parser->document;
4466
+		}
4467
+	}
4468
+
4469
+	/**
4470
+	 * gets the HTTP body for the current response.
4471
+	 *
4472
+	 * @param string $soapmsg The SOAP payload
4473
+	 * @return string The HTTP body, which includes the SOAP payload
4474
+	 * @access private
4475
+	 */
4476
+	private function getHTTPBody($soapmsg)
4477
+	{
4478
+		return $soapmsg;
4479
+	}
4480
+
4481
+	/**
4482
+	 * gets the HTTP content type for the current response.
4483
+	 *
4484
+	 * Note: getHTTPBody must be called before this.
4485
+	 *
4486
+	 * @return string the HTTP content type for the current response.
4487
+	 * @access private
4488
+	 */
4489
+	private function getHTTPContentType()
4490
+	{
4491
+		return 'text/xml';
4492
+	}
4493
+
4494
+	/**
4495
+	 * gets the HTTP content type charset for the current response.
4496
+	 * returns false for non-text content types.
4497
+	 *
4498
+	 * Note: getHTTPBody must be called before this.
4499
+	 *
4500
+	 * @return string the HTTP content type charset for the current response.
4501
+	 * @access private
4502
+	 */
4503
+	private function getHTTPContentTypeCharset()
4504
+	{
4505
+		return $this->soap_defencoding;
4506
+	}
4507
+
4508
+	/**
4509
+	 * add a method to the dispatch map (this has been replaced by the register method)
4510
+	 *
4511
+	 * @param    string $methodname
4512
+	 * @param    string $in array of input values
4513
+	 * @param    string $out array of output values
4514
+	 * @access   public
4515
+	 * @deprecated
4516
+	 */
4517
+	public function add_to_map($methodname, $in, $out)
4518
+	{
4519
+		$this->operations[$methodname] = ['name' => $methodname, 'in' => $in, 'out' => $out];
4520
+	}
4521
+
4522
+	/**
4523
+	 * register a service function with the server
4524
+	 *
4525
+	 * @param    string $name          the name of the PHP function, class.method or class..method
4526
+	 * @param    array  $in            assoc array of input values: key = param name, value = param type
4527
+	 * @param    array  $out           assoc array of output values: key = param name, value = param type
4528
+	 * @param    mixed  $namespace     the element namespace for the method or false
4529
+	 * @param    mixed  $soapaction    the soapaction for the method or false
4530
+	 * @param    mixed  $style         optional (rpc|document) or false Note: when 'document' is specified, parameter and return wrappers are created for you automatically
4531
+	 * @param    mixed  $use           optional (encoded|literal) or false
4532
+	 * @param    string $documentation optional Description to include in WSDL
4533
+	 * @param    string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
4534
+	 * @access   public
4535
+	 * @return bool
4536
+	 */
4537
+	public function register($name, $in = [], $out = [], $namespace = false, $soapaction = false, $style = false, $use = false, $documentation = '', $encodingStyle = '')
4538
+	{
4539
+		global $HTTP_SERVER_VARS;
4540
+
4541
+		if ($this->externalWSDLURL) {
4542
+			die('You cannot bind to an external WSDL file, and register methods outside of it! Please choose either WSDL or no WSDL.');
4543
+		}
4544
+		if (!$name) {
4545
+			die('You must specify a name when you register an operation');
4546
+		}
4547
+		if (!is_array($in)) {
4548
+			die('You must provide an array for operation inputs');
4549
+		}
4550
+		if (!is_array($out)) {
4551
+			die('You must provide an array for operation outputs');
4552
+		}
4553
+		if (false == $namespace) {
4554
+		}
4555
+		if (false == $soapaction) {
4556
+			if (isset($_SERVER)) {
4557
+				$SERVER_NAME = $_SERVER['SERVER_NAME'];
4558
+				$SCRIPT_NAME = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
4559
+				$HTTPS = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : (isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off');
4560
+			} elseif (isset($HTTP_SERVER_VARS)) {
4561
+				$SERVER_NAME = $HTTP_SERVER_VARS['SERVER_NAME'];
4562
+				$SCRIPT_NAME = isset($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : $HTTP_SERVER_VARS['SCRIPT_NAME'];
4563
+				$HTTPS = isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off';
4564
+			} else {
4565
+				$this->setError('Neither _SERVER nor HTTP_SERVER_VARS is available');
4566
+			}
4567
+			if ('1' == $HTTPS || 'on' === $HTTPS) {
4568
+				$SCHEME = 'https';
4569
+			} else {
4570
+				$SCHEME = 'http';
4571
+			}
4572
+			$soapaction = "$SCHEME://$SERVER_NAME$SCRIPT_NAME/$name";
4573
+		}
4574
+		if (false == $style) {
4575
+			$style = 'rpc';
4576
+		}
4577
+		if (false == $use) {
4578
+			$use = 'encoded';
4579
+		}
4580
+		if ('encoded' === $use && '' == $encodingStyle) {
4581
+			$encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
4582
+		}
4583
+
4584
+		$this->operations[$name] = [
4585
+			'name' => $name,
4586
+			'in' => $in,
4587
+			'out' => $out,
4588
+			'namespace' => $namespace,
4589
+			'soapaction' => $soapaction,
4590
+			'style' => $style
4591
+		];
4592
+		if ($this->wsdl) {
4593
+			$this->wsdl->addOperation($name, $in, $out, $namespace, $soapaction, $style, $use, $documentation, $encodingStyle);
4594
+		}
4595
+		return true;
4596
+	}
4597
+
4598
+	/**
4599
+	 * Specify a fault to be returned to the client.
4600
+	 * This also acts as a flag to the server that a fault has occured.
4601
+	 *
4602
+	 * @param    string $faultcode
4603
+	 * @param    string $faultstring
4604
+	 * @param    string $faultactor
4605
+	 * @param    string $faultdetail
4606
+	 * @access   public
4607
+	 */
4608
+	public function fault($faultcode, $faultstring, $faultactor = '', $faultdetail = '')
4609
+	{
4610
+		if ('' == $faultdetail && $this->debug_flag) {
4611
+			$faultdetail = $this->getDebug();
4612
+		}
4613
+		$this->fault = new nusoap_fault($faultcode, $faultactor, $faultstring, $faultdetail);
4614
+		$this->fault->soap_defencoding = $this->soap_defencoding;
4615
+	}
4616
+
4617
+	/**
4618
+	 * Sets up wsdl object.
4619
+	 * Acts as a flag to enable internal WSDL generation
4620
+	 *
4621
+	 * @param string $serviceName , name of the service
4622
+	 * @param mixed $namespace optional 'tns' service namespace or false
4623
+	 * @param mixed $endpoint optional URL of service endpoint or false
4624
+	 * @param string $style optional (rpc|document) WSDL style (also specified by operation)
4625
+	 * @param string $transport optional SOAP transport
4626
+	 * @param mixed $schemaTargetNamespace optional 'types' targetNamespace for service schema or false
4627
+	 */
4628
+	public function configureWSDL($serviceName, $namespace = false, $endpoint = false, $style = 'rpc', $transport = 'http://schemas.xmlsoap.org/soap/http', $schemaTargetNamespace = false)
4629
+	{
4630
+		global $HTTP_SERVER_VARS;
4631
+
4632
+		if (isset($_SERVER)) {
4633
+			$SERVER_NAME = $_SERVER['SERVER_NAME'];
4634
+			$SERVER_PORT = $_SERVER['SERVER_PORT'];
4635
+			$SCRIPT_NAME = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
4636
+			$HTTPS = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : (isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off');
4637
+		} elseif (isset($HTTP_SERVER_VARS)) {
4638
+			$SERVER_NAME = $HTTP_SERVER_VARS['SERVER_NAME'];
4639
+			$SERVER_PORT = $HTTP_SERVER_VARS['SERVER_PORT'];
4640
+			$SCRIPT_NAME = isset($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : $HTTP_SERVER_VARS['SCRIPT_NAME'];
4641
+			$HTTPS = isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off';
4642
+		} else {
4643
+			$this->setError('Neither _SERVER nor HTTP_SERVER_VARS is available');
4644
+		}
4645
+		// If server name has port number attached then strip it (else port number gets duplicated in WSDL output) (occurred using lighttpd and FastCGI)
4646
+		$colon = strpos($SERVER_NAME, ':');
4647
+		if ($colon) {
4648
+			$SERVER_NAME = substr($SERVER_NAME, 0, $colon);
4649
+		}
4650
+		if (80 == $SERVER_PORT) {
4651
+			$SERVER_PORT = '';
4652
+		} else {
4653
+			$SERVER_PORT = ':' . $SERVER_PORT;
4654
+		}
4655
+		if (false == $namespace) {
4656
+			$namespace = "http://$SERVER_NAME/soap/$serviceName";
4657
+		}
4658
+
4659
+		if (false == $endpoint) {
4660
+			if ('1' == $HTTPS || 'on' === $HTTPS) {
4661
+				$SCHEME = 'https';
4662
+			} else {
4663
+				$SCHEME = 'http';
4664
+			}
4665
+			$endpoint = "$SCHEME://$SERVER_NAME$SERVER_PORT$SCRIPT_NAME";
4666
+		}
4667
+
4668
+		if (false == $schemaTargetNamespace) {
4669
+			$schemaTargetNamespace = $namespace;
4670
+		}
4671
+
4672
+		$this->wsdl = new wsdl;
4673
+		$this->wsdl->serviceName = $serviceName;
4674
+		$this->wsdl->endpoint = $endpoint;
4675
+		$this->wsdl->namespaces['tns'] = $namespace;
4676
+		$this->wsdl->namespaces['soap'] = 'http://schemas.xmlsoap.org/wsdl/soap/';
4677
+		$this->wsdl->namespaces['wsdl'] = 'http://schemas.xmlsoap.org/wsdl/';
4678
+		if ($schemaTargetNamespace != $namespace) {
4679
+			$this->wsdl->namespaces['types'] = $schemaTargetNamespace;
4680
+		}
4681
+		$this->wsdl->schemas[$schemaTargetNamespace][0] = new nusoap_xmlschema('', '', $this->wsdl->namespaces);
4682
+		if ('document' === $style) {
4683
+			$this->wsdl->schemas[$schemaTargetNamespace][0]->schemaInfo['elementFormDefault'] = 'qualified';
4684
+		}
4685
+		$this->wsdl->schemas[$schemaTargetNamespace][0]->schemaTargetNamespace = $schemaTargetNamespace;
4686
+		$this->wsdl->schemas[$schemaTargetNamespace][0]->imports['http://schemas.xmlsoap.org/soap/encoding/'][0] = ['location' => '', 'loaded' => true];
4687
+		$this->wsdl->schemas[$schemaTargetNamespace][0]->imports['http://schemas.xmlsoap.org/wsdl/'][0] = ['location' => '', 'loaded' => true];
4688
+		$this->wsdl->bindings[$serviceName . 'Binding'] = [
4689
+			'name' => $serviceName . 'Binding',
4690
+			'style' => $style,
4691
+			'transport' => $transport,
4692
+			'portType' => $serviceName . 'PortType'
4693
+		];
4694
+		$this->wsdl->ports[$serviceName . 'Port'] = [
4695
+			'binding' => $serviceName . 'Binding',
4696
+			'location' => $endpoint,
4697
+			'bindingType' => 'http://schemas.xmlsoap.org/wsdl/soap/'
4698
+		];
4699
+	}
4700 4700
 }
4701 4701
 
4702 4702
 /**
@@ -4718,783 +4718,783 @@  discard block
 block discarded – undo
4718 4718
  */
4719 4719
 class wsdl extends nusoap_base
4720 4720
 {
4721
-    // URL or filename of the root of this WSDL
4722
-    public $wsdl;
4723
-    // define internal arrays of bindings, ports, operations, messages, etc.
4724
-    public $schemas = [];
4725
-    public $currentSchema;
4726
-    public $message = [];
4727
-    public $complexTypes = [];
4728
-    public $messages = [];
4729
-    public $currentMessage;
4730
-    public $currentOperation;
4731
-    public $portTypes = [];
4732
-    public $currentPortType;
4733
-    public $bindings = [];
4734
-    public $currentBinding;
4735
-    public $ports = [];
4736
-    public $currentPort;
4737
-    public $opData = [];
4738
-    public $status = '';
4739
-    public $documentation = false;
4740
-    public $endpoint = '';
4741
-    // array of wsdl docs to import
4742
-    public $import = [];
4743
-    // parser vars
4744
-    public $parser;
4745
-    public $position = 0;
4746
-    public $depth = 0;
4747
-    public $depth_array = [];
4748
-    // for getting wsdl
4749
-    public $proxyhost = '';
4750
-    public $proxyport = '';
4751
-    public $proxyusername = '';
4752
-    public $proxypassword = '';
4753
-    public $timeout = 0;
4754
-    public $response_timeout = 30;
4755
-    public $curl_options = [];    // User-specified cURL options
4756
-    public $use_curl = false;            // whether to always try to use cURL
4757
-    // for HTTP authentication
4758
-    public $username = '';                // Username for HTTP authentication
4759
-    public $password = '';                // Password for HTTP authentication
4760
-    public $authtype = '';                // Type of HTTP authentication
4761
-    public $certRequest = [];        // Certificate for HTTP SSL authentication
4762
-
4763
-    /**
4764
-     * constructor
4765
-     *
4766
-     * @param string  $wsdl             WSDL document URL
4767
-     * @param bool|string $proxyhost
4768
-     * @param bool|string $proxyport
4769
-     * @param bool|string $proxyusername
4770
-     * @param bool|string $proxypassword
4771
-     * @param integer $timeout          set the connection timeout
4772
-     * @param integer $response_timeout set the response timeout
4773
-     * @param array   $curl_options     user-specified cURL options
4774
-     * @param boolean $use_curl         try to use cURL
4775
-     * @access public
4776
-     */
4777
-    public function __construct($wsdl = '', $proxyhost = false, $proxyport = false, $proxyusername = false, $proxypassword = false, $timeout = 0, $response_timeout = 30, $curl_options = null, $use_curl = false)
4778
-    {
4779
-        parent::__construct();
4780
-        $this->debug("ctor wsdl=$wsdl timeout=$timeout response_timeout=$response_timeout");
4781
-        $this->proxyhost = $proxyhost;
4782
-        $this->proxyport = $proxyport;
4783
-        $this->proxyusername = $proxyusername;
4784
-        $this->proxypassword = $proxypassword;
4785
-        $this->timeout = $timeout;
4786
-        $this->response_timeout = $response_timeout;
4787
-        if (is_array($curl_options)) {
4788
-            $this->curl_options = $curl_options;
4789
-        }
4790
-        $this->use_curl = $use_curl;
4791
-        $this->fetchWSDL($wsdl);
4792
-    }
4793
-
4794
-    /**
4795
-     * fetches the WSDL document and parses it
4796
-     *
4797
-     * @access public
4798
-     * @param $wsdl
4799
-     */
4800
-    public function fetchWSDL($wsdl)
4801
-    {
4802
-        $this->debug("parse and process WSDL path=$wsdl");
4803
-        $this->wsdl = $wsdl;
4804
-        // parse wsdl file
4805
-        if ('' != $this->wsdl) {
4806
-            $this->parseWSDL($this->wsdl);
4807
-        }
4808
-        // imports
4809
-        // TODO: handle imports more properly, grabbing them in-line and nesting them
4810
-        $imported_urls = [];
4811
-        $imported = 1;
4812
-        while ($imported > 0) {
4813
-            $imported = 0;
4814
-            // Schema imports
4815
-            foreach ($this->schemas as $ns => $list) {
4816
-                foreach ($list as $xs) {
4817
-                    $wsdlparts = parse_url($this->wsdl);    // this is bogusly simple!
4818
-                    foreach ($xs->imports as $ns2 => $list2) {
4819
-                        for ($ii = 0, $iiMax = count($list2); $ii < $iiMax; $ii++) {
4820
-                            if (!$list2[$ii]['loaded']) {
4821
-                                $this->schemas[$ns][$ns2]->imports[$ns2][$ii]['loaded'] = true;
4822
-                                $url = $list2[$ii]['location'];
4823
-                                if ('' != $url) {
4824
-                                    $urlparts = parse_url($url);
4825
-                                    if (!isset($urlparts['host'])) {
4826
-                                        $url = $wsdlparts['scheme'] . '://' . $wsdlparts['host'] . (isset($wsdlparts['port']) ? ':' . $wsdlparts['port'] : '') .
4827
-                                            substr($wsdlparts['path'], 0, strrpos($wsdlparts['path'], '/') + 1) . $urlparts['path'];
4828
-                                    }
4829
-                                    if (!in_array($url, $imported_urls)) {
4830
-                                        $this->parseWSDL($url);
4831
-                                        $imported++;
4832
-                                        $imported_urls[] = $url;
4833
-                                    }
4834
-                                } else {
4835
-                                    $this->debug('Unexpected scenario: empty URL for unloaded import');
4836
-                                }
4837
-                            }
4838
-                        }
4839
-                    }
4840
-                }
4841
-            }
4842
-            // WSDL imports
4843
-            $wsdlparts = parse_url($this->wsdl);    // this is bogusly simple!
4844
-            foreach ($this->import as $ns => $list) {
4845
-                for ($ii = 0, $iiMax = count($list); $ii < $iiMax; $ii++) {
4846
-                    if (!$list[$ii]['loaded']) {
4847
-                        $this->import[$ns][$ii]['loaded'] = true;
4848
-                        $url = $list[$ii]['location'];
4849
-                        if ('' != $url) {
4850
-                            $urlparts = parse_url($url);
4851
-                            if (!isset($urlparts['host'])) {
4852
-                                $url = $wsdlparts['scheme'] . '://' . $wsdlparts['host'] . (isset($wsdlparts['port']) ? ':' . $wsdlparts['port'] : '') .
4853
-                                    substr($wsdlparts['path'], 0, strrpos($wsdlparts['path'], '/') + 1) . $urlparts['path'];
4854
-                            }
4855
-                            if (!in_array($url, $imported_urls)) {
4856
-                                $this->parseWSDL($url);
4857
-                                $imported++;
4858
-                                $imported_urls[] = $url;
4859
-                            }
4860
-                        } else {
4861
-                            $this->debug('Unexpected scenario: empty URL for unloaded import');
4862
-                        }
4863
-                    }
4864
-                }
4865
-            }
4866
-        }
4867
-        // add new data to operation data
4868
-        foreach ($this->bindings as $binding => $bindingData) {
4869
-            if (isset($bindingData['operations']) && is_array($bindingData['operations'])) {
4870
-                foreach ($bindingData['operations'] as $operation => $data) {
4871
-                    $this->debug('post-parse data gathering for ' . $operation);
4872
-                    $this->bindings[$binding]['operations'][$operation]['input'] =
4873
-                        isset($this->bindings[$binding]['operations'][$operation]['input']) ?
4874
-                            array_merge($this->bindings[$binding]['operations'][$operation]['input'], $this->portTypes[$bindingData['portType']][$operation]['input']) :
4875
-                            $this->portTypes[$bindingData['portType']][$operation]['input'];
4876
-                    $this->bindings[$binding]['operations'][$operation]['output'] =
4877
-                        isset($this->bindings[$binding]['operations'][$operation]['output']) ?
4878
-                            array_merge($this->bindings[$binding]['operations'][$operation]['output'], $this->portTypes[$bindingData['portType']][$operation]['output']) :
4879
-                            $this->portTypes[$bindingData['portType']][$operation]['output'];
4880
-                    if (isset($this->messages[$this->bindings[$binding]['operations'][$operation]['input']['message']])) {
4881
-                        $this->bindings[$binding]['operations'][$operation]['input']['parts'] = $this->messages[$this->bindings[$binding]['operations'][$operation]['input']['message']];
4882
-                    }
4883
-                    if (isset($this->messages[$this->bindings[$binding]['operations'][$operation]['output']['message']])) {
4884
-                        $this->bindings[$binding]['operations'][$operation]['output']['parts'] = $this->messages[$this->bindings[$binding]['operations'][$operation]['output']['message']];
4885
-                    }
4886
-                    // Set operation style if necessary, but do not override one already provided
4887
-                    if (isset($bindingData['style']) && !isset($this->bindings[$binding]['operations'][$operation]['style'])) {
4888
-                        $this->bindings[$binding]['operations'][$operation]['style'] = $bindingData['style'];
4889
-                    }
4890
-                    $this->bindings[$binding]['operations'][$operation]['transport'] = isset($bindingData['transport']) ? $bindingData['transport'] : '';
4891
-                    $this->bindings[$binding]['operations'][$operation]['documentation'] = isset($this->portTypes[$bindingData['portType']][$operation]['documentation']) ? $this->portTypes[$bindingData['portType']][$operation]['documentation'] : '';
4892
-                    $this->bindings[$binding]['operations'][$operation]['endpoint'] = isset($bindingData['endpoint']) ? $bindingData['endpoint'] : '';
4893
-                }
4894
-            }
4895
-        }
4896
-    }
4897
-
4898
-    /**
4899
-     * parses the wsdl document
4900
-     *
4901
-     * @param string $wsdl path or URL
4902
-     * @access private
4903
-     * @return bool
4904
-     */
4905
-    private function parseWSDL($wsdl = '')
4906
-    {
4907
-        $this->debug("parse WSDL at path=$wsdl");
4908
-
4909
-        if ('' == $wsdl) {
4910
-            $this->debug('no wsdl passed to parseWSDL()!!');
4911
-            $this->setError('no wsdl passed to parseWSDL()!!');
4912
-            return false;
4913
-        }
4914
-
4915
-        // parse $wsdl for url format
4916
-        $wsdl_props = parse_url($wsdl);
4917
-
4918
-        if (isset($wsdl_props['scheme']) && ('http' === $wsdl_props['scheme'] || 'https' === $wsdl_props['scheme'])) {
4919
-            $this->debug('getting WSDL http(s) URL ' . $wsdl);
4920
-            // get wsdl
4921
-            $tr = new soap_transport_http($wsdl, $this->curl_options, $this->use_curl);
4922
-            $tr->request_method = 'GET';
4923
-            $tr->useSOAPAction = false;
4924
-            if ($this->proxyhost && $this->proxyport) {
4925
-                $tr->setProxy($this->proxyhost, $this->proxyport, $this->proxyusername, $this->proxypassword);
4926
-            }
4927
-            if ('' != $this->authtype) {
4928
-                $tr->setCredentials($this->username, $this->password, $this->authtype, [], $this->certRequest);
4929
-            }
4930
-            $tr->setEncoding('gzip, deflate');
4931
-            $wsdl_string = $tr->send('', $this->timeout, $this->response_timeout);
4932
-            //$this->debug("WSDL request\n" . $tr->outgoing_payload);
4933
-            //$this->debug("WSDL response\n" . $tr->incoming_payload);
4934
-            $this->appendDebug($tr->getDebug());
4935
-            // catch errors
4936
-            if (false !== ($err = $tr->getError())) {
4937
-                $errstr = 'Getting ' . $wsdl . ' - HTTP ERROR: ' . $err;
4938
-                $this->debug($errstr);
4939
-                $this->setError($errstr);
4940
-                unset($tr);
4941
-                return false;
4942
-            }
4943
-            unset($tr);
4944
-            $this->debug('got WSDL URL');
4945
-        } else {
4946
-            // $wsdl is not http(s), so treat it as a file URL or plain file path
4947
-            if (isset($wsdl_props['scheme']) && ('file' === $wsdl_props['scheme']) && isset($wsdl_props['path'])) {
4948
-                $path = isset($wsdl_props['host']) ? ($wsdl_props['host'] . ':' . $wsdl_props['path']) : $wsdl_props['path'];
4949
-            } else {
4950
-                $path = $wsdl;
4951
-            }
4952
-            $this->debug('getting WSDL file ' . $path);
4953
-            if (false !== ($fp = @fopen($path, 'r'))) {
4954
-                $wsdl_string = '';
4955
-                while (false !== ($data = fread($fp, 32768))) {
4956
-                    $wsdl_string .= $data;
4957
-                }
4958
-                fclose($fp);
4959
-            } else {
4960
-                $errstr = "Bad path to WSDL file $path";
4961
-                $this->debug($errstr);
4962
-                $this->setError($errstr);
4963
-                return false;
4964
-            }
4965
-        }
4966
-        $this->debug('Parse WSDL');
4967
-        // end new code added
4968
-        // Create an XML parser.
4969
-        $this->parser = xml_parser_create();
4970
-        // Set the options for parsing the XML data.
4971
-        // xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
4972
-        xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
4973
-        // Set the object for the parser.
4974
-        xml_set_object($this->parser, $this);
4975
-        // Set the element handlers for the parser.
4976
-        xml_set_element_handler($this->parser, 'start_element', 'end_element');
4977
-        xml_set_character_data_handler($this->parser, 'character_data');
4978
-        // Parse the XML file.
4979
-        if (!xml_parse($this->parser, $wsdl_string, true)) {
4980
-            // Display an error message.
4981
-            $errstr = sprintf(
4982
-                'XML error parsing WSDL from %s on line %d: %s',
4983
-                $wsdl,
4984
-                xml_get_current_line_number($this->parser),
4985
-                xml_error_string(xml_get_error_code($this->parser))
4986
-            );
4987
-            $this->debug($errstr);
4988
-            $this->debug("XML payload:\n" . $wsdl_string);
4989
-            $this->setError($errstr);
4990
-            xml_parser_free($this->parser);
4991
-            unset($this->parser);
4992
-            return false;
4993
-        }
4994
-        // free the parser
4995
-        xml_parser_free($this->parser);
4996
-        unset($this->parser);
4997
-        $this->debug('Parsing WSDL done');
4998
-        // catch wsdl parse errors
4999
-        if ($this->getError()) {
5000
-            return false;
5001
-        }
5002
-        return true;
5003
-    }
5004
-
5005
-    /**
5006
-     * start-element handler
5007
-     *
5008
-     * @param string $parser XML parser object
5009
-     * @param string $name element name
5010
-     * @param string|array $attrs associative array of attributes
5011
-     * @access private
5012
-     */
5013
-    private function start_element($parser, $name, $attrs)
5014
-    {
5015
-        if ('schema' === $this->status) {
5016
-            $this->currentSchema->schemaStartElement($parser, $name, $attrs);
5017
-            $this->appendDebug($this->currentSchema->getDebug());
5018
-            $this->currentSchema->clearDebug();
5019
-        } elseif (preg_match('/schema$/', $name)) {
5020
-            $this->debug('Parsing WSDL schema');
5021
-            // $this->debug("startElement for $name ($attrs[name]). status = $this->status (".$this->getLocalPart($name).")");
5022
-            $this->status = 'schema';
5023
-            $this->currentSchema = new nusoap_xmlschema('', '', $this->namespaces);
5024
-            $this->currentSchema->schemaStartElement($parser, $name, $attrs);
5025
-            $this->appendDebug($this->currentSchema->getDebug());
5026
-            $this->currentSchema->clearDebug();
5027
-        } else {
5028
-            // position in the total number of elements, starting from 0
5029
-            $pos = $this->position++;
5030
-            $depth = $this->depth++;
5031
-            // set self as current value for this depth
5032
-            $this->depth_array[$depth] = $pos;
5033
-            $this->message[$pos] = ['cdata' => ''];
5034
-            // process attributes
5035
-            if (is_array($attrs) && count($attrs) > 0) {
5036
-                // register namespace declarations
5037
-                foreach ($attrs as $k => $v) {
5038
-                    if (preg_match('/^xmlns/', $k)) {
5039
-                        if (false !== ($ns_prefix = substr(strrchr($k, ':'), 1))) {
5040
-                            $this->namespaces[$ns_prefix] = $v;
5041
-                        } else {
5042
-                            $this->namespaces['ns' . (count($this->namespaces) + 1)] = $v;
5043
-                        }
5044
-                        if ('http://www.w3.org/2001/XMLSchema' === $v || 'http://www.w3.org/1999/XMLSchema' === $v || 'http://www.w3.org/2000/10/XMLSchema' === $v) {
5045
-                            $this->XMLSchemaVersion = $v;
5046
-                            $this->namespaces['xsi'] = $v . '-instance';
5047
-                        }
5048
-                    }
5049
-                }
5050
-                // expand each attribute prefix to its namespace
5051
-                foreach ($attrs as $k => $v) {
5052
-                    $k = strpos($k, ':') ? $this->expandQname($k) : $k;
5053
-                    if ('location' !== $k && 'soapAction' !== $k && 'namespace' !== $k) {
5054
-                        $v = strpos($v, ':') ? $this->expandQname($v) : $v;
5055
-                    }
5056
-                    $eAttrs[$k] = $v;
5057
-                }
5058
-                $attrs = $eAttrs;
5059
-            } else {
5060
-                $attrs = [];
5061
-            }
5062
-            // Set default prefix and namespace
5063
-            // to prevent error Undefined variable $prefix and $namespace if (preg_match('/:/', $name)) return 0 or FALSE
5064
-            $prefix = '';
5065
-            $namespace = '';
5066
-            // get element prefix, namespace and name
5067
-            if (preg_match('/:/', $name)) {
5068
-                // get ns prefix
5069
-                $prefix = substr($name, 0, strpos($name, ':'));
5070
-                // get ns
5071
-                $namespace = isset($this->namespaces[$prefix]) ? $this->namespaces[$prefix] : '';
5072
-                // get unqualified name
5073
-                $name = substr(strstr($name, ':'), 1);
5074
-            }
5075
-            // process attributes, expanding any prefixes to namespaces
5076
-            // find status, register data
5077
-            switch ($this->status) {
5078
-                case 'message':
5079
-                    if ('part' === $name) {
5080
-                        if (isset($attrs['type'])) {
5081
-                            $this->debug('msg ' . $this->currentMessage . ": found part (with type) $attrs[name]: " . implode(',', $attrs));
5082
-                            $this->messages[$this->currentMessage][$attrs['name']] = $attrs['type'];
5083
-                        }
5084
-                        if (isset($attrs['element'])) {
5085
-                            $this->debug('msg ' . $this->currentMessage . ": found part (with element) $attrs[name]: " . implode(',', $attrs));
5086
-                            $this->messages[$this->currentMessage][$attrs['name']] = $attrs['element'] . '^';
5087
-                        }
5088
-                    }
5089
-                    break;
5090
-                case 'portType':
5091
-                    switch ($name) {
5092
-                        case 'operation':
5093
-                            $this->currentPortOperation = $attrs['name'];
5094
-                            $this->debug("portType $this->currentPortType operation: $this->currentPortOperation");
5095
-                            if (isset($attrs['parameterOrder'])) {
5096
-                                $this->portTypes[$this->currentPortType][$attrs['name']]['parameterOrder'] = $attrs['parameterOrder'];
5097
-                            }
5098
-                            break;
5099
-                        case 'documentation':
5100
-                            $this->documentation = true;
5101
-                            break;
5102
-                        // merge input/output data
5103
-                        default:
5104
-                            $m = isset($attrs['message']) ? $this->getLocalPart($attrs['message']) : '';
5105
-                            $this->portTypes[$this->currentPortType][$this->currentPortOperation][$name]['message'] = $m;
5106
-                            break;
5107
-                    }
5108
-                    break;
5109
-                case 'binding':
5110
-                    switch ($name) {
5111
-                        case 'binding':
5112
-                            // get ns prefix
5113
-                            if (isset($attrs['style'])) {
5114
-                                $this->bindings[$this->currentBinding]['prefix'] = $prefix;
5115
-                            }
5116
-                            $this->bindings[$this->currentBinding] = array_merge($this->bindings[$this->currentBinding], $attrs);
5117
-                            break;
5118
-                        case 'header':
5119
-                            $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus]['headers'][] = $attrs;
5120
-                            break;
5121
-                        case 'operation':
5122
-                            if (isset($attrs['soapAction'])) {
5123
-                                $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['soapAction'] = $attrs['soapAction'];
5124
-                            }
5125
-                            if (isset($attrs['style'])) {
5126
-                                $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['style'] = $attrs['style'];
5127
-                            }
5128
-                            if (isset($attrs['name'])) {
5129
-                                $this->currentOperation = $attrs['name'];
5130
-                                $this->debug("current binding operation: $this->currentOperation");
5131
-                                $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['name'] = $attrs['name'];
5132
-                                $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['binding'] = $this->currentBinding;
5133
-                                $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['endpoint'] = isset($this->bindings[$this->currentBinding]['endpoint']) ? $this->bindings[$this->currentBinding]['endpoint'] : '';
5134
-                            }
5135
-                            break;
5136
-                        case 'input':
5137
-                            $this->opStatus = 'input';
5138
-                            break;
5139
-                        case 'output':
5140
-                            $this->opStatus = 'output';
5141
-                            break;
5142
-                        case 'body':
5143
-                            if (isset($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus])) {
5144
-                                $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = array_merge($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus], $attrs);
5145
-                            } else {
5146
-                                $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = $attrs;
5147
-                            }
5148
-                            break;
5149
-                    }
5150
-                    break;
5151
-                case 'service':
5152
-                    switch ($name) {
5153
-                        case 'port':
5154
-                            $this->currentPort = $attrs['name'];
5155
-                            $this->debug('current port: ' . $this->currentPort);
5156
-                            $this->ports[$this->currentPort]['binding'] = $this->getLocalPart($attrs['binding']);
5157
-
5158
-                            break;
5159
-                        case 'address':
5160
-                            $this->ports[$this->currentPort]['location'] = $attrs['location'];
5161
-                            $this->ports[$this->currentPort]['bindingType'] = $namespace;
5162
-                            $this->bindings[$this->ports[$this->currentPort]['binding']]['bindingType'] = $namespace;
5163
-                            $this->bindings[$this->ports[$this->currentPort]['binding']]['endpoint'] = $attrs['location'];
5164
-                            break;
5165
-                    }
5166
-                    break;
5167
-            }
5168
-            // set status
5169
-            switch ($name) {
5170
-                case 'import':
5171
-                    if (isset($attrs['location'])) {
5172
-                        $this->import[$attrs['namespace']][] = ['location' => $attrs['location'], 'loaded' => false];
5173
-                        $this->debug('parsing import ' . $attrs['namespace'] . ' - ' . $attrs['location'] . ' (' . count($this->import[$attrs['namespace']]) . ')');
5174
-                    } else {
5175
-                        $this->import[$attrs['namespace']][] = ['location' => '', 'loaded' => true];
5176
-                        if (!$this->getPrefixFromNamespace($attrs['namespace'])) {
5177
-                            $this->namespaces['ns' . (count($this->namespaces) + 1)] = $attrs['namespace'];
5178
-                        }
5179
-                        $this->debug('parsing import ' . $attrs['namespace'] . ' - [no location] (' . count($this->import[$attrs['namespace']]) . ')');
5180
-                    }
5181
-                    break;
5182
-                //wait for schema
5183
-                //case 'types':
5184
-                //	$this->status = 'schema';
5185
-                //	break;
5186
-                case 'message':
5187
-                    $this->status = 'message';
5188
-                    $this->messages[$attrs['name']] = [];
5189
-                    $this->currentMessage = $attrs['name'];
5190
-                    break;
5191
-                case 'portType':
5192
-                    $this->status = 'portType';
5193
-                    $this->portTypes[$attrs['name']] = [];
5194
-                    $this->currentPortType = $attrs['name'];
5195
-                    break;
5196
-                case 'binding':
5197
-                    if (isset($attrs['name'])) {
5198
-                        // get binding name
5199
-                        if (strpos($attrs['name'], ':')) {
5200
-                            $this->currentBinding = $this->getLocalPart($attrs['name']);
5201
-                        } else {
5202
-                            $this->currentBinding = $attrs['name'];
5203
-                        }
5204
-                        $this->status = 'binding';
5205
-                        $this->bindings[$this->currentBinding]['portType'] = $this->getLocalPart($attrs['type']);
5206
-                        $this->debug("current binding: $this->currentBinding of portType: " . $attrs['type']);
5207
-                    }
5208
-                    break;
5209
-                case 'service':
5210
-                    $this->serviceName = $attrs['name'];
5211
-                    $this->status = 'service';
5212
-                    $this->debug('current service: ' . $this->serviceName);
5213
-                    break;
5214
-                case 'definitions':
5215
-                    foreach ($attrs as $name => $value) {
5216
-                        $this->wsdl_info[$name] = $value;
5217
-                    }
5218
-                    break;
5219
-            }
5220
-        }
5221
-    }
5222
-
5223
-    /**
5224
-     * end-element handler
5225
-     *
5226
-     * @param string $parser XML parser object
5227
-     * @param string $name element name
5228
-     * @access private
5229
-     */
5230
-    private function end_element($parser, $name)
5231
-    {
5232
-        // unset schema status
5233
-        if (/*preg_match('/types$/', $name) ||*/
5234
-        preg_match('/schema$/', $name)
5235
-        ) {
5236
-            $this->status = '';
5237
-            $this->appendDebug($this->currentSchema->getDebug());
5238
-            $this->currentSchema->clearDebug();
5239
-            $this->schemas[$this->currentSchema->schemaTargetNamespace][] = $this->currentSchema;
5240
-            $this->debug('Parsing WSDL schema done');
5241
-        }
5242
-        if ('schema' === $this->status) {
5243
-            $this->currentSchema->schemaEndElement($parser, $name);
5244
-        } else {
5245
-            // bring depth down a notch
5246
-            $this->depth--;
5247
-        }
5248
-        // end documentation
5249
-        if ($this->documentation) {
5250
-            //TODO: track the node to which documentation should be assigned; it can be a part, message, etc.
5251
-            //$this->portTypes[$this->currentPortType][$this->currentPortOperation]['documentation'] = $this->documentation;
5252
-            $this->documentation = false;
5253
-        }
5254
-    }
5255
-
5256
-    /**
5257
-     * element content handler
5258
-     *
5259
-     * @param string $parser XML parser object
5260
-     * @param string $data element content
5261
-     * @access private
5262
-     */
5263
-    private function character_data($parser, $data)
5264
-    {
5265
-        $pos = isset($this->depth_array[$this->depth]) ? $this->depth_array[$this->depth] : 0;
5266
-        if (isset($this->message[$pos]['cdata'])) {
5267
-            $this->message[$pos]['cdata'] .= $data;
5268
-        }
5269
-        if ($this->documentation) {
5270
-            $this->documentation .= $data;
5271
-        }
5272
-    }
5273
-
5274
-    /**
5275
-     * if authenticating, set user credentials here
5276
-     *
5277
-     * @param    string $username
5278
-     * @param    string $password
5279
-     * @param    string $authtype (basic|digest|certificate|ntlm)
5280
-     * @param    array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs)
5281
-     * @access   public
5282
-     */
5283
-    public function setCredentials($username, $password, $authtype = 'basic', $certRequest = [])
5284
-    {
5285
-        $this->debug("setCredentials username=$username authtype=$authtype certRequest=");
5286
-        $this->appendDebug($this->varDump($certRequest));
5287
-        $this->username = $username;
5288
-        $this->password = $password;
5289
-        $this->authtype = $authtype;
5290
-        $this->certRequest = $certRequest;
5291
-    }
5292
-
5293
-    /**
5294
-     * @param $binding
5295
-     * @return mixed
5296
-     */
5297
-    public function getBindingData($binding)
5298
-    {
5299
-        if (is_array($this->bindings[$binding])) {
5300
-            return $this->bindings[$binding];
5301
-        }
5302
-    }
5303
-
5304
-    /**
5305
-     * returns an assoc array of operation names => operation data
5306
-     *
5307
-     * @param string $portName WSDL port name
5308
-     * @param string $bindingType eg: soap, smtp, dime (only soap and soap12 are currently supported)
5309
-     * @return array
5310
-     * @access public
5311
-     */
5312
-    public function getOperations($portName = '', $bindingType = 'soap')
5313
-    {
5314
-        $ops = [];
5315
-        if ('soap' === $bindingType) {
5316
-            $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/';
5317
-        } elseif ('soap12' === $bindingType) {
5318
-            $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/';
5319
-        } else {
5320
-            $this->debug("getOperations bindingType $bindingType may not be supported");
5321
-        }
5322
-        $this->debug("getOperations for port '$portName' bindingType $bindingType");
5323
-        // loop thru ports
5324
-        foreach ($this->ports as $port => $portData) {
5325
-            $this->debug("getOperations checking port $port bindingType " . $portData['bindingType']);
5326
-            if ('' == $portName || $port == $portName) {
5327
-                // binding type of port matches parameter
5328
-                if ($portData['bindingType'] == $bindingType) {
5329
-                    $this->debug("getOperations found port $port bindingType $bindingType");
5330
-                    //$this->debug("port data: " . $this->varDump($portData));
5331
-                    //$this->debug("bindings: " . $this->varDump($this->bindings[ $portData['binding'] ]));
5332
-                    // merge bindings
5333
-                    if (isset($this->bindings[$portData['binding']]['operations'])) {
5334
-                        $ops = array_merge($ops, $this->bindings[$portData['binding']]['operations']);
5335
-                    }
5336
-                }
5337
-            }
5338
-        }
5339
-        if (0 == count($ops)) {
5340
-            $this->debug("getOperations found no operations for port '$portName' bindingType $bindingType");
5341
-        }
5342
-        return $ops;
5343
-    }
5344
-
5345
-    /**
5346
-     * returns an associative array of data necessary for calling an operation
5347
-     *
5348
-     * @param string $operation name of operation
5349
-     * @param string $bindingType type of binding eg: soap, soap12
5350
-     * @return array
5351
-     * @access public
5352
-     */
5353
-    public function getOperationData($operation, $bindingType = 'soap')
5354
-    {
5355
-        if ('soap' === $bindingType) {
5356
-            $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/';
5357
-        } elseif ('soap12' === $bindingType) {
5358
-            $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/';
5359
-        }
5360
-        // loop thru ports
5361
-        foreach ($this->ports as $port => $portData) {
5362
-            // binding type of port matches parameter
5363
-            if ($portData['bindingType'] == $bindingType) {
5364
-                // get binding
5365
-                //foreach($this->bindings[ $portData['binding'] ]['operations'] as $bOperation => $opData) {
5366
-                foreach (array_keys($this->bindings[$portData['binding']]['operations']) as $bOperation) {
5367
-                    // note that we could/should also check the namespace here
5368
-                    if ($operation == $bOperation) {
5369
-                        $opData = $this->bindings[$portData['binding']]['operations'][$operation];
5370
-                        return $opData;
5371
-                    }
5372
-                }
5373
-            }
5374
-        }
5375
-    }
5376
-
5377
-    /**
5378
-     * returns an associative array of data necessary for calling an operation
5379
-     *
5380
-     * @param string $soapAction soapAction for operation
5381
-     * @param string $bindingType type of binding eg: soap, soap12
5382
-     * @return array
5383
-     * @access public
5384
-     */
5385
-    public function getOperationDataForSoapAction($soapAction, $bindingType = 'soap')
5386
-    {
5387
-        if ('soap' === $bindingType) {
5388
-            $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/';
5389
-        } elseif ('soap12' === $bindingType) {
5390
-            $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/';
5391
-        }
5392
-        // loop thru ports
5393
-        foreach ($this->ports as $port => $portData) {
5394
-            // binding type of port matches parameter
5395
-            if ($portData['bindingType'] == $bindingType) {
5396
-                // loop through operations for the binding
5397
-                foreach ($this->bindings[$portData['binding']]['operations'] as $bOperation => $opData) {
5398
-                    if ($opData['soapAction'] == $soapAction) {
5399
-                        return $opData;
5400
-                    }
5401
-                }
5402
-            }
5403
-        }
5404
-    }
5405
-
5406
-    /**
5407
-     * returns an array of information about a given type
5408
-     * returns false if no type exists by the given name
5409
-     *
5410
-     *     typeDef = array(
5411
-     *     'elements' => array(), // refs to elements array
5412
-     *    'restrictionBase' => '',
5413
-     *    'phpType' => '',
5414
-     *    'order' => '(sequence|all)',
5415
-     *    'attrs' => array() // refs to attributes array
5416
-     *    )
5417
-     *
5418
-     * @param string $type the type
5419
-     * @param string $ns namespace (not prefix) of the type
5420
-     * @return mixed
5421
-     * @access public
5422
-     * @see nusoap_xmlschema
5423
-     */
5424
-    public function getTypeDef($type, $ns)
5425
-    {
5426
-        $this->debug("in getTypeDef: type=$type, ns=$ns");
5427
-        if ((!$ns) && isset($this->namespaces['tns'])) {
5428
-            $ns = $this->namespaces['tns'];
5429
-            $this->debug("in getTypeDef: type namespace forced to $ns");
5430
-        }
5431
-        if (!isset($this->schemas[$ns])) {
5432
-            foreach ($this->schemas as $ns0 => $schema0) {
5433
-                if (0 == strcasecmp($ns, $ns0)) {
5434
-                    $this->debug("in getTypeDef: replacing schema namespace $ns with $ns0");
5435
-                    $ns = $ns0;
5436
-                    break;
5437
-                }
5438
-            }
5439
-        }
5440
-        if (isset($this->schemas[$ns])) {
5441
-            $this->debug("in getTypeDef: have schema for namespace $ns");
5442
-            for ($i = 0, $iMax = count($this->schemas[$ns]); $i < $iMax; $i++) {
5443
-                $xs = &$this->schemas[$ns][$i];
5444
-                $t = $xs->getTypeDef($type);
5445
-                $this->appendDebug($xs->getDebug());
5446
-                $xs->clearDebug();
5447
-                if ($t) {
5448
-                    $this->debug("in getTypeDef: found type $type");
5449
-                    if (!isset($t['phpType'])) {
5450
-                        // get info for type to tack onto the element
5451
-                        $uqType = substr($t['type'], strrpos($t['type'], ':') + 1);
5452
-                        $ns = substr($t['type'], 0, strrpos($t['type'], ':'));
5453
-                        $etype = $this->getTypeDef($uqType, $ns);
5454
-                        if ($etype) {
5455
-                            $this->debug("found type for [element] $type:");
5456
-                            $this->debug($this->varDump($etype));
5457
-                            if (isset($etype['phpType'])) {
5458
-                                $t['phpType'] = $etype['phpType'];
5459
-                            }
5460
-                            if (isset($etype['elements'])) {
5461
-                                $t['elements'] = $etype['elements'];
5462
-                            }
5463
-                            if (isset($etype['attrs'])) {
5464
-                                $t['attrs'] = $etype['attrs'];
5465
-                            }
5466
-                        } else {
5467
-                            $this->debug("did not find type for [element] $type");
5468
-                        }
5469
-                    }
5470
-                    return $t;
5471
-                }
5472
-            }
5473
-            $this->debug("in getTypeDef: did not find type $type");
5474
-        } else {
5475
-            $this->debug("in getTypeDef: do not have schema for namespace $ns");
5476
-        }
5477
-        return false;
5478
-    }
5479
-
5480
-    /**
5481
-     * prints html description of services
5482
-     *
5483
-     * @access private
5484
-     */
5485
-    public function webDescription()
5486
-    {
5487
-        global $HTTP_SERVER_VARS;
5488
-
5489
-        if (isset($_SERVER)) {
5490
-            $PHP_SELF = $_SERVER['PHP_SELF'];
5491
-        } elseif (isset($HTTP_SERVER_VARS)) {
5492
-            $PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF'];
5493
-        } else {
5494
-            $this->setError('Neither _SERVER nor HTTP_SERVER_VARS is available');
5495
-        }
5496
-
5497
-        $b = '
4721
+	// URL or filename of the root of this WSDL
4722
+	public $wsdl;
4723
+	// define internal arrays of bindings, ports, operations, messages, etc.
4724
+	public $schemas = [];
4725
+	public $currentSchema;
4726
+	public $message = [];
4727
+	public $complexTypes = [];
4728
+	public $messages = [];
4729
+	public $currentMessage;
4730
+	public $currentOperation;
4731
+	public $portTypes = [];
4732
+	public $currentPortType;
4733
+	public $bindings = [];
4734
+	public $currentBinding;
4735
+	public $ports = [];
4736
+	public $currentPort;
4737
+	public $opData = [];
4738
+	public $status = '';
4739
+	public $documentation = false;
4740
+	public $endpoint = '';
4741
+	// array of wsdl docs to import
4742
+	public $import = [];
4743
+	// parser vars
4744
+	public $parser;
4745
+	public $position = 0;
4746
+	public $depth = 0;
4747
+	public $depth_array = [];
4748
+	// for getting wsdl
4749
+	public $proxyhost = '';
4750
+	public $proxyport = '';
4751
+	public $proxyusername = '';
4752
+	public $proxypassword = '';
4753
+	public $timeout = 0;
4754
+	public $response_timeout = 30;
4755
+	public $curl_options = [];    // User-specified cURL options
4756
+	public $use_curl = false;            // whether to always try to use cURL
4757
+	// for HTTP authentication
4758
+	public $username = '';                // Username for HTTP authentication
4759
+	public $password = '';                // Password for HTTP authentication
4760
+	public $authtype = '';                // Type of HTTP authentication
4761
+	public $certRequest = [];        // Certificate for HTTP SSL authentication
4762
+
4763
+	/**
4764
+	 * constructor
4765
+	 *
4766
+	 * @param string  $wsdl             WSDL document URL
4767
+	 * @param bool|string $proxyhost
4768
+	 * @param bool|string $proxyport
4769
+	 * @param bool|string $proxyusername
4770
+	 * @param bool|string $proxypassword
4771
+	 * @param integer $timeout          set the connection timeout
4772
+	 * @param integer $response_timeout set the response timeout
4773
+	 * @param array   $curl_options     user-specified cURL options
4774
+	 * @param boolean $use_curl         try to use cURL
4775
+	 * @access public
4776
+	 */
4777
+	public function __construct($wsdl = '', $proxyhost = false, $proxyport = false, $proxyusername = false, $proxypassword = false, $timeout = 0, $response_timeout = 30, $curl_options = null, $use_curl = false)
4778
+	{
4779
+		parent::__construct();
4780
+		$this->debug("ctor wsdl=$wsdl timeout=$timeout response_timeout=$response_timeout");
4781
+		$this->proxyhost = $proxyhost;
4782
+		$this->proxyport = $proxyport;
4783
+		$this->proxyusername = $proxyusername;
4784
+		$this->proxypassword = $proxypassword;
4785
+		$this->timeout = $timeout;
4786
+		$this->response_timeout = $response_timeout;
4787
+		if (is_array($curl_options)) {
4788
+			$this->curl_options = $curl_options;
4789
+		}
4790
+		$this->use_curl = $use_curl;
4791
+		$this->fetchWSDL($wsdl);
4792
+	}
4793
+
4794
+	/**
4795
+	 * fetches the WSDL document and parses it
4796
+	 *
4797
+	 * @access public
4798
+	 * @param $wsdl
4799
+	 */
4800
+	public function fetchWSDL($wsdl)
4801
+	{
4802
+		$this->debug("parse and process WSDL path=$wsdl");
4803
+		$this->wsdl = $wsdl;
4804
+		// parse wsdl file
4805
+		if ('' != $this->wsdl) {
4806
+			$this->parseWSDL($this->wsdl);
4807
+		}
4808
+		// imports
4809
+		// TODO: handle imports more properly, grabbing them in-line and nesting them
4810
+		$imported_urls = [];
4811
+		$imported = 1;
4812
+		while ($imported > 0) {
4813
+			$imported = 0;
4814
+			// Schema imports
4815
+			foreach ($this->schemas as $ns => $list) {
4816
+				foreach ($list as $xs) {
4817
+					$wsdlparts = parse_url($this->wsdl);    // this is bogusly simple!
4818
+					foreach ($xs->imports as $ns2 => $list2) {
4819
+						for ($ii = 0, $iiMax = count($list2); $ii < $iiMax; $ii++) {
4820
+							if (!$list2[$ii]['loaded']) {
4821
+								$this->schemas[$ns][$ns2]->imports[$ns2][$ii]['loaded'] = true;
4822
+								$url = $list2[$ii]['location'];
4823
+								if ('' != $url) {
4824
+									$urlparts = parse_url($url);
4825
+									if (!isset($urlparts['host'])) {
4826
+										$url = $wsdlparts['scheme'] . '://' . $wsdlparts['host'] . (isset($wsdlparts['port']) ? ':' . $wsdlparts['port'] : '') .
4827
+											substr($wsdlparts['path'], 0, strrpos($wsdlparts['path'], '/') + 1) . $urlparts['path'];
4828
+									}
4829
+									if (!in_array($url, $imported_urls)) {
4830
+										$this->parseWSDL($url);
4831
+										$imported++;
4832
+										$imported_urls[] = $url;
4833
+									}
4834
+								} else {
4835
+									$this->debug('Unexpected scenario: empty URL for unloaded import');
4836
+								}
4837
+							}
4838
+						}
4839
+					}
4840
+				}
4841
+			}
4842
+			// WSDL imports
4843
+			$wsdlparts = parse_url($this->wsdl);    // this is bogusly simple!
4844
+			foreach ($this->import as $ns => $list) {
4845
+				for ($ii = 0, $iiMax = count($list); $ii < $iiMax; $ii++) {
4846
+					if (!$list[$ii]['loaded']) {
4847
+						$this->import[$ns][$ii]['loaded'] = true;
4848
+						$url = $list[$ii]['location'];
4849
+						if ('' != $url) {
4850
+							$urlparts = parse_url($url);
4851
+							if (!isset($urlparts['host'])) {
4852
+								$url = $wsdlparts['scheme'] . '://' . $wsdlparts['host'] . (isset($wsdlparts['port']) ? ':' . $wsdlparts['port'] : '') .
4853
+									substr($wsdlparts['path'], 0, strrpos($wsdlparts['path'], '/') + 1) . $urlparts['path'];
4854
+							}
4855
+							if (!in_array($url, $imported_urls)) {
4856
+								$this->parseWSDL($url);
4857
+								$imported++;
4858
+								$imported_urls[] = $url;
4859
+							}
4860
+						} else {
4861
+							$this->debug('Unexpected scenario: empty URL for unloaded import');
4862
+						}
4863
+					}
4864
+				}
4865
+			}
4866
+		}
4867
+		// add new data to operation data
4868
+		foreach ($this->bindings as $binding => $bindingData) {
4869
+			if (isset($bindingData['operations']) && is_array($bindingData['operations'])) {
4870
+				foreach ($bindingData['operations'] as $operation => $data) {
4871
+					$this->debug('post-parse data gathering for ' . $operation);
4872
+					$this->bindings[$binding]['operations'][$operation]['input'] =
4873
+						isset($this->bindings[$binding]['operations'][$operation]['input']) ?
4874
+							array_merge($this->bindings[$binding]['operations'][$operation]['input'], $this->portTypes[$bindingData['portType']][$operation]['input']) :
4875
+							$this->portTypes[$bindingData['portType']][$operation]['input'];
4876
+					$this->bindings[$binding]['operations'][$operation]['output'] =
4877
+						isset($this->bindings[$binding]['operations'][$operation]['output']) ?
4878
+							array_merge($this->bindings[$binding]['operations'][$operation]['output'], $this->portTypes[$bindingData['portType']][$operation]['output']) :
4879
+							$this->portTypes[$bindingData['portType']][$operation]['output'];
4880
+					if (isset($this->messages[$this->bindings[$binding]['operations'][$operation]['input']['message']])) {
4881
+						$this->bindings[$binding]['operations'][$operation]['input']['parts'] = $this->messages[$this->bindings[$binding]['operations'][$operation]['input']['message']];
4882
+					}
4883
+					if (isset($this->messages[$this->bindings[$binding]['operations'][$operation]['output']['message']])) {
4884
+						$this->bindings[$binding]['operations'][$operation]['output']['parts'] = $this->messages[$this->bindings[$binding]['operations'][$operation]['output']['message']];
4885
+					}
4886
+					// Set operation style if necessary, but do not override one already provided
4887
+					if (isset($bindingData['style']) && !isset($this->bindings[$binding]['operations'][$operation]['style'])) {
4888
+						$this->bindings[$binding]['operations'][$operation]['style'] = $bindingData['style'];
4889
+					}
4890
+					$this->bindings[$binding]['operations'][$operation]['transport'] = isset($bindingData['transport']) ? $bindingData['transport'] : '';
4891
+					$this->bindings[$binding]['operations'][$operation]['documentation'] = isset($this->portTypes[$bindingData['portType']][$operation]['documentation']) ? $this->portTypes[$bindingData['portType']][$operation]['documentation'] : '';
4892
+					$this->bindings[$binding]['operations'][$operation]['endpoint'] = isset($bindingData['endpoint']) ? $bindingData['endpoint'] : '';
4893
+				}
4894
+			}
4895
+		}
4896
+	}
4897
+
4898
+	/**
4899
+	 * parses the wsdl document
4900
+	 *
4901
+	 * @param string $wsdl path or URL
4902
+	 * @access private
4903
+	 * @return bool
4904
+	 */
4905
+	private function parseWSDL($wsdl = '')
4906
+	{
4907
+		$this->debug("parse WSDL at path=$wsdl");
4908
+
4909
+		if ('' == $wsdl) {
4910
+			$this->debug('no wsdl passed to parseWSDL()!!');
4911
+			$this->setError('no wsdl passed to parseWSDL()!!');
4912
+			return false;
4913
+		}
4914
+
4915
+		// parse $wsdl for url format
4916
+		$wsdl_props = parse_url($wsdl);
4917
+
4918
+		if (isset($wsdl_props['scheme']) && ('http' === $wsdl_props['scheme'] || 'https' === $wsdl_props['scheme'])) {
4919
+			$this->debug('getting WSDL http(s) URL ' . $wsdl);
4920
+			// get wsdl
4921
+			$tr = new soap_transport_http($wsdl, $this->curl_options, $this->use_curl);
4922
+			$tr->request_method = 'GET';
4923
+			$tr->useSOAPAction = false;
4924
+			if ($this->proxyhost && $this->proxyport) {
4925
+				$tr->setProxy($this->proxyhost, $this->proxyport, $this->proxyusername, $this->proxypassword);
4926
+			}
4927
+			if ('' != $this->authtype) {
4928
+				$tr->setCredentials($this->username, $this->password, $this->authtype, [], $this->certRequest);
4929
+			}
4930
+			$tr->setEncoding('gzip, deflate');
4931
+			$wsdl_string = $tr->send('', $this->timeout, $this->response_timeout);
4932
+			//$this->debug("WSDL request\n" . $tr->outgoing_payload);
4933
+			//$this->debug("WSDL response\n" . $tr->incoming_payload);
4934
+			$this->appendDebug($tr->getDebug());
4935
+			// catch errors
4936
+			if (false !== ($err = $tr->getError())) {
4937
+				$errstr = 'Getting ' . $wsdl . ' - HTTP ERROR: ' . $err;
4938
+				$this->debug($errstr);
4939
+				$this->setError($errstr);
4940
+				unset($tr);
4941
+				return false;
4942
+			}
4943
+			unset($tr);
4944
+			$this->debug('got WSDL URL');
4945
+		} else {
4946
+			// $wsdl is not http(s), so treat it as a file URL or plain file path
4947
+			if (isset($wsdl_props['scheme']) && ('file' === $wsdl_props['scheme']) && isset($wsdl_props['path'])) {
4948
+				$path = isset($wsdl_props['host']) ? ($wsdl_props['host'] . ':' . $wsdl_props['path']) : $wsdl_props['path'];
4949
+			} else {
4950
+				$path = $wsdl;
4951
+			}
4952
+			$this->debug('getting WSDL file ' . $path);
4953
+			if (false !== ($fp = @fopen($path, 'r'))) {
4954
+				$wsdl_string = '';
4955
+				while (false !== ($data = fread($fp, 32768))) {
4956
+					$wsdl_string .= $data;
4957
+				}
4958
+				fclose($fp);
4959
+			} else {
4960
+				$errstr = "Bad path to WSDL file $path";
4961
+				$this->debug($errstr);
4962
+				$this->setError($errstr);
4963
+				return false;
4964
+			}
4965
+		}
4966
+		$this->debug('Parse WSDL');
4967
+		// end new code added
4968
+		// Create an XML parser.
4969
+		$this->parser = xml_parser_create();
4970
+		// Set the options for parsing the XML data.
4971
+		// xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
4972
+		xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
4973
+		// Set the object for the parser.
4974
+		xml_set_object($this->parser, $this);
4975
+		// Set the element handlers for the parser.
4976
+		xml_set_element_handler($this->parser, 'start_element', 'end_element');
4977
+		xml_set_character_data_handler($this->parser, 'character_data');
4978
+		// Parse the XML file.
4979
+		if (!xml_parse($this->parser, $wsdl_string, true)) {
4980
+			// Display an error message.
4981
+			$errstr = sprintf(
4982
+				'XML error parsing WSDL from %s on line %d: %s',
4983
+				$wsdl,
4984
+				xml_get_current_line_number($this->parser),
4985
+				xml_error_string(xml_get_error_code($this->parser))
4986
+			);
4987
+			$this->debug($errstr);
4988
+			$this->debug("XML payload:\n" . $wsdl_string);
4989
+			$this->setError($errstr);
4990
+			xml_parser_free($this->parser);
4991
+			unset($this->parser);
4992
+			return false;
4993
+		}
4994
+		// free the parser
4995
+		xml_parser_free($this->parser);
4996
+		unset($this->parser);
4997
+		$this->debug('Parsing WSDL done');
4998
+		// catch wsdl parse errors
4999
+		if ($this->getError()) {
5000
+			return false;
5001
+		}
5002
+		return true;
5003
+	}
5004
+
5005
+	/**
5006
+	 * start-element handler
5007
+	 *
5008
+	 * @param string $parser XML parser object
5009
+	 * @param string $name element name
5010
+	 * @param string|array $attrs associative array of attributes
5011
+	 * @access private
5012
+	 */
5013
+	private function start_element($parser, $name, $attrs)
5014
+	{
5015
+		if ('schema' === $this->status) {
5016
+			$this->currentSchema->schemaStartElement($parser, $name, $attrs);
5017
+			$this->appendDebug($this->currentSchema->getDebug());
5018
+			$this->currentSchema->clearDebug();
5019
+		} elseif (preg_match('/schema$/', $name)) {
5020
+			$this->debug('Parsing WSDL schema');
5021
+			// $this->debug("startElement for $name ($attrs[name]). status = $this->status (".$this->getLocalPart($name).")");
5022
+			$this->status = 'schema';
5023
+			$this->currentSchema = new nusoap_xmlschema('', '', $this->namespaces);
5024
+			$this->currentSchema->schemaStartElement($parser, $name, $attrs);
5025
+			$this->appendDebug($this->currentSchema->getDebug());
5026
+			$this->currentSchema->clearDebug();
5027
+		} else {
5028
+			// position in the total number of elements, starting from 0
5029
+			$pos = $this->position++;
5030
+			$depth = $this->depth++;
5031
+			// set self as current value for this depth
5032
+			$this->depth_array[$depth] = $pos;
5033
+			$this->message[$pos] = ['cdata' => ''];
5034
+			// process attributes
5035
+			if (is_array($attrs) && count($attrs) > 0) {
5036
+				// register namespace declarations
5037
+				foreach ($attrs as $k => $v) {
5038
+					if (preg_match('/^xmlns/', $k)) {
5039
+						if (false !== ($ns_prefix = substr(strrchr($k, ':'), 1))) {
5040
+							$this->namespaces[$ns_prefix] = $v;
5041
+						} else {
5042
+							$this->namespaces['ns' . (count($this->namespaces) + 1)] = $v;
5043
+						}
5044
+						if ('http://www.w3.org/2001/XMLSchema' === $v || 'http://www.w3.org/1999/XMLSchema' === $v || 'http://www.w3.org/2000/10/XMLSchema' === $v) {
5045
+							$this->XMLSchemaVersion = $v;
5046
+							$this->namespaces['xsi'] = $v . '-instance';
5047
+						}
5048
+					}
5049
+				}
5050
+				// expand each attribute prefix to its namespace
5051
+				foreach ($attrs as $k => $v) {
5052
+					$k = strpos($k, ':') ? $this->expandQname($k) : $k;
5053
+					if ('location' !== $k && 'soapAction' !== $k && 'namespace' !== $k) {
5054
+						$v = strpos($v, ':') ? $this->expandQname($v) : $v;
5055
+					}
5056
+					$eAttrs[$k] = $v;
5057
+				}
5058
+				$attrs = $eAttrs;
5059
+			} else {
5060
+				$attrs = [];
5061
+			}
5062
+			// Set default prefix and namespace
5063
+			// to prevent error Undefined variable $prefix and $namespace if (preg_match('/:/', $name)) return 0 or FALSE
5064
+			$prefix = '';
5065
+			$namespace = '';
5066
+			// get element prefix, namespace and name
5067
+			if (preg_match('/:/', $name)) {
5068
+				// get ns prefix
5069
+				$prefix = substr($name, 0, strpos($name, ':'));
5070
+				// get ns
5071
+				$namespace = isset($this->namespaces[$prefix]) ? $this->namespaces[$prefix] : '';
5072
+				// get unqualified name
5073
+				$name = substr(strstr($name, ':'), 1);
5074
+			}
5075
+			// process attributes, expanding any prefixes to namespaces
5076
+			// find status, register data
5077
+			switch ($this->status) {
5078
+				case 'message':
5079
+					if ('part' === $name) {
5080
+						if (isset($attrs['type'])) {
5081
+							$this->debug('msg ' . $this->currentMessage . ": found part (with type) $attrs[name]: " . implode(',', $attrs));
5082
+							$this->messages[$this->currentMessage][$attrs['name']] = $attrs['type'];
5083
+						}
5084
+						if (isset($attrs['element'])) {
5085
+							$this->debug('msg ' . $this->currentMessage . ": found part (with element) $attrs[name]: " . implode(',', $attrs));
5086
+							$this->messages[$this->currentMessage][$attrs['name']] = $attrs['element'] . '^';
5087
+						}
5088
+					}
5089
+					break;
5090
+				case 'portType':
5091
+					switch ($name) {
5092
+						case 'operation':
5093
+							$this->currentPortOperation = $attrs['name'];
5094
+							$this->debug("portType $this->currentPortType operation: $this->currentPortOperation");
5095
+							if (isset($attrs['parameterOrder'])) {
5096
+								$this->portTypes[$this->currentPortType][$attrs['name']]['parameterOrder'] = $attrs['parameterOrder'];
5097
+							}
5098
+							break;
5099
+						case 'documentation':
5100
+							$this->documentation = true;
5101
+							break;
5102
+						// merge input/output data
5103
+						default:
5104
+							$m = isset($attrs['message']) ? $this->getLocalPart($attrs['message']) : '';
5105
+							$this->portTypes[$this->currentPortType][$this->currentPortOperation][$name]['message'] = $m;
5106
+							break;
5107
+					}
5108
+					break;
5109
+				case 'binding':
5110
+					switch ($name) {
5111
+						case 'binding':
5112
+							// get ns prefix
5113
+							if (isset($attrs['style'])) {
5114
+								$this->bindings[$this->currentBinding]['prefix'] = $prefix;
5115
+							}
5116
+							$this->bindings[$this->currentBinding] = array_merge($this->bindings[$this->currentBinding], $attrs);
5117
+							break;
5118
+						case 'header':
5119
+							$this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus]['headers'][] = $attrs;
5120
+							break;
5121
+						case 'operation':
5122
+							if (isset($attrs['soapAction'])) {
5123
+								$this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['soapAction'] = $attrs['soapAction'];
5124
+							}
5125
+							if (isset($attrs['style'])) {
5126
+								$this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['style'] = $attrs['style'];
5127
+							}
5128
+							if (isset($attrs['name'])) {
5129
+								$this->currentOperation = $attrs['name'];
5130
+								$this->debug("current binding operation: $this->currentOperation");
5131
+								$this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['name'] = $attrs['name'];
5132
+								$this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['binding'] = $this->currentBinding;
5133
+								$this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['endpoint'] = isset($this->bindings[$this->currentBinding]['endpoint']) ? $this->bindings[$this->currentBinding]['endpoint'] : '';
5134
+							}
5135
+							break;
5136
+						case 'input':
5137
+							$this->opStatus = 'input';
5138
+							break;
5139
+						case 'output':
5140
+							$this->opStatus = 'output';
5141
+							break;
5142
+						case 'body':
5143
+							if (isset($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus])) {
5144
+								$this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = array_merge($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus], $attrs);
5145
+							} else {
5146
+								$this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = $attrs;
5147
+							}
5148
+							break;
5149
+					}
5150
+					break;
5151
+				case 'service':
5152
+					switch ($name) {
5153
+						case 'port':
5154
+							$this->currentPort = $attrs['name'];
5155
+							$this->debug('current port: ' . $this->currentPort);
5156
+							$this->ports[$this->currentPort]['binding'] = $this->getLocalPart($attrs['binding']);
5157
+
5158
+							break;
5159
+						case 'address':
5160
+							$this->ports[$this->currentPort]['location'] = $attrs['location'];
5161
+							$this->ports[$this->currentPort]['bindingType'] = $namespace;
5162
+							$this->bindings[$this->ports[$this->currentPort]['binding']]['bindingType'] = $namespace;
5163
+							$this->bindings[$this->ports[$this->currentPort]['binding']]['endpoint'] = $attrs['location'];
5164
+							break;
5165
+					}
5166
+					break;
5167
+			}
5168
+			// set status
5169
+			switch ($name) {
5170
+				case 'import':
5171
+					if (isset($attrs['location'])) {
5172
+						$this->import[$attrs['namespace']][] = ['location' => $attrs['location'], 'loaded' => false];
5173
+						$this->debug('parsing import ' . $attrs['namespace'] . ' - ' . $attrs['location'] . ' (' . count($this->import[$attrs['namespace']]) . ')');
5174
+					} else {
5175
+						$this->import[$attrs['namespace']][] = ['location' => '', 'loaded' => true];
5176
+						if (!$this->getPrefixFromNamespace($attrs['namespace'])) {
5177
+							$this->namespaces['ns' . (count($this->namespaces) + 1)] = $attrs['namespace'];
5178
+						}
5179
+						$this->debug('parsing import ' . $attrs['namespace'] . ' - [no location] (' . count($this->import[$attrs['namespace']]) . ')');
5180
+					}
5181
+					break;
5182
+				//wait for schema
5183
+				//case 'types':
5184
+				//	$this->status = 'schema';
5185
+				//	break;
5186
+				case 'message':
5187
+					$this->status = 'message';
5188
+					$this->messages[$attrs['name']] = [];
5189
+					$this->currentMessage = $attrs['name'];
5190
+					break;
5191
+				case 'portType':
5192
+					$this->status = 'portType';
5193
+					$this->portTypes[$attrs['name']] = [];
5194
+					$this->currentPortType = $attrs['name'];
5195
+					break;
5196
+				case 'binding':
5197
+					if (isset($attrs['name'])) {
5198
+						// get binding name
5199
+						if (strpos($attrs['name'], ':')) {
5200
+							$this->currentBinding = $this->getLocalPart($attrs['name']);
5201
+						} else {
5202
+							$this->currentBinding = $attrs['name'];
5203
+						}
5204
+						$this->status = 'binding';
5205
+						$this->bindings[$this->currentBinding]['portType'] = $this->getLocalPart($attrs['type']);
5206
+						$this->debug("current binding: $this->currentBinding of portType: " . $attrs['type']);
5207
+					}
5208
+					break;
5209
+				case 'service':
5210
+					$this->serviceName = $attrs['name'];
5211
+					$this->status = 'service';
5212
+					$this->debug('current service: ' . $this->serviceName);
5213
+					break;
5214
+				case 'definitions':
5215
+					foreach ($attrs as $name => $value) {
5216
+						$this->wsdl_info[$name] = $value;
5217
+					}
5218
+					break;
5219
+			}
5220
+		}
5221
+	}
5222
+
5223
+	/**
5224
+	 * end-element handler
5225
+	 *
5226
+	 * @param string $parser XML parser object
5227
+	 * @param string $name element name
5228
+	 * @access private
5229
+	 */
5230
+	private function end_element($parser, $name)
5231
+	{
5232
+		// unset schema status
5233
+		if (/*preg_match('/types$/', $name) ||*/
5234
+		preg_match('/schema$/', $name)
5235
+		) {
5236
+			$this->status = '';
5237
+			$this->appendDebug($this->currentSchema->getDebug());
5238
+			$this->currentSchema->clearDebug();
5239
+			$this->schemas[$this->currentSchema->schemaTargetNamespace][] = $this->currentSchema;
5240
+			$this->debug('Parsing WSDL schema done');
5241
+		}
5242
+		if ('schema' === $this->status) {
5243
+			$this->currentSchema->schemaEndElement($parser, $name);
5244
+		} else {
5245
+			// bring depth down a notch
5246
+			$this->depth--;
5247
+		}
5248
+		// end documentation
5249
+		if ($this->documentation) {
5250
+			//TODO: track the node to which documentation should be assigned; it can be a part, message, etc.
5251
+			//$this->portTypes[$this->currentPortType][$this->currentPortOperation]['documentation'] = $this->documentation;
5252
+			$this->documentation = false;
5253
+		}
5254
+	}
5255
+
5256
+	/**
5257
+	 * element content handler
5258
+	 *
5259
+	 * @param string $parser XML parser object
5260
+	 * @param string $data element content
5261
+	 * @access private
5262
+	 */
5263
+	private function character_data($parser, $data)
5264
+	{
5265
+		$pos = isset($this->depth_array[$this->depth]) ? $this->depth_array[$this->depth] : 0;
5266
+		if (isset($this->message[$pos]['cdata'])) {
5267
+			$this->message[$pos]['cdata'] .= $data;
5268
+		}
5269
+		if ($this->documentation) {
5270
+			$this->documentation .= $data;
5271
+		}
5272
+	}
5273
+
5274
+	/**
5275
+	 * if authenticating, set user credentials here
5276
+	 *
5277
+	 * @param    string $username
5278
+	 * @param    string $password
5279
+	 * @param    string $authtype (basic|digest|certificate|ntlm)
5280
+	 * @param    array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs)
5281
+	 * @access   public
5282
+	 */
5283
+	public function setCredentials($username, $password, $authtype = 'basic', $certRequest = [])
5284
+	{
5285
+		$this->debug("setCredentials username=$username authtype=$authtype certRequest=");
5286
+		$this->appendDebug($this->varDump($certRequest));
5287
+		$this->username = $username;
5288
+		$this->password = $password;
5289
+		$this->authtype = $authtype;
5290
+		$this->certRequest = $certRequest;
5291
+	}
5292
+
5293
+	/**
5294
+	 * @param $binding
5295
+	 * @return mixed
5296
+	 */
5297
+	public function getBindingData($binding)
5298
+	{
5299
+		if (is_array($this->bindings[$binding])) {
5300
+			return $this->bindings[$binding];
5301
+		}
5302
+	}
5303
+
5304
+	/**
5305
+	 * returns an assoc array of operation names => operation data
5306
+	 *
5307
+	 * @param string $portName WSDL port name
5308
+	 * @param string $bindingType eg: soap, smtp, dime (only soap and soap12 are currently supported)
5309
+	 * @return array
5310
+	 * @access public
5311
+	 */
5312
+	public function getOperations($portName = '', $bindingType = 'soap')
5313
+	{
5314
+		$ops = [];
5315
+		if ('soap' === $bindingType) {
5316
+			$bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/';
5317
+		} elseif ('soap12' === $bindingType) {
5318
+			$bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/';
5319
+		} else {
5320
+			$this->debug("getOperations bindingType $bindingType may not be supported");
5321
+		}
5322
+		$this->debug("getOperations for port '$portName' bindingType $bindingType");
5323
+		// loop thru ports
5324
+		foreach ($this->ports as $port => $portData) {
5325
+			$this->debug("getOperations checking port $port bindingType " . $portData['bindingType']);
5326
+			if ('' == $portName || $port == $portName) {
5327
+				// binding type of port matches parameter
5328
+				if ($portData['bindingType'] == $bindingType) {
5329
+					$this->debug("getOperations found port $port bindingType $bindingType");
5330
+					//$this->debug("port data: " . $this->varDump($portData));
5331
+					//$this->debug("bindings: " . $this->varDump($this->bindings[ $portData['binding'] ]));
5332
+					// merge bindings
5333
+					if (isset($this->bindings[$portData['binding']]['operations'])) {
5334
+						$ops = array_merge($ops, $this->bindings[$portData['binding']]['operations']);
5335
+					}
5336
+				}
5337
+			}
5338
+		}
5339
+		if (0 == count($ops)) {
5340
+			$this->debug("getOperations found no operations for port '$portName' bindingType $bindingType");
5341
+		}
5342
+		return $ops;
5343
+	}
5344
+
5345
+	/**
5346
+	 * returns an associative array of data necessary for calling an operation
5347
+	 *
5348
+	 * @param string $operation name of operation
5349
+	 * @param string $bindingType type of binding eg: soap, soap12
5350
+	 * @return array
5351
+	 * @access public
5352
+	 */
5353
+	public function getOperationData($operation, $bindingType = 'soap')
5354
+	{
5355
+		if ('soap' === $bindingType) {
5356
+			$bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/';
5357
+		} elseif ('soap12' === $bindingType) {
5358
+			$bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/';
5359
+		}
5360
+		// loop thru ports
5361
+		foreach ($this->ports as $port => $portData) {
5362
+			// binding type of port matches parameter
5363
+			if ($portData['bindingType'] == $bindingType) {
5364
+				// get binding
5365
+				//foreach($this->bindings[ $portData['binding'] ]['operations'] as $bOperation => $opData) {
5366
+				foreach (array_keys($this->bindings[$portData['binding']]['operations']) as $bOperation) {
5367
+					// note that we could/should also check the namespace here
5368
+					if ($operation == $bOperation) {
5369
+						$opData = $this->bindings[$portData['binding']]['operations'][$operation];
5370
+						return $opData;
5371
+					}
5372
+				}
5373
+			}
5374
+		}
5375
+	}
5376
+
5377
+	/**
5378
+	 * returns an associative array of data necessary for calling an operation
5379
+	 *
5380
+	 * @param string $soapAction soapAction for operation
5381
+	 * @param string $bindingType type of binding eg: soap, soap12
5382
+	 * @return array
5383
+	 * @access public
5384
+	 */
5385
+	public function getOperationDataForSoapAction($soapAction, $bindingType = 'soap')
5386
+	{
5387
+		if ('soap' === $bindingType) {
5388
+			$bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/';
5389
+		} elseif ('soap12' === $bindingType) {
5390
+			$bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/';
5391
+		}
5392
+		// loop thru ports
5393
+		foreach ($this->ports as $port => $portData) {
5394
+			// binding type of port matches parameter
5395
+			if ($portData['bindingType'] == $bindingType) {
5396
+				// loop through operations for the binding
5397
+				foreach ($this->bindings[$portData['binding']]['operations'] as $bOperation => $opData) {
5398
+					if ($opData['soapAction'] == $soapAction) {
5399
+						return $opData;
5400
+					}
5401
+				}
5402
+			}
5403
+		}
5404
+	}
5405
+
5406
+	/**
5407
+	 * returns an array of information about a given type
5408
+	 * returns false if no type exists by the given name
5409
+	 *
5410
+	 *     typeDef = array(
5411
+	 *     'elements' => array(), // refs to elements array
5412
+	 *    'restrictionBase' => '',
5413
+	 *    'phpType' => '',
5414
+	 *    'order' => '(sequence|all)',
5415
+	 *    'attrs' => array() // refs to attributes array
5416
+	 *    )
5417
+	 *
5418
+	 * @param string $type the type
5419
+	 * @param string $ns namespace (not prefix) of the type
5420
+	 * @return mixed
5421
+	 * @access public
5422
+	 * @see nusoap_xmlschema
5423
+	 */
5424
+	public function getTypeDef($type, $ns)
5425
+	{
5426
+		$this->debug("in getTypeDef: type=$type, ns=$ns");
5427
+		if ((!$ns) && isset($this->namespaces['tns'])) {
5428
+			$ns = $this->namespaces['tns'];
5429
+			$this->debug("in getTypeDef: type namespace forced to $ns");
5430
+		}
5431
+		if (!isset($this->schemas[$ns])) {
5432
+			foreach ($this->schemas as $ns0 => $schema0) {
5433
+				if (0 == strcasecmp($ns, $ns0)) {
5434
+					$this->debug("in getTypeDef: replacing schema namespace $ns with $ns0");
5435
+					$ns = $ns0;
5436
+					break;
5437
+				}
5438
+			}
5439
+		}
5440
+		if (isset($this->schemas[$ns])) {
5441
+			$this->debug("in getTypeDef: have schema for namespace $ns");
5442
+			for ($i = 0, $iMax = count($this->schemas[$ns]); $i < $iMax; $i++) {
5443
+				$xs = &$this->schemas[$ns][$i];
5444
+				$t = $xs->getTypeDef($type);
5445
+				$this->appendDebug($xs->getDebug());
5446
+				$xs->clearDebug();
5447
+				if ($t) {
5448
+					$this->debug("in getTypeDef: found type $type");
5449
+					if (!isset($t['phpType'])) {
5450
+						// get info for type to tack onto the element
5451
+						$uqType = substr($t['type'], strrpos($t['type'], ':') + 1);
5452
+						$ns = substr($t['type'], 0, strrpos($t['type'], ':'));
5453
+						$etype = $this->getTypeDef($uqType, $ns);
5454
+						if ($etype) {
5455
+							$this->debug("found type for [element] $type:");
5456
+							$this->debug($this->varDump($etype));
5457
+							if (isset($etype['phpType'])) {
5458
+								$t['phpType'] = $etype['phpType'];
5459
+							}
5460
+							if (isset($etype['elements'])) {
5461
+								$t['elements'] = $etype['elements'];
5462
+							}
5463
+							if (isset($etype['attrs'])) {
5464
+								$t['attrs'] = $etype['attrs'];
5465
+							}
5466
+						} else {
5467
+							$this->debug("did not find type for [element] $type");
5468
+						}
5469
+					}
5470
+					return $t;
5471
+				}
5472
+			}
5473
+			$this->debug("in getTypeDef: did not find type $type");
5474
+		} else {
5475
+			$this->debug("in getTypeDef: do not have schema for namespace $ns");
5476
+		}
5477
+		return false;
5478
+	}
5479
+
5480
+	/**
5481
+	 * prints html description of services
5482
+	 *
5483
+	 * @access private
5484
+	 */
5485
+	public function webDescription()
5486
+	{
5487
+		global $HTTP_SERVER_VARS;
5488
+
5489
+		if (isset($_SERVER)) {
5490
+			$PHP_SELF = $_SERVER['PHP_SELF'];
5491
+		} elseif (isset($HTTP_SERVER_VARS)) {
5492
+			$PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF'];
5493
+		} else {
5494
+			$this->setError('Neither _SERVER nor HTTP_SERVER_VARS is available');
5495
+		}
5496
+
5497
+		$b = '
5498 5498
 		<html><head><title>NuSOAP: ' . $this->serviceName . '</title>
5499 5499
 		<style type="text/css">
5500 5500
 		    body    { font-family: arial; color: #000000; background-color: #ffffff; margin: 0px 0px 0px 0px; }
@@ -5577,1098 +5577,1098 @@  discard block
 block discarded – undo
5577 5577
 				<p>View the <a href="' . $PHP_SELF . '?wsdl">WSDL</a> for the service.
5578 5578
 				Click on an operation name to view it&apos;s details.</p>
5579 5579
 				<ul>';
5580
-        foreach ($this->getOperations() as $op => $data) {
5581
-            $b .= "<li><a href='#' onclick=\"popout();popup('$op')\">$op</a></li>";
5582
-            // create hidden div
5583
-            $b .= "<div id='$op' class='hidden'>
5580
+		foreach ($this->getOperations() as $op => $data) {
5581
+			$b .= "<li><a href='#' onclick=\"popout();popup('$op')\">$op</a></li>";
5582
+			// create hidden div
5583
+			$b .= "<div id='$op' class='hidden'>
5584 5584
 				    <a href='#' onclick='popout()'><font color='#ffffff'>Close</font></a><br><br>";
5585
-            foreach ($data as $donnie => $marie) { // loop through opdata
5586
-                if ('input' === $donnie || 'output' === $donnie) { // show input/output data
5587
-                    $b .= "<font color='white'>" . ucfirst($donnie) . ':</font><br>';
5588
-                    foreach ($marie as $captain => $tenille) { // loop through data
5589
-                        if ('parts' === $captain) { // loop thru parts
5590
-                            $b .= "&nbsp;&nbsp;$captain:<br>";
5591
-                            //if(is_array($tenille)){
5592
-                            foreach ($tenille as $joanie => $chachi) {
5593
-                                $b .= "&nbsp;&nbsp;&nbsp;&nbsp;$joanie: $chachi<br>";
5594
-                            }
5595
-                            //}
5596
-                        } else {
5597
-                            $b .= "&nbsp;&nbsp;$captain: $tenille<br>";
5598
-                        }
5599
-                    }
5600
-                } else {
5601
-                    $b .= "<font color='white'>" . ucfirst($donnie) . ":</font> $marie<br>";
5602
-                }
5603
-            }
5604
-            $b .= '</div>';
5605
-        }
5606
-        $b .= '
5585
+			foreach ($data as $donnie => $marie) { // loop through opdata
5586
+				if ('input' === $donnie || 'output' === $donnie) { // show input/output data
5587
+					$b .= "<font color='white'>" . ucfirst($donnie) . ':</font><br>';
5588
+					foreach ($marie as $captain => $tenille) { // loop through data
5589
+						if ('parts' === $captain) { // loop thru parts
5590
+							$b .= "&nbsp;&nbsp;$captain:<br>";
5591
+							//if(is_array($tenille)){
5592
+							foreach ($tenille as $joanie => $chachi) {
5593
+								$b .= "&nbsp;&nbsp;&nbsp;&nbsp;$joanie: $chachi<br>";
5594
+							}
5595
+							//}
5596
+						} else {
5597
+							$b .= "&nbsp;&nbsp;$captain: $tenille<br>";
5598
+						}
5599
+					}
5600
+				} else {
5601
+					$b .= "<font color='white'>" . ucfirst($donnie) . ":</font> $marie<br>";
5602
+				}
5603
+			}
5604
+			$b .= '</div>';
5605
+		}
5606
+		$b .= '
5607 5607
 				<ul>
5608 5608
 			</div>
5609 5609
 		</div></body></html>';
5610
-        return $b;
5611
-    }
5612
-
5613
-    /**
5614
-     * serialize the parsed wsdl
5615
-     *
5616
-     * @param mixed $debug whether to put debug=1 in endpoint URL
5617
-     * @return string serialization of WSDL
5618
-     * @access public
5619
-     */
5620
-    public function serialize($debug = 0)
5621
-    {
5622
-        $xml = '<?xml version="1.0" encoding="ISO-8859-1"?>';
5623
-        $xml .= "\n<definitions";
5624
-        foreach ($this->namespaces as $k => $v) {
5625
-            $xml .= " xmlns:$k=\"$v\"";
5626
-        }
5627
-        // 10.9.02 - add poulter fix for wsdl and tns declarations
5628
-        if (isset($this->namespaces['wsdl'])) {
5629
-            $xml .= ' xmlns="' . $this->namespaces['wsdl'] . '"';
5630
-        }
5631
-        if (isset($this->namespaces['tns'])) {
5632
-            $xml .= ' targetNamespace="' . $this->namespaces['tns'] . '"';
5633
-        }
5634
-        $xml .= '>';
5635
-        // imports
5636
-        if (is_array($this->import) && count($this->import) > 0) {
5637
-            foreach ($this->import as $ns => $list) {
5638
-                foreach ($list as $ii) {
5639
-                    if ('' != $ii['location']) {
5640
-                        $xml .= '<import location="' . $ii['location'] . '" namespace="' . $ns . '" />';
5641
-                    } else {
5642
-                        $xml .= '<import namespace="' . $ns . '" />';
5643
-                    }
5644
-                }
5645
-            }
5646
-        }
5647
-        // types
5648
-        if (is_array($this->schemas) && count($this->schemas) >= 1) {
5649
-            $xml .= "\n<types>\n";
5650
-            foreach ($this->schemas as $ns => $list) {
5651
-                foreach ($list as $xs) {
5652
-                    $xml .= $xs->serializeSchema();
5653
-                }
5654
-            }
5655
-            $xml .= '</types>';
5656
-        }
5657
-        // messages
5658
-        if (is_array($this->messages) && count($this->messages) >= 1) {
5659
-            foreach ($this->messages as $msgName => $msgParts) {
5660
-                $xml .= "\n<message name=\"" . $msgName . '">';
5661
-                if (is_array($msgParts)) {
5662
-                    foreach ($msgParts as $partName => $partType) {
5663
-                        // print 'serializing '.$partType.', sv: '.$this->XMLSchemaVersion.'<br>';
5664
-                        if (strpos($partType, ':')) {
5665
-                            $typePrefix = $this->getPrefixFromNamespace($this->getPrefix($partType));
5666
-                        } elseif (isset($this->typemap[$this->namespaces['xsd']][$partType])) {
5667
-                            // print 'checking typemap: '.$this->XMLSchemaVersion.'<br>';
5668
-                            $typePrefix = 'xsd';
5669
-                        } else {
5670
-                            foreach ($this->typemap as $ns => $types) {
5671
-                                if (isset($types[$partType])) {
5672
-                                    $typePrefix = $this->getPrefixFromNamespace($ns);
5673
-                                }
5674
-                            }
5675
-                            if (!isset($typePrefix)) {
5676
-                                die("$partType has no namespace!");
5677
-                            }
5678
-                        }
5679
-                        $ns = $this->getNamespaceFromPrefix($typePrefix);
5680
-                        $localPart = $this->getLocalPart($partType);
5681
-                        $typeDef = $this->getTypeDef($localPart, $ns);
5682
-                        if ('element' === $typeDef['typeClass']) {
5683
-                            $elementortype = 'element';
5684
-                            if ('^' === substr($localPart, -1)) {
5685
-                                $localPart = substr($localPart, 0, -1);
5686
-                            }
5687
-                        } else {
5688
-                            $elementortype = 'type';
5689
-                        }
5690
-                        $xml .= "\n" . '  <part name="' . $partName . '" ' . $elementortype . '="' . $typePrefix . ':' . $localPart . '" />';
5691
-                    }
5692
-                }
5693
-                $xml .= '</message>';
5694
-            }
5695
-        }
5696
-        // bindings & porttypes
5697
-        if (is_array($this->bindings) && count($this->bindings) >= 1) {
5698
-            $binding_xml = '';
5699
-            $portType_xml = '';
5700
-            foreach ($this->bindings as $bindingName => $attrs) {
5701
-                $binding_xml .= "\n<binding name=\"" . $bindingName . '" type="tns:' . $attrs['portType'] . '">';
5702
-                $binding_xml .= "\n" . '  <soap:binding style="' . $attrs['style'] . '" transport="' . $attrs['transport'] . '"/>';
5703
-                $portType_xml .= "\n<portType name=\"" . $attrs['portType'] . '">';
5704
-                foreach ($attrs['operations'] as $opName => $opParts) {
5705
-                    $binding_xml .= "\n" . '  <operation name="' . $opName . '">';
5706
-                    $binding_xml .= "\n" . '    <soap:operation soapAction="' . $opParts['soapAction'] . '" style="' . $opParts['style'] . '"/>';
5707
-                    if (isset($opParts['input']['encodingStyle']) && '' != $opParts['input']['encodingStyle']) {
5708
-                        $enc_style = ' encodingStyle="' . $opParts['input']['encodingStyle'] . '"';
5709
-                    } else {
5710
-                        $enc_style = '';
5711
-                    }
5712
-                    $binding_xml .= "\n" . '    <input><soap:body use="' . $opParts['input']['use'] . '" namespace="' . $opParts['input']['namespace'] . '"' . $enc_style . '/></input>';
5713
-                    if (isset($opParts['output']['encodingStyle']) && '' != $opParts['output']['encodingStyle']) {
5714
-                        $enc_style = ' encodingStyle="' . $opParts['output']['encodingStyle'] . '"';
5715
-                    } else {
5716
-                        $enc_style = '';
5717
-                    }
5718
-                    $binding_xml .= "\n" . '    <output><soap:body use="' . $opParts['output']['use'] . '" namespace="' . $opParts['output']['namespace'] . '"' . $enc_style . '/></output>';
5719
-                    $binding_xml .= "\n" . '  </operation>';
5720
-                    $portType_xml .= "\n" . '  <operation name="' . $opParts['name'] . '"';
5721
-                    if (isset($opParts['parameterOrder'])) {
5722
-                        $portType_xml .= ' parameterOrder="' . $opParts['parameterOrder'] . '"';
5723
-                    }
5724
-                    $portType_xml .= '>';
5725
-                    if (isset($opParts['documentation']) && '' != $opParts['documentation']) {
5726
-                        $portType_xml .= "\n" . '    <documentation>' . htmlspecialchars($opParts['documentation']) . '</documentation>';
5727
-                    }
5728
-                    $portType_xml .= "\n" . '    <input message="tns:' . $opParts['input']['message'] . '"/>';
5729
-                    $portType_xml .= "\n" . '    <output message="tns:' . $opParts['output']['message'] . '"/>';
5730
-                    $portType_xml .= "\n" . '  </operation>';
5731
-                }
5732
-                $portType_xml .= "\n" . '</portType>';
5733
-                $binding_xml .= "\n" . '</binding>';
5734
-            }
5735
-            $xml .= $portType_xml . $binding_xml;
5736
-        }
5737
-        // services
5738
-        $xml .= "\n<service name=\"" . $this->serviceName . '">';
5739
-        if (is_array($this->ports) && count($this->ports) >= 1) {
5740
-            foreach ($this->ports as $pName => $attrs) {
5741
-                $xml .= "\n" . '  <port name="' . $pName . '" binding="tns:' . $attrs['binding'] . '">';
5742
-                $xml .= "\n" . '    <soap:address location="' . $attrs['location'] . ($debug ? '?debug=1' : '') . '"/>';
5743
-                $xml .= "\n" . '  </port>';
5744
-            }
5745
-        }
5746
-        $xml .= "\n" . '</service>';
5747
-        return $xml . "\n</definitions>";
5748
-    }
5749
-
5750
-    /**
5751
-     * determine whether a set of parameters are unwrapped
5752
-     * when they are expect to be wrapped, Microsoft-style.
5753
-     *
5754
-     * @param string $type the type (element name) of the wrapper
5755
-     * @param array $parameters the parameter values for the SOAP call
5756
-     * @return boolean whether they parameters are unwrapped (and should be wrapped)
5757
-     * @access private
5758
-     */
5759
-    private function parametersMatchWrapped($type, &$parameters)
5760
-    {
5761
-        $this->debug("in parametersMatchWrapped type=$type, parameters=");
5762
-        $this->appendDebug($this->varDump($parameters));
5763
-
5764
-        // split type into namespace:unqualified-type
5765
-        if (strpos($type, ':')) {
5766
-            $uqType = substr($type, strrpos($type, ':') + 1);
5767
-            $ns = substr($type, 0, strrpos($type, ':'));
5768
-            $this->debug("in parametersMatchWrapped: got a prefixed type: $uqType, $ns");
5769
-            if ($this->getNamespaceFromPrefix($ns)) {
5770
-                $ns = $this->getNamespaceFromPrefix($ns);
5771
-                $this->debug("in parametersMatchWrapped: expanded prefixed type: $uqType, $ns");
5772
-            }
5773
-        } else {
5774
-            // TODO: should the type be compared to types in XSD, and the namespace
5775
-            // set to XSD if the type matches?
5776
-            $this->debug("in parametersMatchWrapped: No namespace for type $type");
5777
-            $ns = '';
5778
-            $uqType = $type;
5779
-        }
5780
-
5781
-        // get the type information
5782
-        if (!$typeDef = $this->getTypeDef($uqType, $ns)) {
5783
-            $this->debug("in parametersMatchWrapped: $type ($uqType) is not a supported type.");
5784
-            return false;
5785
-        }
5786
-        $this->debug('in parametersMatchWrapped: found typeDef=');
5787
-        $this->appendDebug($this->varDump($typeDef));
5788
-        if ('^' === substr($uqType, -1)) {
5789
-            $uqType = substr($uqType, 0, -1);
5790
-        }
5791
-        $phpType = $typeDef['phpType'];
5792
-        $arrayType = (isset($typeDef['arrayType']) ? $typeDef['arrayType'] : '');
5793
-        $this->debug("in parametersMatchWrapped: uqType: $uqType, ns: $ns, phptype: $phpType, arrayType: $arrayType");
5794
-
5795
-        // we expect a complexType or element of complexType
5796
-        if ('struct' !== $phpType) {
5797
-            $this->debug('in parametersMatchWrapped: not a struct');
5798
-            return false;
5799
-        }
5800
-
5801
-        // see whether the parameter names match the elements
5802
-        if (isset($typeDef['elements']) && is_array($typeDef['elements'])) {
5803
-            $elements = 0;
5804
-            $matches = 0;
5805
-            foreach ($typeDef['elements'] as $name => $attrs) {
5806
-                if (isset($parameters[$name])) {
5807
-                    $this->debug("in parametersMatchWrapped: have parameter named $name");
5808
-                    $matches++;
5809
-                } else {
5810
-                    $this->debug("in parametersMatchWrapped: do not have parameter named $name");
5811
-                }
5812
-                $elements++;
5813
-            }
5814
-
5815
-            $this->debug("in parametersMatchWrapped: $matches parameter names match $elements wrapped parameter names");
5816
-            if (0 == $matches) {
5817
-                return false;
5818
-            }
5819
-            return true;
5820
-        }
5821
-
5822
-        // since there are no elements for the type, if the user passed no
5823
-        // parameters, the parameters match wrapped.
5824
-        $this->debug("in parametersMatchWrapped: no elements type $ns:$uqType");
5825
-        return 0 == count($parameters);
5826
-    }
5827
-
5828
-    /**
5829
-     * serialize PHP values according to a WSDL message definition
5830
-     * contrary to the method name, this is not limited to RPC
5831
-     *
5832
-     * TODO
5833
-     * - multi-ref serialization
5834
-     * - validate PHP values against type definitions, return errors if invalid
5835
-     *
5836
-     * @param string $operation operation name
5837
-     * @param string $direction (input|output)
5838
-     * @param mixed $parameters parameter value(s)
5839
-     * @param string $bindingType (soap|soap12)
5840
-     * @return mixed parameters serialized as XML or false on error (e.g. operation not found)
5841
-     * @access public
5842
-     */
5843
-    public function serializeRPCParameters($operation, $direction, $parameters, $bindingType = 'soap')
5844
-    {
5845
-        $this->debug("in serializeRPCParameters: operation=$operation, direction=$direction, XMLSchemaVersion=$this->XMLSchemaVersion, bindingType=$bindingType");
5846
-        $this->appendDebug('parameters=' . $this->varDump($parameters));
5847
-
5848
-        if ('input' !== $direction && 'output' !== $direction) {
5849
-            $this->debug('The value of the \$direction argument needs to be either "input" or "output"');
5850
-            $this->setError('The value of the \$direction argument needs to be either "input" or "output"');
5851
-            return false;
5852
-        }
5853
-        if (!$opData = $this->getOperationData($operation, $bindingType)) {
5854
-            $this->debug('Unable to retrieve WSDL data for operation: ' . $operation . ' bindingType: ' . $bindingType);
5855
-            $this->setError('Unable to retrieve WSDL data for operation: ' . $operation . ' bindingType: ' . $bindingType);
5856
-            return false;
5857
-        }
5858
-        $this->debug('in serializeRPCParameters: opData:');
5859
-        $this->appendDebug($this->varDump($opData));
5860
-
5861
-        // Get encoding style for output and set to current
5862
-        $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
5863
-        if (('input' === $direction) && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) {
5864
-            $encodingStyle = $opData['output']['encodingStyle'];
5865
-            $enc_style = $encodingStyle;
5866
-        }
5867
-
5868
-        // set input params
5869
-        $xml = '';
5870
-        if (isset($opData[$direction]['parts']) && count($opData[$direction]['parts']) > 0) {
5871
-            $parts = &$opData[$direction]['parts'];
5872
-            $part_count = count($parts);
5873
-            $style = $opData['style'];
5874
-            $use = $opData[$direction]['use'];
5875
-            $this->debug("have $part_count part(s) to serialize using $style/$use");
5876
-            if (is_array($parameters)) {
5877
-                $parametersArrayType = $this->isArraySimpleOrStruct($parameters);
5878
-                $parameter_count = count($parameters);
5879
-                $this->debug("have $parameter_count parameter(s) provided as $parametersArrayType to serialize");
5880
-                // check for Microsoft-style wrapped parameters
5881
-                if ('document' === $style && 'literal' === $use && 1 == $part_count && isset($parts['parameters'])) {
5882
-                    $this->debug('check whether the caller has wrapped the parameters');
5883
-                    if ('output' === $direction && 'arraySimple' === $parametersArrayType && 1 == $parameter_count) {
5884
-                        // TODO: consider checking here for double-wrapping, when
5885
-                        // service function wraps, then NuSOAP wraps again
5886
-                        $this->debug("change simple array to associative with 'parameters' element");
5887
-                        $parameters['parameters'] = $parameters[0];
5888
-                        unset($parameters[0]);
5889
-                    }
5890
-                    if (('arrayStruct' === $parametersArrayType || 0 == $parameter_count) && !isset($parameters['parameters'])) {
5891
-                        $this->debug('check whether caller\'s parameters match the wrapped ones');
5892
-                        if ($this->parametersMatchWrapped($parts['parameters'], $parameters)) {
5893
-                            $this->debug('wrap the parameters for the caller');
5894
-                            $parameters = ['parameters' => $parameters];
5895
-                            $parameter_count = 1;
5896
-                        }
5897
-                    }
5898
-                }
5899
-                foreach ($parts as $name => $type) {
5900
-                    $this->debug("serializing part $name of type $type");
5901
-                    // Track encoding style
5902
-                    if (isset($opData[$direction]['encodingStyle']) && $encodingStyle != $opData[$direction]['encodingStyle']) {
5903
-                        $encodingStyle = $opData[$direction]['encodingStyle'];
5904
-                        $enc_style = $encodingStyle;
5905
-                    } else {
5906
-                        $enc_style = false;
5907
-                    }
5908
-                    // NOTE: add error handling here
5909
-                    // if serializeType returns false, then catch global error and fault
5910
-                    if ('arraySimple' === $parametersArrayType) {
5911
-                        $p = array_shift($parameters);
5912
-                        $this->debug('calling serializeType w/indexed param');
5913
-                        $xml .= $this->serializeType($name, $type, $p, $use, $enc_style);
5914
-                    } elseif (isset($parameters[$name])) {
5915
-                        $this->debug('calling serializeType w/named param');
5916
-                        $xml .= $this->serializeType($name, $type, $parameters[$name], $use, $enc_style);
5917
-                    } else {
5918
-                        // TODO: only send nillable
5919
-                        $this->debug('calling serializeType w/null param');
5920
-                        $xml .= $this->serializeType($name, $type, null, $use, $enc_style);
5921
-                    }
5922
-                }
5923
-            } else {
5924
-                $this->debug('no parameters passed.');
5925
-            }
5926
-        }
5927
-        $this->debug("serializeRPCParameters returning: $xml");
5928
-        return $xml;
5929
-    }
5930
-
5931
-    /**
5932
-     * serialize a PHP value according to a WSDL message definition
5933
-     *
5934
-     * TODO
5935
-     * - multi-ref serialization
5936
-     * - validate PHP values against type definitions, return errors if invalid
5937
-     *
5938
-     * @param string $operation operation name
5939
-     * @param string $direction (input|output)
5940
-     * @param mixed $parameters parameter value(s)
5941
-     * @return mixed parameters serialized as XML or false on error (e.g. operation not found)
5942
-     * @access public
5943
-     * @deprecated
5944
-     */
5945
-    public function serializeParameters($operation, $direction, $parameters)
5946
-    {
5947
-        $this->debug("in serializeParameters: operation=$operation, direction=$direction, XMLSchemaVersion=$this->XMLSchemaVersion");
5948
-        $this->appendDebug('parameters=' . $this->varDump($parameters));
5949
-
5950
-        if ('input' !== $direction && 'output' !== $direction) {
5951
-            $this->debug('The value of the \$direction argument needs to be either "input" or "output"');
5952
-            $this->setError('The value of the \$direction argument needs to be either "input" or "output"');
5953
-            return false;
5954
-        }
5955
-        if (!$opData = $this->getOperationData($operation)) {
5956
-            $this->debug('Unable to retrieve WSDL data for operation: ' . $operation);
5957
-            $this->setError('Unable to retrieve WSDL data for operation: ' . $operation);
5958
-            return false;
5959
-        }
5960
-        $this->debug('opData:');
5961
-        $this->appendDebug($this->varDump($opData));
5962
-
5963
-        // Get encoding style for output and set to current
5964
-        $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
5965
-        if (('input' === $direction) && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) {
5966
-            $encodingStyle = $opData['output']['encodingStyle'];
5967
-            $enc_style = $encodingStyle;
5968
-        }
5969
-
5970
-        // set input params
5971
-        $xml = '';
5972
-        if (isset($opData[$direction]['parts']) && count($opData[$direction]['parts']) > 0) {
5973
-            $use = $opData[$direction]['use'];
5974
-            $this->debug("use=$use");
5975
-            $this->debug('got ' . count($opData[$direction]['parts']) . ' part(s)');
5976
-            if (is_array($parameters)) {
5977
-                $parametersArrayType = $this->isArraySimpleOrStruct($parameters);
5978
-                $this->debug('have ' . $parametersArrayType . ' parameters');
5979
-                foreach ($opData[$direction]['parts'] as $name => $type) {
5980
-                    $this->debug('serializing part "' . $name . '" of type "' . $type . '"');
5981
-                    // Track encoding style
5982
-                    if (isset($opData[$direction]['encodingStyle']) && $encodingStyle != $opData[$direction]['encodingStyle']) {
5983
-                        $encodingStyle = $opData[$direction]['encodingStyle'];
5984
-                        $enc_style = $encodingStyle;
5985
-                    } else {
5986
-                        $enc_style = false;
5987
-                    }
5988
-                    // NOTE: add error handling here
5989
-                    // if serializeType returns false, then catch global error and fault
5990
-                    if ('arraySimple' === $parametersArrayType) {
5991
-                        $p = array_shift($parameters);
5992
-                        $this->debug('calling serializeType w/indexed param');
5993
-                        $xml .= $this->serializeType($name, $type, $p, $use, $enc_style);
5994
-                    } elseif (isset($parameters[$name])) {
5995
-                        $this->debug('calling serializeType w/named param');
5996
-                        $xml .= $this->serializeType($name, $type, $parameters[$name], $use, $enc_style);
5997
-                    } else {
5998
-                        // TODO: only send nillable
5999
-                        $this->debug('calling serializeType w/null param');
6000
-                        $xml .= $this->serializeType($name, $type, null, $use, $enc_style);
6001
-                    }
6002
-                }
6003
-            } else {
6004
-                $this->debug('no parameters passed.');
6005
-            }
6006
-        }
6007
-        $this->debug("serializeParameters returning: $xml");
6008
-        return $xml;
6009
-    }
6010
-
6011
-    /**
6012
-     * serializes a PHP value according a given type definition
6013
-     *
6014
-     * @param string  $name          name of value (part or element)
6015
-     * @param string  $type          XML schema type of value (type or element)
6016
-     * @param mixed   $value         a native PHP value (parameter value)
6017
-     * @param string  $use           use for part (encoded|literal)
6018
-     * @param bool|string $encodingStyle SOAP encoding style for the value (if different than the enclosing style)
6019
-     * @param bool $unqualified   a kludge for what should be XML namespace form handling
6020
-     * @return string value serialized as an XML string
6021
-     * @access private
6022
-     */
6023
-    private function serializeType($name, $type, $value, $use = 'encoded', $encodingStyle = false, $unqualified = false)
6024
-    {
6025
-        $this->debug("in serializeType: name=$name, type=$type, use=$use, encodingStyle=$encodingStyle, unqualified=" . ($unqualified ? 'unqualified' : 'qualified'));
6026
-        $this->appendDebug('value=' . $this->varDump($value));
6027
-        if ('encoded' === $use && $encodingStyle) {
6028
-            $encodingStyle = ' SOAP-ENV:encodingStyle="' . $encodingStyle . '"';
6029
-        }
6030
-
6031
-        // if a soapval has been supplied, let its type override the WSDL
6032
-        if (is_object($value) && 'soapval' === get_class($value)) {
6033
-            if ($value->type_ns) {
6034
-                $type = $value->type_ns . ':' . $value->type;
6035
-                $forceType = true;
6036
-                $this->debug("in serializeType: soapval overrides type to $type");
6037
-            } elseif ($value->type) {
6038
-                $type = $value->type;
6039
-                $forceType = true;
6040
-                $this->debug("in serializeType: soapval overrides type to $type");
6041
-            } else {
6042
-                $forceType = false;
6043
-                $this->debug('in serializeType: soapval does not override type');
6044
-            }
6045
-            $attrs = $value->attributes;
6046
-            $value = $value->value;
6047
-            $this->debug("in serializeType: soapval overrides value to $value");
6048
-            if ($attrs) {
6049
-                if (!is_array($value)) {
6050
-                    $value['!'] = $value;
6051
-                }
6052
-                foreach ($attrs as $n => $v) {
6053
-                    $value['!' . $n] = $v;
6054
-                }
6055
-                $this->debug('in serializeType: soapval provides attributes');
6056
-            }
6057
-        } else {
6058
-            $forceType = false;
6059
-        }
6060
-
6061
-        $xml = '';
6062
-        if (strpos($type, ':')) {
6063
-            $uqType = substr($type, strrpos($type, ':') + 1);
6064
-            $ns = substr($type, 0, strrpos($type, ':'));
6065
-            $this->debug("in serializeType: got a prefixed type: $uqType, $ns");
6066
-            if ($this->getNamespaceFromPrefix($ns)) {
6067
-                $ns = $this->getNamespaceFromPrefix($ns);
6068
-                $this->debug("in serializeType: expanded prefixed type: $uqType, $ns");
6069
-            }
6070
-
6071
-            if ($ns == $this->XMLSchemaVersion || 'http://schemas.xmlsoap.org/soap/encoding/' === $ns) {
6072
-                $this->debug('in serializeType: type namespace indicates XML Schema or SOAP Encoding type');
6073
-                if ($unqualified && 'literal' === $use) {
6074
-                    $elementNS = ' xmlns=""';
6075
-                } else {
6076
-                    $elementNS = '';
6077
-                }
6078
-                if (null === $value) {
6079
-                    if ('literal' === $use) {
6080
-                        // TODO: depends on minOccurs
6081
-                        $xml = "<$name$elementNS/>";
6082
-                    } else {
6083
-                        // TODO: depends on nillable, which should be checked before calling this method
6084
-                        $xml = "<$name$elementNS xsi:nil=\"true\" xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"/>";
6085
-                    }
6086
-                    $this->debug("in serializeType: returning: $xml");
6087
-                    return $xml;
6088
-                }
6089
-                if ('Array' === $uqType) {
6090
-                    // JBoss/Axis does this sometimes
6091
-                    return $this->serialize_val($value, $name, false, false, false, false, $use);
6092
-                }
6093
-                if ('boolean' === $uqType) {
6094
-                    if ((is_string($value) && 'false' === $value) || (!$value)) {
6095
-                        $value = 'false';
6096
-                    } else {
6097
-                        $value = 'true';
6098
-                    }
6099
-                }
6100
-                if ('string' === $uqType && 'string' === gettype($value)) {
6101
-                    $value = $this->expandEntities($value);
6102
-                }
6103
-                if (('long' === $uqType || 'unsignedLong' === $uqType) && 'double' === gettype($value)) {
6104
-                    $value = sprintf('%.0lf', $value);
6105
-                }
6106
-                // it's a scalar
6107
-                // TODO: what about null/nil values?
6108
-                // check type isn't a custom type extending xmlschema namespace
6109
-                if (!$this->getTypeDef($uqType, $ns)) {
6110
-                    if ('literal' === $use) {
6111
-                        if ($forceType) {
6112
-                            $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">$value</$name>";
6113
-                        } else {
6114
-                            $xml = "<$name$elementNS>$value</$name>";
6115
-                        }
6116
-                    } else {
6117
-                        $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>$value</$name>";
6118
-                    }
6119
-                    $this->debug("in serializeType: returning: $xml");
6120
-                    return $xml;
6121
-                }
6122
-                $this->debug('custom type extends XML Schema or SOAP Encoding namespace (yuck)');
6123
-            } elseif ('http://xml.apache.org/xml-soap' === $ns) {
6124
-                $this->debug('in serializeType: appears to be Apache SOAP type');
6125
-                if ('Map' === $uqType) {
6126
-                    $tt_prefix = $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap');
6127
-                    if (!$tt_prefix) {
6128
-                        $this->debug('in serializeType: Add namespace for Apache SOAP type');
6129
-                        $tt_prefix = 'ns' . mt_rand(1000, 9999);
6130
-                        $this->namespaces[$tt_prefix] = 'http://xml.apache.org/xml-soap';
6131
-                        // force this to be added to usedNamespaces
6132
-                        $tt_prefix = $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap');
6133
-                    }
6134
-                    $contents = '';
6135
-                    foreach ($value as $k => $v) {
6136
-                        $this->debug("serializing map element: key $k, value $v");
6137
-                        $contents .= '<item>';
6138
-                        $contents .= $this->serialize_val($k, 'key', false, false, false, false, $use);
6139
-                        $contents .= $this->serialize_val($v, 'value', false, false, false, false, $use);
6140
-                        $contents .= '</item>';
6141
-                    }
6142
-                    if ('literal' === $use) {
6143
-                        if ($forceType) {
6144
-                            $xml = "<$name xsi:type=\"" . $tt_prefix . ":$uqType\">$contents</$name>";
6145
-                        } else {
6146
-                            $xml = "<$name>$contents</$name>";
6147
-                        }
6148
-                    } else {
6149
-                        $xml = "<$name xsi:type=\"" . $tt_prefix . ":$uqType\"$encodingStyle>$contents</$name>";
6150
-                    }
6151
-                    $this->debug("in serializeType: returning: $xml");
6152
-                    return $xml;
6153
-                }
6154
-                $this->debug('in serializeType: Apache SOAP type, but only support Map');
6155
-            }
6156
-        } else {
6157
-            // TODO: should the type be compared to types in XSD, and the namespace
6158
-            // set to XSD if the type matches?
6159
-            $this->debug("in serializeType: No namespace for type $type");
6160
-            $ns = '';
6161
-            $uqType = $type;
6162
-        }
6163
-        if (!$typeDef = $this->getTypeDef($uqType, $ns)) {
6164
-            $this->setError("$type ($uqType) is not a supported type.");
6165
-            $this->debug("in serializeType: $type ($uqType) is not a supported type.");
6166
-            return false;
6167
-        } else {
6168
-            $this->debug('in serializeType: found typeDef');
6169
-            $this->appendDebug('typeDef=' . $this->varDump($typeDef));
6170
-            if ('^' === substr($uqType, -1)) {
6171
-                $uqType = substr($uqType, 0, -1);
6172
-            }
6173
-        }
6174
-        if (!isset($typeDef['phpType'])) {
6175
-            $this->setError("$type ($uqType) has no phpType.");
6176
-            $this->debug("in serializeType: $type ($uqType) has no phpType.");
6177
-            return false;
6178
-        }
6179
-        $phpType = $typeDef['phpType'];
6180
-        $this->debug("in serializeType: uqType: $uqType, ns: $ns, phptype: $phpType, arrayType: " . (isset($typeDef['arrayType']) ? $typeDef['arrayType'] : ''));
6181
-        // if php type == struct, map value to the <all> element names
6182
-        if ('struct' === $phpType) {
6183
-            if (isset($typeDef['typeClass']) && 'element' === $typeDef['typeClass']) {
6184
-                $elementName = $uqType;
6185
-                if (isset($typeDef['form']) && ('qualified' === $typeDef['form'])) {
6186
-                    $elementNS = " xmlns=\"$ns\"";
6187
-                } else {
6188
-                    $elementNS = ' xmlns=""';
6189
-                }
6190
-            } else {
6191
-                $elementName = $name;
6192
-                if ($unqualified) {
6193
-                    $elementNS = ' xmlns=""';
6194
-                } else {
6195
-                    $elementNS = '';
6196
-                }
6197
-            }
6198
-            if (null === $value) {
6199
-                if ('literal' === $use) {
6200
-                    // TODO: depends on minOccurs and nillable
6201
-                    $xml = "<$elementName$elementNS/>";
6202
-                } else {
6203
-                    $xml = "<$elementName$elementNS xsi:nil=\"true\" xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"/>";
6204
-                }
6205
-                $this->debug("in serializeType: returning: $xml");
6206
-                return $xml;
6207
-            }
6208
-            if (is_object($value)) {
6209
-                $value = get_object_vars($value);
6210
-            }
6211
-            if (is_array($value)) {
6212
-                $elementAttrs = $this->serializeComplexTypeAttributes($typeDef, $value, $ns, $uqType);
6213
-                if ('literal' === $use) {
6214
-                    if ($forceType) {
6215
-                        $xml = "<$elementName$elementNS$elementAttrs xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">";
6216
-                    } else {
6217
-                        $xml = "<$elementName$elementNS$elementAttrs>";
6218
-                    }
6219
-                } else {
6220
-                    $xml = "<$elementName$elementNS$elementAttrs xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>";
6221
-                }
5610
+		return $b;
5611
+	}
6222 5612
 
6223
-                if (isset($typeDef['simpleContent']) && 'true' === $typeDef['simpleContent']) {
6224
-                    if (isset($value['!'])) {
6225
-                        $xml .= $value['!'];
6226
-                        $this->debug("in serializeType: serialized simpleContent for type $type");
6227
-                    } else {
6228
-                        $this->debug("in serializeType: no simpleContent to serialize for type $type");
6229
-                    }
6230
-                } else {
6231
-                    // complexContent
6232
-                    $xml .= $this->serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use, $encodingStyle);
6233
-                }
6234
-                $xml .= "</$elementName>";
6235
-            } else {
6236
-                $this->debug('in serializeType: phpType is struct, but value is not an array');
6237
-                $this->setError('phpType is struct, but value is not an array: see debug output for details');
6238
-                $xml = '';
6239
-            }
6240
-        } elseif ('array' === $phpType) {
6241
-            if (isset($typeDef['form']) && ('qualified' === $typeDef['form'])) {
6242
-                $elementNS = " xmlns=\"$ns\"";
6243
-            } else {
6244
-                if ($unqualified) {
6245
-                    $elementNS = ' xmlns=""';
6246
-                } else {
6247
-                    $elementNS = '';
6248
-                }
6249
-            }
6250
-            if (null === $value) {
6251
-                if ('literal' === $use) {
6252
-                    // TODO: depends on minOccurs
6253
-                    $xml = "<$name$elementNS/>";
6254
-                } else {
6255
-                    $xml = "<$name$elementNS xsi:nil=\"true\" xsi:type=\"" .
6256
-                        $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') . ':Array" ' .
6257
-                        $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') .
6258
-                        ':arrayType="' .
6259
-                        $this->getPrefixFromNamespace($this->getPrefix($typeDef['arrayType'])) .
6260
-                        ':' .
6261
-                        $this->getLocalPart($typeDef['arrayType']) . '[0]"/>';
6262
-                }
6263
-                $this->debug("in serializeType: returning: $xml");
6264
-                return $xml;
6265
-            }
6266
-            if (isset($typeDef['multidimensional'])) {
6267
-                $nv = [];
6268
-                foreach ($value as $v) {
6269
-                    $cols = ',' . count($v);
6270
-                    $nv = array_merge($nv, $v);
6271
-                }
6272
-                $value = $nv;
6273
-            } else {
6274
-                $cols = '';
6275
-            }
6276
-            if (is_array($value) && count($value) >= 1) {
6277
-                $rows = count($value);
6278
-                $contents = '';
6279
-                foreach ($value as $k => $v) {
6280
-                    $this->debug("serializing array element: $k, " . (is_array($v) ? 'array' : $v) . " of type: $typeDef[arrayType]");
6281
-                    //if (strpos($typeDef['arrayType'], ':') ) {
6282
-                    if (!in_array($typeDef['arrayType'], $this->typemap['http://www.w3.org/2001/XMLSchema'])) {
6283
-                        $contents .= $this->serializeType('item', $typeDef['arrayType'], $v, $use);
6284
-                    } else {
6285
-                        $contents .= $this->serialize_val($v, 'item', $typeDef['arrayType'], null, $this->XMLSchemaVersion, false, $use);
6286
-                    }
6287
-                }
6288
-            } else {
6289
-                $rows = 0;
6290
-                $contents = null;
6291
-            }
6292
-            // TODO: for now, an empty value will be serialized as a zero element
6293
-            // array.  Revisit this when coding the handling of null/nil values.
6294
-            if ('literal' === $use) {
6295
-                $xml = "<$name$elementNS>"
6296
-                    . $contents
6297
-                    . "</$name>";
6298
-            } else {
6299
-                $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') . ':Array" ' .
6300
-                    $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/')
6301
-                    . ':arrayType="'
6302
-                    . $this->getPrefixFromNamespace($this->getPrefix($typeDef['arrayType']))
6303
-                       . ':' . $this->getLocalPart($typeDef['arrayType']) . "[$rows$cols]\">"
6304
-                    . $contents
6305
-                    . "</$name>";
6306
-            }
6307
-        } elseif ('scalar' === $phpType) {
6308
-            if (isset($typeDef['form']) && ('qualified' === $typeDef['form'])) {
6309
-                $elementNS = " xmlns=\"$ns\"";
6310
-            } else {
6311
-                if ($unqualified) {
6312
-                    $elementNS = ' xmlns=""';
6313
-                } else {
6314
-                    $elementNS = '';
6315
-                }
6316
-            }
6317
-            if ('literal' === $use) {
6318
-                if ($forceType) {
6319
-                    $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">$value</$name>";
6320
-                } else {
6321
-                    $xml = "<$name$elementNS>$value</$name>";
6322
-                }
6323
-            } else {
6324
-                $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>$value</$name>";
6325
-            }
6326
-        }
6327
-        $this->debug("in serializeType: returning: $xml");
6328
-        return $xml;
6329
-    }
6330
-
6331
-    /**
6332
-     * serializes the attributes for a complexType
6333
-     *
6334
-     * @param array $typeDef our internal representation of an XML schema type (or element)
6335
-     * @param mixed $value a native PHP value (parameter value)
6336
-     * @param string $ns the namespace of the type
6337
-     * @param string $uqType the local part of the type
6338
-     * @return string value serialized as an XML string
6339
-     * @access private
6340
-     */
6341
-    private function serializeComplexTypeAttributes($typeDef, $value, $ns, $uqType)
6342
-    {
6343
-        $this->debug("serializeComplexTypeAttributes for XML Schema type $ns:$uqType");
6344
-        $xml = '';
6345
-        if (isset($typeDef['extensionBase'])) {
6346
-            $nsx = $this->getPrefix($typeDef['extensionBase']);
6347
-            $uqTypex = $this->getLocalPart($typeDef['extensionBase']);
6348
-            if ($this->getNamespaceFromPrefix($nsx)) {
6349
-                $nsx = $this->getNamespaceFromPrefix($nsx);
6350
-            }
6351
-            if (false !== ($typeDefx = $this->getTypeDef($uqTypex, $nsx))) {
6352
-                $this->debug("serialize attributes for extension base $nsx:$uqTypex");
6353
-                $xml .= $this->serializeComplexTypeAttributes($typeDefx, $value, $nsx, $uqTypex);
6354
-            } else {
6355
-                $this->debug("extension base $nsx:$uqTypex is not a supported type");
6356
-            }
6357
-        }
6358
-        if (isset($typeDef['attrs']) && is_array($typeDef['attrs'])) {
6359
-            $this->debug("serialize attributes for XML Schema type $ns:$uqType");
6360
-            if (is_array($value)) {
6361
-                $xvalue = $value;
6362
-            } elseif (is_object($value)) {
6363
-                $xvalue = get_object_vars($value);
6364
-            } else {
6365
-                $this->debug("value is neither an array nor an object for XML Schema type $ns:$uqType");
6366
-                $xvalue = [];
6367
-            }
6368
-            foreach ($typeDef['attrs'] as $aName => $attrs) {
6369
-                if (isset($xvalue['!' . $aName])) {
6370
-                    $xname = '!' . $aName;
6371
-                    $this->debug("value provided for attribute $aName with key $xname");
6372
-                } elseif (isset($xvalue[$aName])) {
6373
-                    $xname = $aName;
6374
-                    $this->debug("value provided for attribute $aName with key $xname");
6375
-                } elseif (isset($attrs['default'])) {
6376
-                    $xname = '!' . $aName;
6377
-                    $xvalue[$xname] = $attrs['default'];
6378
-                    $this->debug('use default value of ' . $xvalue[$aName] . ' for attribute ' . $aName);
6379
-                } else {
6380
-                    $xname = '';
6381
-                    $this->debug("no value provided for attribute $aName");
6382
-                }
6383
-                if ($xname) {
6384
-                    $xml .= " $aName=\"" . $this->expandEntities($xvalue[$xname]) . '"';
6385
-                }
6386
-            }
6387
-        } else {
6388
-            $this->debug("no attributes to serialize for XML Schema type $ns:$uqType");
6389
-        }
6390
-        return $xml;
6391
-    }
6392
-
6393
-    /**
6394
-     * serializes the elements for a complexType
6395
-     *
6396
-     * @param array  $typeDef       our internal representation of an XML schema type (or element)
6397
-     * @param mixed  $value         a native PHP value (parameter value)
6398
-     * @param string $ns            the namespace of the type
6399
-     * @param string $uqType        the local part of the type
6400
-     * @param string $use           use for part (encoded|literal)
6401
-     * @param bool|string $encodingStyle SOAP encoding style for the value (if different than the enclosing style)
6402
-     * @return string value serialized as an XML string
6403
-     * @access private
6404
-     */
6405
-    private function serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use = 'encoded', $encodingStyle = false)
6406
-    {
6407
-        $this->debug("in serializeComplexTypeElements for XML Schema type $ns:$uqType");
6408
-        $xml = '';
6409
-        if (isset($typeDef['extensionBase'])) {
6410
-            $nsx = $this->getPrefix($typeDef['extensionBase']);
6411
-            $uqTypex = $this->getLocalPart($typeDef['extensionBase']);
6412
-            if ($this->getNamespaceFromPrefix($nsx)) {
6413
-                $nsx = $this->getNamespaceFromPrefix($nsx);
6414
-            }
6415
-            if (false !== ($typeDefx = $this->getTypeDef($uqTypex, $nsx))) {
6416
-                $this->debug("serialize elements for extension base $nsx:$uqTypex");
6417
-                $xml .= $this->serializeComplexTypeElements($typeDefx, $value, $nsx, $uqTypex, $use, $encodingStyle);
6418
-            } else {
6419
-                $this->debug("extension base $nsx:$uqTypex is not a supported type");
6420
-            }
6421
-        }
6422
-        if (isset($typeDef['elements']) && is_array($typeDef['elements'])) {
6423
-            $this->debug("in serializeComplexTypeElements, serialize elements for XML Schema type $ns:$uqType");
6424
-            if (is_array($value)) {
6425
-                $xvalue = $value;
6426
-            } elseif (is_object($value)) {
6427
-                $xvalue = get_object_vars($value);
6428
-            } else {
6429
-                $this->debug("value is neither an array nor an object for XML Schema type $ns:$uqType");
6430
-                $xvalue = [];
6431
-            }
6432
-            // toggle whether all elements are present - ideally should validate against schema
6433
-            if (is_array($xvalue) && (count($typeDef['elements']) != count($xvalue))) {
6434
-                $optionals = true;
6435
-            }
6436
-            foreach ($typeDef['elements'] as $eName => $attrs) {
6437
-                if (!isset($xvalue[$eName])) {
6438
-                    if (isset($attrs['default'])) {
6439
-                        $xvalue[$eName] = $attrs['default'];
6440
-                        $this->debug('use default value of ' . $xvalue[$eName] . ' for element ' . $eName);
6441
-                    }
6442
-                }
6443
-                // if user took advantage of a minOccurs=0, then only serialize named parameters
6444
-                if (isset($optionals)
6445
-                    && (!isset($xvalue[$eName]))
6446
-                    && ((!isset($attrs['nillable'])) || 'true' !== $attrs['nillable'])
6447
-                ) {
6448
-                    if (isset($attrs['minOccurs']) && '0' <> $attrs['minOccurs']) {
6449
-                        $this->debug("apparent error: no value provided for element $eName with minOccurs=" . $attrs['minOccurs']);
6450
-                    }
6451
-                    // do nothing
6452
-                    $this->debug("no value provided for complexType element $eName and element is not nillable, so serialize nothing");
6453
-                } else {
6454
-                    // get value
6455
-                    if (isset($xvalue[$eName])) {
6456
-                        $v = $xvalue[$eName];
6457
-                    } else {
6458
-                        $v = null;
6459
-                    }
6460
-                    if (isset($attrs['form'])) {
6461
-                        $unqualified = ('unqualified' === $attrs['form']);
6462
-                    } else {
6463
-                        $unqualified = false;
6464
-                    }
6465
-                    if (isset($attrs['maxOccurs']) && ('unbounded' === $attrs['maxOccurs'] || $attrs['maxOccurs'] > 1) && isset($v) && is_array($v) && 'arraySimple' === $this->isArraySimpleOrStruct($v)) {
6466
-                        $vv = $v;
6467
-                        foreach ($vv as $k => $v) {
6468
-                            if (isset($attrs['type']) || isset($attrs['ref'])) {
6469
-                                // serialize schema-defined type
6470
-                                $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified);
6471
-                            } else {
6472
-                                // serialize generic type (can this ever really happen?)
6473
-                                $this->debug("calling serialize_val() for $v, $eName, false, false, false, false, $use");
6474
-                                $xml .= $this->serialize_val($v, $eName, false, false, false, false, $use);
6475
-                            }
6476
-                        }
6477
-                    } else {
6478
-                        if (null === $v && isset($attrs['minOccurs']) && '0' == $attrs['minOccurs']) {
6479
-                            // do nothing
6480
-                        } elseif (null === $v && isset($attrs['nillable']) && 'true' === $attrs['nillable']) {
6481
-                            // TODO: serialize a nil correctly, but for now serialize schema-defined type
6482
-                            $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified);
6483
-                        } elseif (isset($attrs['type']) || isset($attrs['ref'])) {
6484
-                            // serialize schema-defined type
6485
-                            $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified);
6486
-                        } else {
6487
-                            // serialize generic type (can this ever really happen?)
6488
-                            $this->debug("calling serialize_val() for $v, $eName, false, false, false, false, $use");
6489
-                            $xml .= $this->serialize_val($v, $eName, false, false, false, false, $use);
6490
-                        }
6491
-                    }
6492
-                }
6493
-            }
6494
-        } else {
6495
-            $this->debug("no elements to serialize for XML Schema type $ns:$uqType");
6496
-        }
6497
-        return $xml;
6498
-    }
6499
-
6500
-    /**
6501
-     * adds an XML Schema complex type to the WSDL types
6502
-     *
6503
-     * @param string $name
6504
-     * @param string $typeClass (complexType|simpleType|attribute)
6505
-     * @param string $phpType currently supported are array and struct (php assoc array)
6506
-     * @param string $compositor (all|sequence|choice)
6507
-     * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
6508
-     * @param array $elements e.g. array ( name => array(name=>'',type=>'') )
6509
-     * @param array $attrs e.g. array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'xsd:string[]'))
6510
-     * @param string $arrayType as namespace:name (xsd:string)
6511
-     * @see nusoap_xmlschema
6512
-     * @access public
6513
-     */
6514
-    public function addComplexType($name, $typeClass = 'complexType', $phpType = 'array', $compositor = '', $restrictionBase = '', $elements = [], $attrs = [], $arrayType = '')
6515
-    {
6516
-        if (is_array($elements) && count($elements) > 0) {
6517
-            $eElements = [];
6518
-            foreach ($elements as $n => $e) {
6519
-                // expand each element
6520
-                $ee = [];
6521
-                foreach ($e as $k => $v) {
6522
-                    $k = strpos($k, ':') ? $this->expandQname($k) : $k;
6523
-                    $v = strpos($v, ':') ? $this->expandQname($v) : $v;
6524
-                    $ee[$k] = $v;
6525
-                }
6526
-                $eElements[$n] = $ee;
6527
-            }
6528
-            $elements = $eElements;
6529
-        }
6530
-
6531
-        if (is_array($attrs) && count($attrs) > 0) {
6532
-            foreach ($attrs as $n => $a) {
6533
-                // expand each attribute
6534
-                foreach ($a as $k => $v) {
6535
-                    $k = strpos($k, ':') ? $this->expandQname($k) : $k;
6536
-                    $v = strpos($v, ':') ? $this->expandQname($v) : $v;
6537
-                    $aa[$k] = $v;
6538
-                }
6539
-                $eAttrs[$n] = $aa;
6540
-            }
6541
-            $attrs = $eAttrs;
6542
-        }
6543
-
6544
-        $restrictionBase = strpos($restrictionBase, ':') ? $this->expandQname($restrictionBase) : $restrictionBase;
6545
-        $arrayType = strpos($arrayType, ':') ? $this->expandQname($arrayType) : $arrayType;
6546
-
6547
-        $typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns'];
6548
-        $this->schemas[$typens][0]->addComplexType($name, $typeClass, $phpType, $compositor, $restrictionBase, $elements, $attrs, $arrayType);
6549
-    }
6550
-
6551
-    /**
6552
-     * adds an XML Schema simple type to the WSDL types
6553
-     *
6554
-     * @param string $name
6555
-     * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
6556
-     * @param string $typeClass (should always be simpleType)
6557
-     * @param string $phpType (should always be scalar)
6558
-     * @param array $enumeration array of values
6559
-     * @see nusoap_xmlschema
6560
-     * @access public
6561
-     */
6562
-    public function addSimpleType($name, $restrictionBase = '', $typeClass = 'simpleType', $phpType = 'scalar', $enumeration = [])
6563
-    {
6564
-        $restrictionBase = strpos($restrictionBase, ':') ? $this->expandQname($restrictionBase) : $restrictionBase;
6565
-
6566
-        $typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns'];
6567
-        $this->schemas[$typens][0]->addSimpleType($name, $restrictionBase, $typeClass, $phpType, $enumeration);
6568
-    }
6569
-
6570
-    /**
6571
-     * adds an element to the WSDL types
6572
-     *
6573
-     * @param array $attrs attributes that must include name and type
6574
-     * @see nusoap_xmlschema
6575
-     * @access public
6576
-     */
6577
-    public function addElement($attrs)
6578
-    {
6579
-        $typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns'];
6580
-        $this->schemas[$typens][0]->addElement($attrs);
6581
-    }
6582
-
6583
-    /**
6584
-     * register an operation with the server
6585
-     *
6586
-     * @param string      $name          operation (method) name
6587
-     * @param bool|array  $in            assoc array of input values: key = param name, value = param type
6588
-     * @param bool|array  $out           assoc array of output values: key = param name, value = param type
6589
-     * @param bool|string $namespace     optional The namespace for the operation
6590
-     * @param bool|string $soapaction    optional The soapaction for the operation
6591
-     * @param string      $style         (rpc|document) optional The style for the operation Note: when 'document' is specified, parameter and return wrappers are created for you automatically
6592
-     * @param string      $use           (encoded|literal) optional The use for the parameters (cannot mix right now)
6593
-     * @param string      $documentation optional The description to include in the WSDL
6594
-     * @param string      $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
6595
-     * @access public
6596
-     * @return bool
6597
-     */
6598
-    public function addOperation($name, $in = false, $out = false, $namespace = false, $soapaction = false, $style = 'rpc', $use = 'encoded', $documentation = '', $encodingStyle = '')
6599
-    {
6600
-        if ('encoded' === $use && '' == $encodingStyle) {
6601
-            $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
6602
-        }
6603
-
6604
-        if ('document' === $style) {
6605
-            $elements = [];
6606
-            foreach ($in as $n => $t) {
6607
-                $elements[$n] = ['name' => $n, 'type' => $t, 'form' => 'unqualified'];
6608
-            }
6609
-            $this->addComplexType($name . 'RequestType', 'complexType', 'struct', 'all', '', $elements);
6610
-            $this->addElement(['name' => $name, 'type' => $name . 'RequestType']);
6611
-            $in = ['parameters' => 'tns:' . $name . '^'];
6612
-
6613
-            $elements = [];
6614
-            foreach ($out as $n => $t) {
6615
-                $elements[$n] = ['name' => $n, 'type' => $t, 'form' => 'unqualified'];
6616
-            }
6617
-            $this->addComplexType($name . 'ResponseType', 'complexType', 'struct', 'all', '', $elements);
6618
-            $this->addElement(['name' => $name . 'Response', 'type' => $name . 'ResponseType', 'form' => 'qualified']);
6619
-            $out = ['parameters' => 'tns:' . $name . 'Response' . '^'];
6620
-        }
6621
-
6622
-        // get binding
6623
-        $this->bindings[$this->serviceName . 'Binding']['operations'][$name] =
6624
-            [
6625
-                'name' => $name,
6626
-                'binding' => $this->serviceName . 'Binding',
6627
-                'endpoint' => $this->endpoint,
6628
-                'soapAction' => $soapaction,
6629
-                'style' => $style,
6630
-                'input' => [
6631
-                    'use' => $use,
6632
-                    'namespace' => $namespace,
6633
-                    'encodingStyle' => $encodingStyle,
6634
-                    'message' => $name . 'Request',
6635
-                    'parts' => $in
6636
-                ],
6637
-                'output' => [
6638
-                    'use' => $use,
6639
-                    'namespace' => $namespace,
6640
-                    'encodingStyle' => $encodingStyle,
6641
-                    'message' => $name . 'Response',
6642
-                    'parts' => $out
6643
-                ],
6644
-                'namespace' => $namespace,
6645
-                'transport' => 'http://schemas.xmlsoap.org/soap/http',
6646
-                'documentation' => $documentation
6647
-            ];
6648
-        // add portTypes
6649
-        // add messages
6650
-        if ($in) {
6651
-            foreach ($in as $pName => $pType) {
6652
-                if (strpos($pType, ':')) {
6653
-                    $pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)) . ':' . $this->getLocalPart($pType);
6654
-                }
6655
-                $this->messages[$name . 'Request'][$pName] = $pType;
6656
-            }
6657
-        } else {
6658
-            $this->messages[$name . 'Request'] = '0';
6659
-        }
6660
-        if ($out) {
6661
-            foreach ($out as $pName => $pType) {
6662
-                if (strpos($pType, ':')) {
6663
-                    $pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)) . ':' . $this->getLocalPart($pType);
6664
-                }
6665
-                $this->messages[$name . 'Response'][$pName] = $pType;
6666
-            }
6667
-        } else {
6668
-            $this->messages[$name . 'Response'] = '0';
6669
-        }
6670
-        return true;
6671
-    }
5613
+	/**
5614
+	 * serialize the parsed wsdl
5615
+	 *
5616
+	 * @param mixed $debug whether to put debug=1 in endpoint URL
5617
+	 * @return string serialization of WSDL
5618
+	 * @access public
5619
+	 */
5620
+	public function serialize($debug = 0)
5621
+	{
5622
+		$xml = '<?xml version="1.0" encoding="ISO-8859-1"?>';
5623
+		$xml .= "\n<definitions";
5624
+		foreach ($this->namespaces as $k => $v) {
5625
+			$xml .= " xmlns:$k=\"$v\"";
5626
+		}
5627
+		// 10.9.02 - add poulter fix for wsdl and tns declarations
5628
+		if (isset($this->namespaces['wsdl'])) {
5629
+			$xml .= ' xmlns="' . $this->namespaces['wsdl'] . '"';
5630
+		}
5631
+		if (isset($this->namespaces['tns'])) {
5632
+			$xml .= ' targetNamespace="' . $this->namespaces['tns'] . '"';
5633
+		}
5634
+		$xml .= '>';
5635
+		// imports
5636
+		if (is_array($this->import) && count($this->import) > 0) {
5637
+			foreach ($this->import as $ns => $list) {
5638
+				foreach ($list as $ii) {
5639
+					if ('' != $ii['location']) {
5640
+						$xml .= '<import location="' . $ii['location'] . '" namespace="' . $ns . '" />';
5641
+					} else {
5642
+						$xml .= '<import namespace="' . $ns . '" />';
5643
+					}
5644
+				}
5645
+			}
5646
+		}
5647
+		// types
5648
+		if (is_array($this->schemas) && count($this->schemas) >= 1) {
5649
+			$xml .= "\n<types>\n";
5650
+			foreach ($this->schemas as $ns => $list) {
5651
+				foreach ($list as $xs) {
5652
+					$xml .= $xs->serializeSchema();
5653
+				}
5654
+			}
5655
+			$xml .= '</types>';
5656
+		}
5657
+		// messages
5658
+		if (is_array($this->messages) && count($this->messages) >= 1) {
5659
+			foreach ($this->messages as $msgName => $msgParts) {
5660
+				$xml .= "\n<message name=\"" . $msgName . '">';
5661
+				if (is_array($msgParts)) {
5662
+					foreach ($msgParts as $partName => $partType) {
5663
+						// print 'serializing '.$partType.', sv: '.$this->XMLSchemaVersion.'<br>';
5664
+						if (strpos($partType, ':')) {
5665
+							$typePrefix = $this->getPrefixFromNamespace($this->getPrefix($partType));
5666
+						} elseif (isset($this->typemap[$this->namespaces['xsd']][$partType])) {
5667
+							// print 'checking typemap: '.$this->XMLSchemaVersion.'<br>';
5668
+							$typePrefix = 'xsd';
5669
+						} else {
5670
+							foreach ($this->typemap as $ns => $types) {
5671
+								if (isset($types[$partType])) {
5672
+									$typePrefix = $this->getPrefixFromNamespace($ns);
5673
+								}
5674
+							}
5675
+							if (!isset($typePrefix)) {
5676
+								die("$partType has no namespace!");
5677
+							}
5678
+						}
5679
+						$ns = $this->getNamespaceFromPrefix($typePrefix);
5680
+						$localPart = $this->getLocalPart($partType);
5681
+						$typeDef = $this->getTypeDef($localPart, $ns);
5682
+						if ('element' === $typeDef['typeClass']) {
5683
+							$elementortype = 'element';
5684
+							if ('^' === substr($localPart, -1)) {
5685
+								$localPart = substr($localPart, 0, -1);
5686
+							}
5687
+						} else {
5688
+							$elementortype = 'type';
5689
+						}
5690
+						$xml .= "\n" . '  <part name="' . $partName . '" ' . $elementortype . '="' . $typePrefix . ':' . $localPart . '" />';
5691
+					}
5692
+				}
5693
+				$xml .= '</message>';
5694
+			}
5695
+		}
5696
+		// bindings & porttypes
5697
+		if (is_array($this->bindings) && count($this->bindings) >= 1) {
5698
+			$binding_xml = '';
5699
+			$portType_xml = '';
5700
+			foreach ($this->bindings as $bindingName => $attrs) {
5701
+				$binding_xml .= "\n<binding name=\"" . $bindingName . '" type="tns:' . $attrs['portType'] . '">';
5702
+				$binding_xml .= "\n" . '  <soap:binding style="' . $attrs['style'] . '" transport="' . $attrs['transport'] . '"/>';
5703
+				$portType_xml .= "\n<portType name=\"" . $attrs['portType'] . '">';
5704
+				foreach ($attrs['operations'] as $opName => $opParts) {
5705
+					$binding_xml .= "\n" . '  <operation name="' . $opName . '">';
5706
+					$binding_xml .= "\n" . '    <soap:operation soapAction="' . $opParts['soapAction'] . '" style="' . $opParts['style'] . '"/>';
5707
+					if (isset($opParts['input']['encodingStyle']) && '' != $opParts['input']['encodingStyle']) {
5708
+						$enc_style = ' encodingStyle="' . $opParts['input']['encodingStyle'] . '"';
5709
+					} else {
5710
+						$enc_style = '';
5711
+					}
5712
+					$binding_xml .= "\n" . '    <input><soap:body use="' . $opParts['input']['use'] . '" namespace="' . $opParts['input']['namespace'] . '"' . $enc_style . '/></input>';
5713
+					if (isset($opParts['output']['encodingStyle']) && '' != $opParts['output']['encodingStyle']) {
5714
+						$enc_style = ' encodingStyle="' . $opParts['output']['encodingStyle'] . '"';
5715
+					} else {
5716
+						$enc_style = '';
5717
+					}
5718
+					$binding_xml .= "\n" . '    <output><soap:body use="' . $opParts['output']['use'] . '" namespace="' . $opParts['output']['namespace'] . '"' . $enc_style . '/></output>';
5719
+					$binding_xml .= "\n" . '  </operation>';
5720
+					$portType_xml .= "\n" . '  <operation name="' . $opParts['name'] . '"';
5721
+					if (isset($opParts['parameterOrder'])) {
5722
+						$portType_xml .= ' parameterOrder="' . $opParts['parameterOrder'] . '"';
5723
+					}
5724
+					$portType_xml .= '>';
5725
+					if (isset($opParts['documentation']) && '' != $opParts['documentation']) {
5726
+						$portType_xml .= "\n" . '    <documentation>' . htmlspecialchars($opParts['documentation']) . '</documentation>';
5727
+					}
5728
+					$portType_xml .= "\n" . '    <input message="tns:' . $opParts['input']['message'] . '"/>';
5729
+					$portType_xml .= "\n" . '    <output message="tns:' . $opParts['output']['message'] . '"/>';
5730
+					$portType_xml .= "\n" . '  </operation>';
5731
+				}
5732
+				$portType_xml .= "\n" . '</portType>';
5733
+				$binding_xml .= "\n" . '</binding>';
5734
+			}
5735
+			$xml .= $portType_xml . $binding_xml;
5736
+		}
5737
+		// services
5738
+		$xml .= "\n<service name=\"" . $this->serviceName . '">';
5739
+		if (is_array($this->ports) && count($this->ports) >= 1) {
5740
+			foreach ($this->ports as $pName => $attrs) {
5741
+				$xml .= "\n" . '  <port name="' . $pName . '" binding="tns:' . $attrs['binding'] . '">';
5742
+				$xml .= "\n" . '    <soap:address location="' . $attrs['location'] . ($debug ? '?debug=1' : '') . '"/>';
5743
+				$xml .= "\n" . '  </port>';
5744
+			}
5745
+		}
5746
+		$xml .= "\n" . '</service>';
5747
+		return $xml . "\n</definitions>";
5748
+	}
5749
+
5750
+	/**
5751
+	 * determine whether a set of parameters are unwrapped
5752
+	 * when they are expect to be wrapped, Microsoft-style.
5753
+	 *
5754
+	 * @param string $type the type (element name) of the wrapper
5755
+	 * @param array $parameters the parameter values for the SOAP call
5756
+	 * @return boolean whether they parameters are unwrapped (and should be wrapped)
5757
+	 * @access private
5758
+	 */
5759
+	private function parametersMatchWrapped($type, &$parameters)
5760
+	{
5761
+		$this->debug("in parametersMatchWrapped type=$type, parameters=");
5762
+		$this->appendDebug($this->varDump($parameters));
5763
+
5764
+		// split type into namespace:unqualified-type
5765
+		if (strpos($type, ':')) {
5766
+			$uqType = substr($type, strrpos($type, ':') + 1);
5767
+			$ns = substr($type, 0, strrpos($type, ':'));
5768
+			$this->debug("in parametersMatchWrapped: got a prefixed type: $uqType, $ns");
5769
+			if ($this->getNamespaceFromPrefix($ns)) {
5770
+				$ns = $this->getNamespaceFromPrefix($ns);
5771
+				$this->debug("in parametersMatchWrapped: expanded prefixed type: $uqType, $ns");
5772
+			}
5773
+		} else {
5774
+			// TODO: should the type be compared to types in XSD, and the namespace
5775
+			// set to XSD if the type matches?
5776
+			$this->debug("in parametersMatchWrapped: No namespace for type $type");
5777
+			$ns = '';
5778
+			$uqType = $type;
5779
+		}
5780
+
5781
+		// get the type information
5782
+		if (!$typeDef = $this->getTypeDef($uqType, $ns)) {
5783
+			$this->debug("in parametersMatchWrapped: $type ($uqType) is not a supported type.");
5784
+			return false;
5785
+		}
5786
+		$this->debug('in parametersMatchWrapped: found typeDef=');
5787
+		$this->appendDebug($this->varDump($typeDef));
5788
+		if ('^' === substr($uqType, -1)) {
5789
+			$uqType = substr($uqType, 0, -1);
5790
+		}
5791
+		$phpType = $typeDef['phpType'];
5792
+		$arrayType = (isset($typeDef['arrayType']) ? $typeDef['arrayType'] : '');
5793
+		$this->debug("in parametersMatchWrapped: uqType: $uqType, ns: $ns, phptype: $phpType, arrayType: $arrayType");
5794
+
5795
+		// we expect a complexType or element of complexType
5796
+		if ('struct' !== $phpType) {
5797
+			$this->debug('in parametersMatchWrapped: not a struct');
5798
+			return false;
5799
+		}
5800
+
5801
+		// see whether the parameter names match the elements
5802
+		if (isset($typeDef['elements']) && is_array($typeDef['elements'])) {
5803
+			$elements = 0;
5804
+			$matches = 0;
5805
+			foreach ($typeDef['elements'] as $name => $attrs) {
5806
+				if (isset($parameters[$name])) {
5807
+					$this->debug("in parametersMatchWrapped: have parameter named $name");
5808
+					$matches++;
5809
+				} else {
5810
+					$this->debug("in parametersMatchWrapped: do not have parameter named $name");
5811
+				}
5812
+				$elements++;
5813
+			}
5814
+
5815
+			$this->debug("in parametersMatchWrapped: $matches parameter names match $elements wrapped parameter names");
5816
+			if (0 == $matches) {
5817
+				return false;
5818
+			}
5819
+			return true;
5820
+		}
5821
+
5822
+		// since there are no elements for the type, if the user passed no
5823
+		// parameters, the parameters match wrapped.
5824
+		$this->debug("in parametersMatchWrapped: no elements type $ns:$uqType");
5825
+		return 0 == count($parameters);
5826
+	}
5827
+
5828
+	/**
5829
+	 * serialize PHP values according to a WSDL message definition
5830
+	 * contrary to the method name, this is not limited to RPC
5831
+	 *
5832
+	 * TODO
5833
+	 * - multi-ref serialization
5834
+	 * - validate PHP values against type definitions, return errors if invalid
5835
+	 *
5836
+	 * @param string $operation operation name
5837
+	 * @param string $direction (input|output)
5838
+	 * @param mixed $parameters parameter value(s)
5839
+	 * @param string $bindingType (soap|soap12)
5840
+	 * @return mixed parameters serialized as XML or false on error (e.g. operation not found)
5841
+	 * @access public
5842
+	 */
5843
+	public function serializeRPCParameters($operation, $direction, $parameters, $bindingType = 'soap')
5844
+	{
5845
+		$this->debug("in serializeRPCParameters: operation=$operation, direction=$direction, XMLSchemaVersion=$this->XMLSchemaVersion, bindingType=$bindingType");
5846
+		$this->appendDebug('parameters=' . $this->varDump($parameters));
5847
+
5848
+		if ('input' !== $direction && 'output' !== $direction) {
5849
+			$this->debug('The value of the \$direction argument needs to be either "input" or "output"');
5850
+			$this->setError('The value of the \$direction argument needs to be either "input" or "output"');
5851
+			return false;
5852
+		}
5853
+		if (!$opData = $this->getOperationData($operation, $bindingType)) {
5854
+			$this->debug('Unable to retrieve WSDL data for operation: ' . $operation . ' bindingType: ' . $bindingType);
5855
+			$this->setError('Unable to retrieve WSDL data for operation: ' . $operation . ' bindingType: ' . $bindingType);
5856
+			return false;
5857
+		}
5858
+		$this->debug('in serializeRPCParameters: opData:');
5859
+		$this->appendDebug($this->varDump($opData));
5860
+
5861
+		// Get encoding style for output and set to current
5862
+		$encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
5863
+		if (('input' === $direction) && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) {
5864
+			$encodingStyle = $opData['output']['encodingStyle'];
5865
+			$enc_style = $encodingStyle;
5866
+		}
5867
+
5868
+		// set input params
5869
+		$xml = '';
5870
+		if (isset($opData[$direction]['parts']) && count($opData[$direction]['parts']) > 0) {
5871
+			$parts = &$opData[$direction]['parts'];
5872
+			$part_count = count($parts);
5873
+			$style = $opData['style'];
5874
+			$use = $opData[$direction]['use'];
5875
+			$this->debug("have $part_count part(s) to serialize using $style/$use");
5876
+			if (is_array($parameters)) {
5877
+				$parametersArrayType = $this->isArraySimpleOrStruct($parameters);
5878
+				$parameter_count = count($parameters);
5879
+				$this->debug("have $parameter_count parameter(s) provided as $parametersArrayType to serialize");
5880
+				// check for Microsoft-style wrapped parameters
5881
+				if ('document' === $style && 'literal' === $use && 1 == $part_count && isset($parts['parameters'])) {
5882
+					$this->debug('check whether the caller has wrapped the parameters');
5883
+					if ('output' === $direction && 'arraySimple' === $parametersArrayType && 1 == $parameter_count) {
5884
+						// TODO: consider checking here for double-wrapping, when
5885
+						// service function wraps, then NuSOAP wraps again
5886
+						$this->debug("change simple array to associative with 'parameters' element");
5887
+						$parameters['parameters'] = $parameters[0];
5888
+						unset($parameters[0]);
5889
+					}
5890
+					if (('arrayStruct' === $parametersArrayType || 0 == $parameter_count) && !isset($parameters['parameters'])) {
5891
+						$this->debug('check whether caller\'s parameters match the wrapped ones');
5892
+						if ($this->parametersMatchWrapped($parts['parameters'], $parameters)) {
5893
+							$this->debug('wrap the parameters for the caller');
5894
+							$parameters = ['parameters' => $parameters];
5895
+							$parameter_count = 1;
5896
+						}
5897
+					}
5898
+				}
5899
+				foreach ($parts as $name => $type) {
5900
+					$this->debug("serializing part $name of type $type");
5901
+					// Track encoding style
5902
+					if (isset($opData[$direction]['encodingStyle']) && $encodingStyle != $opData[$direction]['encodingStyle']) {
5903
+						$encodingStyle = $opData[$direction]['encodingStyle'];
5904
+						$enc_style = $encodingStyle;
5905
+					} else {
5906
+						$enc_style = false;
5907
+					}
5908
+					// NOTE: add error handling here
5909
+					// if serializeType returns false, then catch global error and fault
5910
+					if ('arraySimple' === $parametersArrayType) {
5911
+						$p = array_shift($parameters);
5912
+						$this->debug('calling serializeType w/indexed param');
5913
+						$xml .= $this->serializeType($name, $type, $p, $use, $enc_style);
5914
+					} elseif (isset($parameters[$name])) {
5915
+						$this->debug('calling serializeType w/named param');
5916
+						$xml .= $this->serializeType($name, $type, $parameters[$name], $use, $enc_style);
5917
+					} else {
5918
+						// TODO: only send nillable
5919
+						$this->debug('calling serializeType w/null param');
5920
+						$xml .= $this->serializeType($name, $type, null, $use, $enc_style);
5921
+					}
5922
+				}
5923
+			} else {
5924
+				$this->debug('no parameters passed.');
5925
+			}
5926
+		}
5927
+		$this->debug("serializeRPCParameters returning: $xml");
5928
+		return $xml;
5929
+	}
5930
+
5931
+	/**
5932
+	 * serialize a PHP value according to a WSDL message definition
5933
+	 *
5934
+	 * TODO
5935
+	 * - multi-ref serialization
5936
+	 * - validate PHP values against type definitions, return errors if invalid
5937
+	 *
5938
+	 * @param string $operation operation name
5939
+	 * @param string $direction (input|output)
5940
+	 * @param mixed $parameters parameter value(s)
5941
+	 * @return mixed parameters serialized as XML or false on error (e.g. operation not found)
5942
+	 * @access public
5943
+	 * @deprecated
5944
+	 */
5945
+	public function serializeParameters($operation, $direction, $parameters)
5946
+	{
5947
+		$this->debug("in serializeParameters: operation=$operation, direction=$direction, XMLSchemaVersion=$this->XMLSchemaVersion");
5948
+		$this->appendDebug('parameters=' . $this->varDump($parameters));
5949
+
5950
+		if ('input' !== $direction && 'output' !== $direction) {
5951
+			$this->debug('The value of the \$direction argument needs to be either "input" or "output"');
5952
+			$this->setError('The value of the \$direction argument needs to be either "input" or "output"');
5953
+			return false;
5954
+		}
5955
+		if (!$opData = $this->getOperationData($operation)) {
5956
+			$this->debug('Unable to retrieve WSDL data for operation: ' . $operation);
5957
+			$this->setError('Unable to retrieve WSDL data for operation: ' . $operation);
5958
+			return false;
5959
+		}
5960
+		$this->debug('opData:');
5961
+		$this->appendDebug($this->varDump($opData));
5962
+
5963
+		// Get encoding style for output and set to current
5964
+		$encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
5965
+		if (('input' === $direction) && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) {
5966
+			$encodingStyle = $opData['output']['encodingStyle'];
5967
+			$enc_style = $encodingStyle;
5968
+		}
5969
+
5970
+		// set input params
5971
+		$xml = '';
5972
+		if (isset($opData[$direction]['parts']) && count($opData[$direction]['parts']) > 0) {
5973
+			$use = $opData[$direction]['use'];
5974
+			$this->debug("use=$use");
5975
+			$this->debug('got ' . count($opData[$direction]['parts']) . ' part(s)');
5976
+			if (is_array($parameters)) {
5977
+				$parametersArrayType = $this->isArraySimpleOrStruct($parameters);
5978
+				$this->debug('have ' . $parametersArrayType . ' parameters');
5979
+				foreach ($opData[$direction]['parts'] as $name => $type) {
5980
+					$this->debug('serializing part "' . $name . '" of type "' . $type . '"');
5981
+					// Track encoding style
5982
+					if (isset($opData[$direction]['encodingStyle']) && $encodingStyle != $opData[$direction]['encodingStyle']) {
5983
+						$encodingStyle = $opData[$direction]['encodingStyle'];
5984
+						$enc_style = $encodingStyle;
5985
+					} else {
5986
+						$enc_style = false;
5987
+					}
5988
+					// NOTE: add error handling here
5989
+					// if serializeType returns false, then catch global error and fault
5990
+					if ('arraySimple' === $parametersArrayType) {
5991
+						$p = array_shift($parameters);
5992
+						$this->debug('calling serializeType w/indexed param');
5993
+						$xml .= $this->serializeType($name, $type, $p, $use, $enc_style);
5994
+					} elseif (isset($parameters[$name])) {
5995
+						$this->debug('calling serializeType w/named param');
5996
+						$xml .= $this->serializeType($name, $type, $parameters[$name], $use, $enc_style);
5997
+					} else {
5998
+						// TODO: only send nillable
5999
+						$this->debug('calling serializeType w/null param');
6000
+						$xml .= $this->serializeType($name, $type, null, $use, $enc_style);
6001
+					}
6002
+				}
6003
+			} else {
6004
+				$this->debug('no parameters passed.');
6005
+			}
6006
+		}
6007
+		$this->debug("serializeParameters returning: $xml");
6008
+		return $xml;
6009
+	}
6010
+
6011
+	/**
6012
+	 * serializes a PHP value according a given type definition
6013
+	 *
6014
+	 * @param string  $name          name of value (part or element)
6015
+	 * @param string  $type          XML schema type of value (type or element)
6016
+	 * @param mixed   $value         a native PHP value (parameter value)
6017
+	 * @param string  $use           use for part (encoded|literal)
6018
+	 * @param bool|string $encodingStyle SOAP encoding style for the value (if different than the enclosing style)
6019
+	 * @param bool $unqualified   a kludge for what should be XML namespace form handling
6020
+	 * @return string value serialized as an XML string
6021
+	 * @access private
6022
+	 */
6023
+	private function serializeType($name, $type, $value, $use = 'encoded', $encodingStyle = false, $unqualified = false)
6024
+	{
6025
+		$this->debug("in serializeType: name=$name, type=$type, use=$use, encodingStyle=$encodingStyle, unqualified=" . ($unqualified ? 'unqualified' : 'qualified'));
6026
+		$this->appendDebug('value=' . $this->varDump($value));
6027
+		if ('encoded' === $use && $encodingStyle) {
6028
+			$encodingStyle = ' SOAP-ENV:encodingStyle="' . $encodingStyle . '"';
6029
+		}
6030
+
6031
+		// if a soapval has been supplied, let its type override the WSDL
6032
+		if (is_object($value) && 'soapval' === get_class($value)) {
6033
+			if ($value->type_ns) {
6034
+				$type = $value->type_ns . ':' . $value->type;
6035
+				$forceType = true;
6036
+				$this->debug("in serializeType: soapval overrides type to $type");
6037
+			} elseif ($value->type) {
6038
+				$type = $value->type;
6039
+				$forceType = true;
6040
+				$this->debug("in serializeType: soapval overrides type to $type");
6041
+			} else {
6042
+				$forceType = false;
6043
+				$this->debug('in serializeType: soapval does not override type');
6044
+			}
6045
+			$attrs = $value->attributes;
6046
+			$value = $value->value;
6047
+			$this->debug("in serializeType: soapval overrides value to $value");
6048
+			if ($attrs) {
6049
+				if (!is_array($value)) {
6050
+					$value['!'] = $value;
6051
+				}
6052
+				foreach ($attrs as $n => $v) {
6053
+					$value['!' . $n] = $v;
6054
+				}
6055
+				$this->debug('in serializeType: soapval provides attributes');
6056
+			}
6057
+		} else {
6058
+			$forceType = false;
6059
+		}
6060
+
6061
+		$xml = '';
6062
+		if (strpos($type, ':')) {
6063
+			$uqType = substr($type, strrpos($type, ':') + 1);
6064
+			$ns = substr($type, 0, strrpos($type, ':'));
6065
+			$this->debug("in serializeType: got a prefixed type: $uqType, $ns");
6066
+			if ($this->getNamespaceFromPrefix($ns)) {
6067
+				$ns = $this->getNamespaceFromPrefix($ns);
6068
+				$this->debug("in serializeType: expanded prefixed type: $uqType, $ns");
6069
+			}
6070
+
6071
+			if ($ns == $this->XMLSchemaVersion || 'http://schemas.xmlsoap.org/soap/encoding/' === $ns) {
6072
+				$this->debug('in serializeType: type namespace indicates XML Schema or SOAP Encoding type');
6073
+				if ($unqualified && 'literal' === $use) {
6074
+					$elementNS = ' xmlns=""';
6075
+				} else {
6076
+					$elementNS = '';
6077
+				}
6078
+				if (null === $value) {
6079
+					if ('literal' === $use) {
6080
+						// TODO: depends on minOccurs
6081
+						$xml = "<$name$elementNS/>";
6082
+					} else {
6083
+						// TODO: depends on nillable, which should be checked before calling this method
6084
+						$xml = "<$name$elementNS xsi:nil=\"true\" xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"/>";
6085
+					}
6086
+					$this->debug("in serializeType: returning: $xml");
6087
+					return $xml;
6088
+				}
6089
+				if ('Array' === $uqType) {
6090
+					// JBoss/Axis does this sometimes
6091
+					return $this->serialize_val($value, $name, false, false, false, false, $use);
6092
+				}
6093
+				if ('boolean' === $uqType) {
6094
+					if ((is_string($value) && 'false' === $value) || (!$value)) {
6095
+						$value = 'false';
6096
+					} else {
6097
+						$value = 'true';
6098
+					}
6099
+				}
6100
+				if ('string' === $uqType && 'string' === gettype($value)) {
6101
+					$value = $this->expandEntities($value);
6102
+				}
6103
+				if (('long' === $uqType || 'unsignedLong' === $uqType) && 'double' === gettype($value)) {
6104
+					$value = sprintf('%.0lf', $value);
6105
+				}
6106
+				// it's a scalar
6107
+				// TODO: what about null/nil values?
6108
+				// check type isn't a custom type extending xmlschema namespace
6109
+				if (!$this->getTypeDef($uqType, $ns)) {
6110
+					if ('literal' === $use) {
6111
+						if ($forceType) {
6112
+							$xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">$value</$name>";
6113
+						} else {
6114
+							$xml = "<$name$elementNS>$value</$name>";
6115
+						}
6116
+					} else {
6117
+						$xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>$value</$name>";
6118
+					}
6119
+					$this->debug("in serializeType: returning: $xml");
6120
+					return $xml;
6121
+				}
6122
+				$this->debug('custom type extends XML Schema or SOAP Encoding namespace (yuck)');
6123
+			} elseif ('http://xml.apache.org/xml-soap' === $ns) {
6124
+				$this->debug('in serializeType: appears to be Apache SOAP type');
6125
+				if ('Map' === $uqType) {
6126
+					$tt_prefix = $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap');
6127
+					if (!$tt_prefix) {
6128
+						$this->debug('in serializeType: Add namespace for Apache SOAP type');
6129
+						$tt_prefix = 'ns' . mt_rand(1000, 9999);
6130
+						$this->namespaces[$tt_prefix] = 'http://xml.apache.org/xml-soap';
6131
+						// force this to be added to usedNamespaces
6132
+						$tt_prefix = $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap');
6133
+					}
6134
+					$contents = '';
6135
+					foreach ($value as $k => $v) {
6136
+						$this->debug("serializing map element: key $k, value $v");
6137
+						$contents .= '<item>';
6138
+						$contents .= $this->serialize_val($k, 'key', false, false, false, false, $use);
6139
+						$contents .= $this->serialize_val($v, 'value', false, false, false, false, $use);
6140
+						$contents .= '</item>';
6141
+					}
6142
+					if ('literal' === $use) {
6143
+						if ($forceType) {
6144
+							$xml = "<$name xsi:type=\"" . $tt_prefix . ":$uqType\">$contents</$name>";
6145
+						} else {
6146
+							$xml = "<$name>$contents</$name>";
6147
+						}
6148
+					} else {
6149
+						$xml = "<$name xsi:type=\"" . $tt_prefix . ":$uqType\"$encodingStyle>$contents</$name>";
6150
+					}
6151
+					$this->debug("in serializeType: returning: $xml");
6152
+					return $xml;
6153
+				}
6154
+				$this->debug('in serializeType: Apache SOAP type, but only support Map');
6155
+			}
6156
+		} else {
6157
+			// TODO: should the type be compared to types in XSD, and the namespace
6158
+			// set to XSD if the type matches?
6159
+			$this->debug("in serializeType: No namespace for type $type");
6160
+			$ns = '';
6161
+			$uqType = $type;
6162
+		}
6163
+		if (!$typeDef = $this->getTypeDef($uqType, $ns)) {
6164
+			$this->setError("$type ($uqType) is not a supported type.");
6165
+			$this->debug("in serializeType: $type ($uqType) is not a supported type.");
6166
+			return false;
6167
+		} else {
6168
+			$this->debug('in serializeType: found typeDef');
6169
+			$this->appendDebug('typeDef=' . $this->varDump($typeDef));
6170
+			if ('^' === substr($uqType, -1)) {
6171
+				$uqType = substr($uqType, 0, -1);
6172
+			}
6173
+		}
6174
+		if (!isset($typeDef['phpType'])) {
6175
+			$this->setError("$type ($uqType) has no phpType.");
6176
+			$this->debug("in serializeType: $type ($uqType) has no phpType.");
6177
+			return false;
6178
+		}
6179
+		$phpType = $typeDef['phpType'];
6180
+		$this->debug("in serializeType: uqType: $uqType, ns: $ns, phptype: $phpType, arrayType: " . (isset($typeDef['arrayType']) ? $typeDef['arrayType'] : ''));
6181
+		// if php type == struct, map value to the <all> element names
6182
+		if ('struct' === $phpType) {
6183
+			if (isset($typeDef['typeClass']) && 'element' === $typeDef['typeClass']) {
6184
+				$elementName = $uqType;
6185
+				if (isset($typeDef['form']) && ('qualified' === $typeDef['form'])) {
6186
+					$elementNS = " xmlns=\"$ns\"";
6187
+				} else {
6188
+					$elementNS = ' xmlns=""';
6189
+				}
6190
+			} else {
6191
+				$elementName = $name;
6192
+				if ($unqualified) {
6193
+					$elementNS = ' xmlns=""';
6194
+				} else {
6195
+					$elementNS = '';
6196
+				}
6197
+			}
6198
+			if (null === $value) {
6199
+				if ('literal' === $use) {
6200
+					// TODO: depends on minOccurs and nillable
6201
+					$xml = "<$elementName$elementNS/>";
6202
+				} else {
6203
+					$xml = "<$elementName$elementNS xsi:nil=\"true\" xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"/>";
6204
+				}
6205
+				$this->debug("in serializeType: returning: $xml");
6206
+				return $xml;
6207
+			}
6208
+			if (is_object($value)) {
6209
+				$value = get_object_vars($value);
6210
+			}
6211
+			if (is_array($value)) {
6212
+				$elementAttrs = $this->serializeComplexTypeAttributes($typeDef, $value, $ns, $uqType);
6213
+				if ('literal' === $use) {
6214
+					if ($forceType) {
6215
+						$xml = "<$elementName$elementNS$elementAttrs xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">";
6216
+					} else {
6217
+						$xml = "<$elementName$elementNS$elementAttrs>";
6218
+					}
6219
+				} else {
6220
+					$xml = "<$elementName$elementNS$elementAttrs xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>";
6221
+				}
6222
+
6223
+				if (isset($typeDef['simpleContent']) && 'true' === $typeDef['simpleContent']) {
6224
+					if (isset($value['!'])) {
6225
+						$xml .= $value['!'];
6226
+						$this->debug("in serializeType: serialized simpleContent for type $type");
6227
+					} else {
6228
+						$this->debug("in serializeType: no simpleContent to serialize for type $type");
6229
+					}
6230
+				} else {
6231
+					// complexContent
6232
+					$xml .= $this->serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use, $encodingStyle);
6233
+				}
6234
+				$xml .= "</$elementName>";
6235
+			} else {
6236
+				$this->debug('in serializeType: phpType is struct, but value is not an array');
6237
+				$this->setError('phpType is struct, but value is not an array: see debug output for details');
6238
+				$xml = '';
6239
+			}
6240
+		} elseif ('array' === $phpType) {
6241
+			if (isset($typeDef['form']) && ('qualified' === $typeDef['form'])) {
6242
+				$elementNS = " xmlns=\"$ns\"";
6243
+			} else {
6244
+				if ($unqualified) {
6245
+					$elementNS = ' xmlns=""';
6246
+				} else {
6247
+					$elementNS = '';
6248
+				}
6249
+			}
6250
+			if (null === $value) {
6251
+				if ('literal' === $use) {
6252
+					// TODO: depends on minOccurs
6253
+					$xml = "<$name$elementNS/>";
6254
+				} else {
6255
+					$xml = "<$name$elementNS xsi:nil=\"true\" xsi:type=\"" .
6256
+						$this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') . ':Array" ' .
6257
+						$this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') .
6258
+						':arrayType="' .
6259
+						$this->getPrefixFromNamespace($this->getPrefix($typeDef['arrayType'])) .
6260
+						':' .
6261
+						$this->getLocalPart($typeDef['arrayType']) . '[0]"/>';
6262
+				}
6263
+				$this->debug("in serializeType: returning: $xml");
6264
+				return $xml;
6265
+			}
6266
+			if (isset($typeDef['multidimensional'])) {
6267
+				$nv = [];
6268
+				foreach ($value as $v) {
6269
+					$cols = ',' . count($v);
6270
+					$nv = array_merge($nv, $v);
6271
+				}
6272
+				$value = $nv;
6273
+			} else {
6274
+				$cols = '';
6275
+			}
6276
+			if (is_array($value) && count($value) >= 1) {
6277
+				$rows = count($value);
6278
+				$contents = '';
6279
+				foreach ($value as $k => $v) {
6280
+					$this->debug("serializing array element: $k, " . (is_array($v) ? 'array' : $v) . " of type: $typeDef[arrayType]");
6281
+					//if (strpos($typeDef['arrayType'], ':') ) {
6282
+					if (!in_array($typeDef['arrayType'], $this->typemap['http://www.w3.org/2001/XMLSchema'])) {
6283
+						$contents .= $this->serializeType('item', $typeDef['arrayType'], $v, $use);
6284
+					} else {
6285
+						$contents .= $this->serialize_val($v, 'item', $typeDef['arrayType'], null, $this->XMLSchemaVersion, false, $use);
6286
+					}
6287
+				}
6288
+			} else {
6289
+				$rows = 0;
6290
+				$contents = null;
6291
+			}
6292
+			// TODO: for now, an empty value will be serialized as a zero element
6293
+			// array.  Revisit this when coding the handling of null/nil values.
6294
+			if ('literal' === $use) {
6295
+				$xml = "<$name$elementNS>"
6296
+					. $contents
6297
+					. "</$name>";
6298
+			} else {
6299
+				$xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') . ':Array" ' .
6300
+					$this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/')
6301
+					. ':arrayType="'
6302
+					. $this->getPrefixFromNamespace($this->getPrefix($typeDef['arrayType']))
6303
+					   . ':' . $this->getLocalPart($typeDef['arrayType']) . "[$rows$cols]\">"
6304
+					. $contents
6305
+					. "</$name>";
6306
+			}
6307
+		} elseif ('scalar' === $phpType) {
6308
+			if (isset($typeDef['form']) && ('qualified' === $typeDef['form'])) {
6309
+				$elementNS = " xmlns=\"$ns\"";
6310
+			} else {
6311
+				if ($unqualified) {
6312
+					$elementNS = ' xmlns=""';
6313
+				} else {
6314
+					$elementNS = '';
6315
+				}
6316
+			}
6317
+			if ('literal' === $use) {
6318
+				if ($forceType) {
6319
+					$xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">$value</$name>";
6320
+				} else {
6321
+					$xml = "<$name$elementNS>$value</$name>";
6322
+				}
6323
+			} else {
6324
+				$xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>$value</$name>";
6325
+			}
6326
+		}
6327
+		$this->debug("in serializeType: returning: $xml");
6328
+		return $xml;
6329
+	}
6330
+
6331
+	/**
6332
+	 * serializes the attributes for a complexType
6333
+	 *
6334
+	 * @param array $typeDef our internal representation of an XML schema type (or element)
6335
+	 * @param mixed $value a native PHP value (parameter value)
6336
+	 * @param string $ns the namespace of the type
6337
+	 * @param string $uqType the local part of the type
6338
+	 * @return string value serialized as an XML string
6339
+	 * @access private
6340
+	 */
6341
+	private function serializeComplexTypeAttributes($typeDef, $value, $ns, $uqType)
6342
+	{
6343
+		$this->debug("serializeComplexTypeAttributes for XML Schema type $ns:$uqType");
6344
+		$xml = '';
6345
+		if (isset($typeDef['extensionBase'])) {
6346
+			$nsx = $this->getPrefix($typeDef['extensionBase']);
6347
+			$uqTypex = $this->getLocalPart($typeDef['extensionBase']);
6348
+			if ($this->getNamespaceFromPrefix($nsx)) {
6349
+				$nsx = $this->getNamespaceFromPrefix($nsx);
6350
+			}
6351
+			if (false !== ($typeDefx = $this->getTypeDef($uqTypex, $nsx))) {
6352
+				$this->debug("serialize attributes for extension base $nsx:$uqTypex");
6353
+				$xml .= $this->serializeComplexTypeAttributes($typeDefx, $value, $nsx, $uqTypex);
6354
+			} else {
6355
+				$this->debug("extension base $nsx:$uqTypex is not a supported type");
6356
+			}
6357
+		}
6358
+		if (isset($typeDef['attrs']) && is_array($typeDef['attrs'])) {
6359
+			$this->debug("serialize attributes for XML Schema type $ns:$uqType");
6360
+			if (is_array($value)) {
6361
+				$xvalue = $value;
6362
+			} elseif (is_object($value)) {
6363
+				$xvalue = get_object_vars($value);
6364
+			} else {
6365
+				$this->debug("value is neither an array nor an object for XML Schema type $ns:$uqType");
6366
+				$xvalue = [];
6367
+			}
6368
+			foreach ($typeDef['attrs'] as $aName => $attrs) {
6369
+				if (isset($xvalue['!' . $aName])) {
6370
+					$xname = '!' . $aName;
6371
+					$this->debug("value provided for attribute $aName with key $xname");
6372
+				} elseif (isset($xvalue[$aName])) {
6373
+					$xname = $aName;
6374
+					$this->debug("value provided for attribute $aName with key $xname");
6375
+				} elseif (isset($attrs['default'])) {
6376
+					$xname = '!' . $aName;
6377
+					$xvalue[$xname] = $attrs['default'];
6378
+					$this->debug('use default value of ' . $xvalue[$aName] . ' for attribute ' . $aName);
6379
+				} else {
6380
+					$xname = '';
6381
+					$this->debug("no value provided for attribute $aName");
6382
+				}
6383
+				if ($xname) {
6384
+					$xml .= " $aName=\"" . $this->expandEntities($xvalue[$xname]) . '"';
6385
+				}
6386
+			}
6387
+		} else {
6388
+			$this->debug("no attributes to serialize for XML Schema type $ns:$uqType");
6389
+		}
6390
+		return $xml;
6391
+	}
6392
+
6393
+	/**
6394
+	 * serializes the elements for a complexType
6395
+	 *
6396
+	 * @param array  $typeDef       our internal representation of an XML schema type (or element)
6397
+	 * @param mixed  $value         a native PHP value (parameter value)
6398
+	 * @param string $ns            the namespace of the type
6399
+	 * @param string $uqType        the local part of the type
6400
+	 * @param string $use           use for part (encoded|literal)
6401
+	 * @param bool|string $encodingStyle SOAP encoding style for the value (if different than the enclosing style)
6402
+	 * @return string value serialized as an XML string
6403
+	 * @access private
6404
+	 */
6405
+	private function serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use = 'encoded', $encodingStyle = false)
6406
+	{
6407
+		$this->debug("in serializeComplexTypeElements for XML Schema type $ns:$uqType");
6408
+		$xml = '';
6409
+		if (isset($typeDef['extensionBase'])) {
6410
+			$nsx = $this->getPrefix($typeDef['extensionBase']);
6411
+			$uqTypex = $this->getLocalPart($typeDef['extensionBase']);
6412
+			if ($this->getNamespaceFromPrefix($nsx)) {
6413
+				$nsx = $this->getNamespaceFromPrefix($nsx);
6414
+			}
6415
+			if (false !== ($typeDefx = $this->getTypeDef($uqTypex, $nsx))) {
6416
+				$this->debug("serialize elements for extension base $nsx:$uqTypex");
6417
+				$xml .= $this->serializeComplexTypeElements($typeDefx, $value, $nsx, $uqTypex, $use, $encodingStyle);
6418
+			} else {
6419
+				$this->debug("extension base $nsx:$uqTypex is not a supported type");
6420
+			}
6421
+		}
6422
+		if (isset($typeDef['elements']) && is_array($typeDef['elements'])) {
6423
+			$this->debug("in serializeComplexTypeElements, serialize elements for XML Schema type $ns:$uqType");
6424
+			if (is_array($value)) {
6425
+				$xvalue = $value;
6426
+			} elseif (is_object($value)) {
6427
+				$xvalue = get_object_vars($value);
6428
+			} else {
6429
+				$this->debug("value is neither an array nor an object for XML Schema type $ns:$uqType");
6430
+				$xvalue = [];
6431
+			}
6432
+			// toggle whether all elements are present - ideally should validate against schema
6433
+			if (is_array($xvalue) && (count($typeDef['elements']) != count($xvalue))) {
6434
+				$optionals = true;
6435
+			}
6436
+			foreach ($typeDef['elements'] as $eName => $attrs) {
6437
+				if (!isset($xvalue[$eName])) {
6438
+					if (isset($attrs['default'])) {
6439
+						$xvalue[$eName] = $attrs['default'];
6440
+						$this->debug('use default value of ' . $xvalue[$eName] . ' for element ' . $eName);
6441
+					}
6442
+				}
6443
+				// if user took advantage of a minOccurs=0, then only serialize named parameters
6444
+				if (isset($optionals)
6445
+					&& (!isset($xvalue[$eName]))
6446
+					&& ((!isset($attrs['nillable'])) || 'true' !== $attrs['nillable'])
6447
+				) {
6448
+					if (isset($attrs['minOccurs']) && '0' <> $attrs['minOccurs']) {
6449
+						$this->debug("apparent error: no value provided for element $eName with minOccurs=" . $attrs['minOccurs']);
6450
+					}
6451
+					// do nothing
6452
+					$this->debug("no value provided for complexType element $eName and element is not nillable, so serialize nothing");
6453
+				} else {
6454
+					// get value
6455
+					if (isset($xvalue[$eName])) {
6456
+						$v = $xvalue[$eName];
6457
+					} else {
6458
+						$v = null;
6459
+					}
6460
+					if (isset($attrs['form'])) {
6461
+						$unqualified = ('unqualified' === $attrs['form']);
6462
+					} else {
6463
+						$unqualified = false;
6464
+					}
6465
+					if (isset($attrs['maxOccurs']) && ('unbounded' === $attrs['maxOccurs'] || $attrs['maxOccurs'] > 1) && isset($v) && is_array($v) && 'arraySimple' === $this->isArraySimpleOrStruct($v)) {
6466
+						$vv = $v;
6467
+						foreach ($vv as $k => $v) {
6468
+							if (isset($attrs['type']) || isset($attrs['ref'])) {
6469
+								// serialize schema-defined type
6470
+								$xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified);
6471
+							} else {
6472
+								// serialize generic type (can this ever really happen?)
6473
+								$this->debug("calling serialize_val() for $v, $eName, false, false, false, false, $use");
6474
+								$xml .= $this->serialize_val($v, $eName, false, false, false, false, $use);
6475
+							}
6476
+						}
6477
+					} else {
6478
+						if (null === $v && isset($attrs['minOccurs']) && '0' == $attrs['minOccurs']) {
6479
+							// do nothing
6480
+						} elseif (null === $v && isset($attrs['nillable']) && 'true' === $attrs['nillable']) {
6481
+							// TODO: serialize a nil correctly, but for now serialize schema-defined type
6482
+							$xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified);
6483
+						} elseif (isset($attrs['type']) || isset($attrs['ref'])) {
6484
+							// serialize schema-defined type
6485
+							$xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified);
6486
+						} else {
6487
+							// serialize generic type (can this ever really happen?)
6488
+							$this->debug("calling serialize_val() for $v, $eName, false, false, false, false, $use");
6489
+							$xml .= $this->serialize_val($v, $eName, false, false, false, false, $use);
6490
+						}
6491
+					}
6492
+				}
6493
+			}
6494
+		} else {
6495
+			$this->debug("no elements to serialize for XML Schema type $ns:$uqType");
6496
+		}
6497
+		return $xml;
6498
+	}
6499
+
6500
+	/**
6501
+	 * adds an XML Schema complex type to the WSDL types
6502
+	 *
6503
+	 * @param string $name
6504
+	 * @param string $typeClass (complexType|simpleType|attribute)
6505
+	 * @param string $phpType currently supported are array and struct (php assoc array)
6506
+	 * @param string $compositor (all|sequence|choice)
6507
+	 * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
6508
+	 * @param array $elements e.g. array ( name => array(name=>'',type=>'') )
6509
+	 * @param array $attrs e.g. array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'xsd:string[]'))
6510
+	 * @param string $arrayType as namespace:name (xsd:string)
6511
+	 * @see nusoap_xmlschema
6512
+	 * @access public
6513
+	 */
6514
+	public function addComplexType($name, $typeClass = 'complexType', $phpType = 'array', $compositor = '', $restrictionBase = '', $elements = [], $attrs = [], $arrayType = '')
6515
+	{
6516
+		if (is_array($elements) && count($elements) > 0) {
6517
+			$eElements = [];
6518
+			foreach ($elements as $n => $e) {
6519
+				// expand each element
6520
+				$ee = [];
6521
+				foreach ($e as $k => $v) {
6522
+					$k = strpos($k, ':') ? $this->expandQname($k) : $k;
6523
+					$v = strpos($v, ':') ? $this->expandQname($v) : $v;
6524
+					$ee[$k] = $v;
6525
+				}
6526
+				$eElements[$n] = $ee;
6527
+			}
6528
+			$elements = $eElements;
6529
+		}
6530
+
6531
+		if (is_array($attrs) && count($attrs) > 0) {
6532
+			foreach ($attrs as $n => $a) {
6533
+				// expand each attribute
6534
+				foreach ($a as $k => $v) {
6535
+					$k = strpos($k, ':') ? $this->expandQname($k) : $k;
6536
+					$v = strpos($v, ':') ? $this->expandQname($v) : $v;
6537
+					$aa[$k] = $v;
6538
+				}
6539
+				$eAttrs[$n] = $aa;
6540
+			}
6541
+			$attrs = $eAttrs;
6542
+		}
6543
+
6544
+		$restrictionBase = strpos($restrictionBase, ':') ? $this->expandQname($restrictionBase) : $restrictionBase;
6545
+		$arrayType = strpos($arrayType, ':') ? $this->expandQname($arrayType) : $arrayType;
6546
+
6547
+		$typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns'];
6548
+		$this->schemas[$typens][0]->addComplexType($name, $typeClass, $phpType, $compositor, $restrictionBase, $elements, $attrs, $arrayType);
6549
+	}
6550
+
6551
+	/**
6552
+	 * adds an XML Schema simple type to the WSDL types
6553
+	 *
6554
+	 * @param string $name
6555
+	 * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
6556
+	 * @param string $typeClass (should always be simpleType)
6557
+	 * @param string $phpType (should always be scalar)
6558
+	 * @param array $enumeration array of values
6559
+	 * @see nusoap_xmlschema
6560
+	 * @access public
6561
+	 */
6562
+	public function addSimpleType($name, $restrictionBase = '', $typeClass = 'simpleType', $phpType = 'scalar', $enumeration = [])
6563
+	{
6564
+		$restrictionBase = strpos($restrictionBase, ':') ? $this->expandQname($restrictionBase) : $restrictionBase;
6565
+
6566
+		$typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns'];
6567
+		$this->schemas[$typens][0]->addSimpleType($name, $restrictionBase, $typeClass, $phpType, $enumeration);
6568
+	}
6569
+
6570
+	/**
6571
+	 * adds an element to the WSDL types
6572
+	 *
6573
+	 * @param array $attrs attributes that must include name and type
6574
+	 * @see nusoap_xmlschema
6575
+	 * @access public
6576
+	 */
6577
+	public function addElement($attrs)
6578
+	{
6579
+		$typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns'];
6580
+		$this->schemas[$typens][0]->addElement($attrs);
6581
+	}
6582
+
6583
+	/**
6584
+	 * register an operation with the server
6585
+	 *
6586
+	 * @param string      $name          operation (method) name
6587
+	 * @param bool|array  $in            assoc array of input values: key = param name, value = param type
6588
+	 * @param bool|array  $out           assoc array of output values: key = param name, value = param type
6589
+	 * @param bool|string $namespace     optional The namespace for the operation
6590
+	 * @param bool|string $soapaction    optional The soapaction for the operation
6591
+	 * @param string      $style         (rpc|document) optional The style for the operation Note: when 'document' is specified, parameter and return wrappers are created for you automatically
6592
+	 * @param string      $use           (encoded|literal) optional The use for the parameters (cannot mix right now)
6593
+	 * @param string      $documentation optional The description to include in the WSDL
6594
+	 * @param string      $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
6595
+	 * @access public
6596
+	 * @return bool
6597
+	 */
6598
+	public function addOperation($name, $in = false, $out = false, $namespace = false, $soapaction = false, $style = 'rpc', $use = 'encoded', $documentation = '', $encodingStyle = '')
6599
+	{
6600
+		if ('encoded' === $use && '' == $encodingStyle) {
6601
+			$encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
6602
+		}
6603
+
6604
+		if ('document' === $style) {
6605
+			$elements = [];
6606
+			foreach ($in as $n => $t) {
6607
+				$elements[$n] = ['name' => $n, 'type' => $t, 'form' => 'unqualified'];
6608
+			}
6609
+			$this->addComplexType($name . 'RequestType', 'complexType', 'struct', 'all', '', $elements);
6610
+			$this->addElement(['name' => $name, 'type' => $name . 'RequestType']);
6611
+			$in = ['parameters' => 'tns:' . $name . '^'];
6612
+
6613
+			$elements = [];
6614
+			foreach ($out as $n => $t) {
6615
+				$elements[$n] = ['name' => $n, 'type' => $t, 'form' => 'unqualified'];
6616
+			}
6617
+			$this->addComplexType($name . 'ResponseType', 'complexType', 'struct', 'all', '', $elements);
6618
+			$this->addElement(['name' => $name . 'Response', 'type' => $name . 'ResponseType', 'form' => 'qualified']);
6619
+			$out = ['parameters' => 'tns:' . $name . 'Response' . '^'];
6620
+		}
6621
+
6622
+		// get binding
6623
+		$this->bindings[$this->serviceName . 'Binding']['operations'][$name] =
6624
+			[
6625
+				'name' => $name,
6626
+				'binding' => $this->serviceName . 'Binding',
6627
+				'endpoint' => $this->endpoint,
6628
+				'soapAction' => $soapaction,
6629
+				'style' => $style,
6630
+				'input' => [
6631
+					'use' => $use,
6632
+					'namespace' => $namespace,
6633
+					'encodingStyle' => $encodingStyle,
6634
+					'message' => $name . 'Request',
6635
+					'parts' => $in
6636
+				],
6637
+				'output' => [
6638
+					'use' => $use,
6639
+					'namespace' => $namespace,
6640
+					'encodingStyle' => $encodingStyle,
6641
+					'message' => $name . 'Response',
6642
+					'parts' => $out
6643
+				],
6644
+				'namespace' => $namespace,
6645
+				'transport' => 'http://schemas.xmlsoap.org/soap/http',
6646
+				'documentation' => $documentation
6647
+			];
6648
+		// add portTypes
6649
+		// add messages
6650
+		if ($in) {
6651
+			foreach ($in as $pName => $pType) {
6652
+				if (strpos($pType, ':')) {
6653
+					$pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)) . ':' . $this->getLocalPart($pType);
6654
+				}
6655
+				$this->messages[$name . 'Request'][$pName] = $pType;
6656
+			}
6657
+		} else {
6658
+			$this->messages[$name . 'Request'] = '0';
6659
+		}
6660
+		if ($out) {
6661
+			foreach ($out as $pName => $pType) {
6662
+				if (strpos($pType, ':')) {
6663
+					$pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)) . ':' . $this->getLocalPart($pType);
6664
+				}
6665
+				$this->messages[$name . 'Response'][$pName] = $pType;
6666
+			}
6667
+		} else {
6668
+			$this->messages[$name . 'Response'] = '0';
6669
+		}
6670
+		return true;
6671
+	}
6672 6672
 }
6673 6673
 
6674 6674
 
@@ -6683,235 +6683,235 @@  discard block
 block discarded – undo
6683 6683
  */
6684 6684
 class nusoap_parser extends nusoap_base
6685 6685
 {
6686
-    public $xml = '';
6687
-    public $xml_encoding = '';
6688
-    public $method = '';
6689
-    public $root_struct = '';
6690
-    public $root_struct_name = '';
6691
-    public $root_struct_namespace = '';
6692
-    public $root_header = '';
6693
-    public $document = '';            // incoming SOAP body (text)
6694
-    // determines where in the message we are (envelope,header,body,method)
6695
-    public $status = '';
6696
-    public $position = 0;
6697
-    public $depth = 0;
6698
-    public $default_namespace = '';
6686
+	public $xml = '';
6687
+	public $xml_encoding = '';
6688
+	public $method = '';
6689
+	public $root_struct = '';
6690
+	public $root_struct_name = '';
6691
+	public $root_struct_namespace = '';
6692
+	public $root_header = '';
6693
+	public $document = '';            // incoming SOAP body (text)
6694
+	// determines where in the message we are (envelope,header,body,method)
6695
+	public $status = '';
6696
+	public $position = 0;
6697
+	public $depth = 0;
6698
+	public $default_namespace = '';
6699 6699
 //    public $namespaces = []; //Field 'namespaces' is already defined in \nusoap_base
6700
-    public $message = [];
6701
-    public $parent = '';
6702
-    public $fault = false;
6703
-    public $fault_code = '';
6704
-    public $fault_str = '';
6705
-    public $fault_detail = '';
6706
-    public $depth_array = [];
6707
-    public $debug_flag = true;
6708
-    public $soapresponse;    // parsed SOAP Body
6709
-    public $soapheader;        // parsed SOAP Header
6710
-    public $responseHeaders = '';    // incoming SOAP headers (text)
6711
-    public $body_position = 0;
6712
-    // for multiref parsing:
6713
-    // array of id => pos
6714
-    public $ids = [];
6715
-    // array of id => hrefs => pos
6716
-    public $multirefs = [];
6717
-    // toggle for auto-decoding element content
6718
-    public $decode_utf8 = true;
6719
-
6720
-    /**
6721
-     * constructor that actually does the parsing
6722
-     *
6723
-     * @param    string $xml         SOAP message
6724
-     * @param    string $encoding    character encoding scheme of message
6725
-     * @param    string|array $method      method for which XML is parsed (unused?)
6726
-     * @param    bool|string $decode_utf8 whether to decode UTF-8 to ISO-8859-1
6727
-     * @access   public
6728
-     */
6729
-    public function __construct($xml, $encoding = 'UTF-8', $method = '', $decode_utf8 = true)
6730
-    {
6731
-        parent::__construct();
6732
-        $this->xml = $xml;
6733
-        $this->xml_encoding = $encoding;
6734
-        $this->method = $method;
6735
-        $this->decode_utf8 = $decode_utf8;
6736
-
6737
-        // Check whether content has been read.
6738
-        if (!empty($xml)) {
6739
-            // Check XML encoding
6740
-            $pos_xml = strpos($xml, '<?xml');
6741
-            if (false !== $pos_xml) {
6742
-                $xml_decl = substr($xml, $pos_xml, strpos($xml, '?>', $pos_xml + 2) - $pos_xml + 1);
6743
-                if (preg_match("/encoding=[\"']([^\"']*)[\"']/", $xml_decl, $res)) {
6744
-                    $xml_encoding = $res[1];
6745
-                    if (strtoupper($xml_encoding) != $encoding) {
6746
-                        $err = "Charset from HTTP Content-Type '" . $encoding . "' does not match encoding from XML declaration '" . $xml_encoding . "'";
6747
-                        $this->debug($err);
6748
-                        if ('ISO-8859-1' !== $encoding || 'UTF-8' !== strtoupper($xml_encoding)) {
6749
-                            $this->setError($err);
6750
-                            return;
6751
-                        }
6752
-                        // when HTTP says ISO-8859-1 (the default) and XML says UTF-8 (the typical), assume the other endpoint is just sloppy and proceed
6753
-                    } else {
6754
-                        $this->debug('Charset from HTTP Content-Type matches encoding from XML declaration');
6755
-                    }
6756
-                } else {
6757
-                    $this->debug('No encoding specified in XML declaration');
6758
-                }
6759
-            } else {
6760
-                $this->debug('No XML declaration');
6761
-            }
6762
-            $this->debug('Entering nusoap_parser(), length=' . strlen($xml) . ', encoding=' . $encoding);
6763
-            // Create an XML parser - why not xml_parser_create_ns?
6764
-            $this->parser = xml_parser_create($this->xml_encoding);
6765
-            // Set the options for parsing the XML data.
6766
-            //xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
6767
-            xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
6768
-            xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, $this->xml_encoding);
6769
-            // Set the object for the parser.
6770
-            xml_set_object($this->parser, $this);
6771
-            // Set the element handlers for the parser.
6772
-            xml_set_element_handler($this->parser, 'start_element', 'end_element');
6773
-            xml_set_character_data_handler($this->parser, 'character_data');
6774
-
6775
-            // Parse the XML file.
6776
-            if (!xml_parse($this->parser, $xml, true)) {
6777
-                // Display an error message.
6778
-                $err = sprintf(
6779
-                    'XML error parsing SOAP payload on line %d: %s',
6780
-                    xml_get_current_line_number($this->parser),
6781
-                    xml_error_string(xml_get_error_code($this->parser))
6782
-                );
6783
-                $this->debug($err);
6784
-                $this->debug("XML payload:\n" . $xml);
6785
-                $this->setError($err);
6786
-            } else {
6787
-                $this->debug('in nusoap_parser ctor, message:');
6788
-                $this->appendDebug($this->varDump($this->message));
6789
-                $this->debug('parsed successfully, found root struct: ' . $this->root_struct . ' of name ' . $this->root_struct_name);
6790
-                // get final value
6791
-                $this->soapresponse = $this->message[$this->root_struct]['result'];
6792
-                // get header value
6793
-                if ('' != $this->root_header && isset($this->message[$this->root_header]['result'])) {
6794
-                    $this->soapheader = $this->message[$this->root_header]['result'];
6795
-                }
6796
-                // resolve hrefs/ids
6797
-                if (is_array($this->multirefs) && count($this->multirefs) > 0) {
6798
-                    foreach ($this->multirefs as $id => $hrefs) {
6799
-                        $this->debug('resolving multirefs for id: ' . $id);
6800
-                        $idVal = $this->buildVal($this->ids[$id]);
6801
-                        if (is_array($idVal) && isset($idVal['!id'])) {
6802
-                            unset($idVal['!id']);
6803
-                        }
6804
-                        foreach ($hrefs as $refPos => $ref) {
6805
-                            $this->debug('resolving href at pos ' . $refPos);
6806
-                            $this->multirefs[$id][$refPos] = $idVal;
6807
-                        }
6808
-                    }
6809
-                }
6810
-            }
6811
-            xml_parser_free($this->parser);
6812
-            unset($this->parser);
6813
-        } else {
6814
-            $this->debug('xml was empty, didn\'t parse!');
6815
-            $this->setError('xml was empty, didn\'t parse!');
6816
-        }
6817
-    }
6818
-
6819
-    /**
6820
-     * start-element handler
6821
-     *
6822
-     * @param    resource $parser XML parser object
6823
-     * @param    string $name element name
6824
-     * @param    array $attrs associative array of attributes
6825
-     * @access   private
6826
-     */
6827
-    private function start_element($parser, $name, $attrs)
6828
-    {
6829
-        // position in a total number of elements, starting from 0
6830
-        // update class level pos
6831
-        $pos = $this->position++;
6832
-        // and set mine
6833
-        $this->message[$pos] = ['pos' => $pos, 'children' => '', 'cdata' => ''];
6834
-        // depth = how many levels removed from root?
6835
-        // set mine as current global depth and increment global depth value
6836
-        $this->message[$pos]['depth'] = $this->depth++;
6837
-
6838
-        // else add self as child to whoever the current parent is
6839
-        if (0 != $pos) {
6840
-            $this->message[$this->parent]['children'] .= '|' . $pos;
6841
-        }
6842
-        // set my parent
6843
-        $this->message[$pos]['parent'] = $this->parent;
6844
-        // set self as current parent
6845
-        $this->parent = $pos;
6846
-        // set self as current value for this depth
6847
-        $this->depth_array[$this->depth] = $pos;
6848
-        // get element prefix
6849
-        if (strpos($name, ':')) {
6850
-            // get ns prefix
6851
-            $prefix = substr($name, 0, strpos($name, ':'));
6852
-            // get unqualified name
6853
-            $name = substr(strstr($name, ':'), 1);
6854
-        }
6855
-        // set status
6856
-        if ('Envelope' === $name && '' == $this->status) {
6857
-            $this->status = 'envelope';
6858
-        } elseif ('Header' === $name && 'envelope' === $this->status) {
6859
-            $this->root_header = $pos;
6860
-            $this->status = 'header';
6861
-        } elseif ('Body' === $name && 'envelope' === $this->status) {
6862
-            $this->status = 'body';
6863
-            $this->body_position = $pos;
6864
-        // set method
6865
-        } elseif ('body' === $this->status && $pos == ($this->body_position + 1)) {
6866
-            $this->status = 'method';
6867
-            $this->root_struct_name = $name;
6868
-            $this->root_struct = $pos;
6869
-            $this->message[$pos]['type'] = 'struct';
6870
-            $this->debug("found root struct $this->root_struct_name, pos $this->root_struct");
6871
-        }
6872
-        // set my status
6873
-        $this->message[$pos]['status'] = $this->status;
6874
-        // set name
6875
-        $this->message[$pos]['name'] = htmlspecialchars($name);
6876
-        // set attrs
6877
-        $this->message[$pos]['attrs'] = $attrs;
6878
-
6879
-        // loop through atts, logging ns and type declarations
6880
-        $attstr = '';
6881
-        foreach ($attrs as $key => $value) {
6882
-            $key_prefix = $this->getPrefix($key);
6883
-            $key_localpart = $this->getLocalPart($key);
6884
-            // if ns declarations, add to class level array of valid namespaces
6885
-            if ('xmlns' === $key_prefix) {
6886
-                if (preg_match('/^http:\/\/www.w3.org\/[0-9]{4}\/XMLSchema$/', $value)) {
6887
-                    $this->XMLSchemaVersion = $value;
6888
-                    $this->namespaces['xsd'] = $this->XMLSchemaVersion;
6889
-                    $this->namespaces['xsi'] = $this->XMLSchemaVersion . '-instance';
6890
-                }
6891
-                $this->namespaces[$key_localpart] = $value;
6892
-                // set method namespace
6893
-                if ($name == $this->root_struct_name) {
6894
-                    $this->methodNamespace = $value;
6895
-                }
6896
-                // if it's a type declaration, set type
6897
-            } elseif ('type' === $key_localpart) {
6898
-                if (isset($this->message[$pos]['type']) && 'array' === $this->message[$pos]['type']) {
6899
-                    // do nothing: already processed arrayType
6900
-                } else {
6901
-                    $value_prefix = $this->getPrefix($value);
6902
-                    $value_localpart = $this->getLocalPart($value);
6903
-                    $this->message[$pos]['type'] = $value_localpart;
6904
-                    $this->message[$pos]['typePrefix'] = $value_prefix;
6905
-                    if (isset($this->namespaces[$value_prefix])) {
6906
-                        $this->message[$pos]['type_namespace'] = $this->namespaces[$value_prefix];
6907
-                    } elseif (isset($attrs['xmlns:' . $value_prefix])) {
6908
-                        $this->message[$pos]['type_namespace'] = $attrs['xmlns:' . $value_prefix];
6909
-                    }
6910
-                    // should do something here with the namespace of specified type?
6911
-                }
6912
-            } elseif ('arrayType' === $key_localpart) {
6913
-                $this->message[$pos]['type'] = 'array';
6914
-                /* do arrayType ereg here
6700
+	public $message = [];
6701
+	public $parent = '';
6702
+	public $fault = false;
6703
+	public $fault_code = '';
6704
+	public $fault_str = '';
6705
+	public $fault_detail = '';
6706
+	public $depth_array = [];
6707
+	public $debug_flag = true;
6708
+	public $soapresponse;    // parsed SOAP Body
6709
+	public $soapheader;        // parsed SOAP Header
6710
+	public $responseHeaders = '';    // incoming SOAP headers (text)
6711
+	public $body_position = 0;
6712
+	// for multiref parsing:
6713
+	// array of id => pos
6714
+	public $ids = [];
6715
+	// array of id => hrefs => pos
6716
+	public $multirefs = [];
6717
+	// toggle for auto-decoding element content
6718
+	public $decode_utf8 = true;
6719
+
6720
+	/**
6721
+	 * constructor that actually does the parsing
6722
+	 *
6723
+	 * @param    string $xml         SOAP message
6724
+	 * @param    string $encoding    character encoding scheme of message
6725
+	 * @param    string|array $method      method for which XML is parsed (unused?)
6726
+	 * @param    bool|string $decode_utf8 whether to decode UTF-8 to ISO-8859-1
6727
+	 * @access   public
6728
+	 */
6729
+	public function __construct($xml, $encoding = 'UTF-8', $method = '', $decode_utf8 = true)
6730
+	{
6731
+		parent::__construct();
6732
+		$this->xml = $xml;
6733
+		$this->xml_encoding = $encoding;
6734
+		$this->method = $method;
6735
+		$this->decode_utf8 = $decode_utf8;
6736
+
6737
+		// Check whether content has been read.
6738
+		if (!empty($xml)) {
6739
+			// Check XML encoding
6740
+			$pos_xml = strpos($xml, '<?xml');
6741
+			if (false !== $pos_xml) {
6742
+				$xml_decl = substr($xml, $pos_xml, strpos($xml, '?>', $pos_xml + 2) - $pos_xml + 1);
6743
+				if (preg_match("/encoding=[\"']([^\"']*)[\"']/", $xml_decl, $res)) {
6744
+					$xml_encoding = $res[1];
6745
+					if (strtoupper($xml_encoding) != $encoding) {
6746
+						$err = "Charset from HTTP Content-Type '" . $encoding . "' does not match encoding from XML declaration '" . $xml_encoding . "'";
6747
+						$this->debug($err);
6748
+						if ('ISO-8859-1' !== $encoding || 'UTF-8' !== strtoupper($xml_encoding)) {
6749
+							$this->setError($err);
6750
+							return;
6751
+						}
6752
+						// when HTTP says ISO-8859-1 (the default) and XML says UTF-8 (the typical), assume the other endpoint is just sloppy and proceed
6753
+					} else {
6754
+						$this->debug('Charset from HTTP Content-Type matches encoding from XML declaration');
6755
+					}
6756
+				} else {
6757
+					$this->debug('No encoding specified in XML declaration');
6758
+				}
6759
+			} else {
6760
+				$this->debug('No XML declaration');
6761
+			}
6762
+			$this->debug('Entering nusoap_parser(), length=' . strlen($xml) . ', encoding=' . $encoding);
6763
+			// Create an XML parser - why not xml_parser_create_ns?
6764
+			$this->parser = xml_parser_create($this->xml_encoding);
6765
+			// Set the options for parsing the XML data.
6766
+			//xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
6767
+			xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
6768
+			xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, $this->xml_encoding);
6769
+			// Set the object for the parser.
6770
+			xml_set_object($this->parser, $this);
6771
+			// Set the element handlers for the parser.
6772
+			xml_set_element_handler($this->parser, 'start_element', 'end_element');
6773
+			xml_set_character_data_handler($this->parser, 'character_data');
6774
+
6775
+			// Parse the XML file.
6776
+			if (!xml_parse($this->parser, $xml, true)) {
6777
+				// Display an error message.
6778
+				$err = sprintf(
6779
+					'XML error parsing SOAP payload on line %d: %s',
6780
+					xml_get_current_line_number($this->parser),
6781
+					xml_error_string(xml_get_error_code($this->parser))
6782
+				);
6783
+				$this->debug($err);
6784
+				$this->debug("XML payload:\n" . $xml);
6785
+				$this->setError($err);
6786
+			} else {
6787
+				$this->debug('in nusoap_parser ctor, message:');
6788
+				$this->appendDebug($this->varDump($this->message));
6789
+				$this->debug('parsed successfully, found root struct: ' . $this->root_struct . ' of name ' . $this->root_struct_name);
6790
+				// get final value
6791
+				$this->soapresponse = $this->message[$this->root_struct]['result'];
6792
+				// get header value
6793
+				if ('' != $this->root_header && isset($this->message[$this->root_header]['result'])) {
6794
+					$this->soapheader = $this->message[$this->root_header]['result'];
6795
+				}
6796
+				// resolve hrefs/ids
6797
+				if (is_array($this->multirefs) && count($this->multirefs) > 0) {
6798
+					foreach ($this->multirefs as $id => $hrefs) {
6799
+						$this->debug('resolving multirefs for id: ' . $id);
6800
+						$idVal = $this->buildVal($this->ids[$id]);
6801
+						if (is_array($idVal) && isset($idVal['!id'])) {
6802
+							unset($idVal['!id']);
6803
+						}
6804
+						foreach ($hrefs as $refPos => $ref) {
6805
+							$this->debug('resolving href at pos ' . $refPos);
6806
+							$this->multirefs[$id][$refPos] = $idVal;
6807
+						}
6808
+					}
6809
+				}
6810
+			}
6811
+			xml_parser_free($this->parser);
6812
+			unset($this->parser);
6813
+		} else {
6814
+			$this->debug('xml was empty, didn\'t parse!');
6815
+			$this->setError('xml was empty, didn\'t parse!');
6816
+		}
6817
+	}
6818
+
6819
+	/**
6820
+	 * start-element handler
6821
+	 *
6822
+	 * @param    resource $parser XML parser object
6823
+	 * @param    string $name element name
6824
+	 * @param    array $attrs associative array of attributes
6825
+	 * @access   private
6826
+	 */
6827
+	private function start_element($parser, $name, $attrs)
6828
+	{
6829
+		// position in a total number of elements, starting from 0
6830
+		// update class level pos
6831
+		$pos = $this->position++;
6832
+		// and set mine
6833
+		$this->message[$pos] = ['pos' => $pos, 'children' => '', 'cdata' => ''];
6834
+		// depth = how many levels removed from root?
6835
+		// set mine as current global depth and increment global depth value
6836
+		$this->message[$pos]['depth'] = $this->depth++;
6837
+
6838
+		// else add self as child to whoever the current parent is
6839
+		if (0 != $pos) {
6840
+			$this->message[$this->parent]['children'] .= '|' . $pos;
6841
+		}
6842
+		// set my parent
6843
+		$this->message[$pos]['parent'] = $this->parent;
6844
+		// set self as current parent
6845
+		$this->parent = $pos;
6846
+		// set self as current value for this depth
6847
+		$this->depth_array[$this->depth] = $pos;
6848
+		// get element prefix
6849
+		if (strpos($name, ':')) {
6850
+			// get ns prefix
6851
+			$prefix = substr($name, 0, strpos($name, ':'));
6852
+			// get unqualified name
6853
+			$name = substr(strstr($name, ':'), 1);
6854
+		}
6855
+		// set status
6856
+		if ('Envelope' === $name && '' == $this->status) {
6857
+			$this->status = 'envelope';
6858
+		} elseif ('Header' === $name && 'envelope' === $this->status) {
6859
+			$this->root_header = $pos;
6860
+			$this->status = 'header';
6861
+		} elseif ('Body' === $name && 'envelope' === $this->status) {
6862
+			$this->status = 'body';
6863
+			$this->body_position = $pos;
6864
+		// set method
6865
+		} elseif ('body' === $this->status && $pos == ($this->body_position + 1)) {
6866
+			$this->status = 'method';
6867
+			$this->root_struct_name = $name;
6868
+			$this->root_struct = $pos;
6869
+			$this->message[$pos]['type'] = 'struct';
6870
+			$this->debug("found root struct $this->root_struct_name, pos $this->root_struct");
6871
+		}
6872
+		// set my status
6873
+		$this->message[$pos]['status'] = $this->status;
6874
+		// set name
6875
+		$this->message[$pos]['name'] = htmlspecialchars($name);
6876
+		// set attrs
6877
+		$this->message[$pos]['attrs'] = $attrs;
6878
+
6879
+		// loop through atts, logging ns and type declarations
6880
+		$attstr = '';
6881
+		foreach ($attrs as $key => $value) {
6882
+			$key_prefix = $this->getPrefix($key);
6883
+			$key_localpart = $this->getLocalPart($key);
6884
+			// if ns declarations, add to class level array of valid namespaces
6885
+			if ('xmlns' === $key_prefix) {
6886
+				if (preg_match('/^http:\/\/www.w3.org\/[0-9]{4}\/XMLSchema$/', $value)) {
6887
+					$this->XMLSchemaVersion = $value;
6888
+					$this->namespaces['xsd'] = $this->XMLSchemaVersion;
6889
+					$this->namespaces['xsi'] = $this->XMLSchemaVersion . '-instance';
6890
+				}
6891
+				$this->namespaces[$key_localpart] = $value;
6892
+				// set method namespace
6893
+				if ($name == $this->root_struct_name) {
6894
+					$this->methodNamespace = $value;
6895
+				}
6896
+				// if it's a type declaration, set type
6897
+			} elseif ('type' === $key_localpart) {
6898
+				if (isset($this->message[$pos]['type']) && 'array' === $this->message[$pos]['type']) {
6899
+					// do nothing: already processed arrayType
6900
+				} else {
6901
+					$value_prefix = $this->getPrefix($value);
6902
+					$value_localpart = $this->getLocalPart($value);
6903
+					$this->message[$pos]['type'] = $value_localpart;
6904
+					$this->message[$pos]['typePrefix'] = $value_prefix;
6905
+					if (isset($this->namespaces[$value_prefix])) {
6906
+						$this->message[$pos]['type_namespace'] = $this->namespaces[$value_prefix];
6907
+					} elseif (isset($attrs['xmlns:' . $value_prefix])) {
6908
+						$this->message[$pos]['type_namespace'] = $attrs['xmlns:' . $value_prefix];
6909
+					}
6910
+					// should do something here with the namespace of specified type?
6911
+				}
6912
+			} elseif ('arrayType' === $key_localpart) {
6913
+				$this->message[$pos]['type'] = 'array';
6914
+				/* do arrayType ereg here
6915 6915
                 [1]    arrayTypeValue    ::=    atype asize
6916 6916
                 [2]    atype    ::=    QName rank*
6917 6917
                 [3]    rank    ::=    '[' (',')* ']'
@@ -6919,130 +6919,130 @@  discard block
 block discarded – undo
6919 6919
                 [5]    length    ::=    nextDimension* Digit+
6920 6920
                 [6]    nextDimension    ::=    Digit+ ','
6921 6921
                 */
6922
-                $expr = '/([A-Za-z0-9_]+):([A-Za-z]+[A-Za-z0-9_]+)\[([0-9]+),?([0-9]*)\]/';
6923
-                if (preg_match($expr, $value, $regs)) {
6924
-                    $this->message[$pos]['typePrefix'] = $regs[1];
6925
-                    $this->message[$pos]['arrayTypePrefix'] = $regs[1];
6926
-                    if (isset($this->namespaces[$regs[1]])) {
6927
-                        $this->message[$pos]['arrayTypeNamespace'] = $this->namespaces[$regs[1]];
6928
-                    } elseif (isset($attrs['xmlns:' . $regs[1]])) {
6929
-                        $this->message[$pos]['arrayTypeNamespace'] = $attrs['xmlns:' . $regs[1]];
6930
-                    }
6931
-                    $this->message[$pos]['arrayType'] = $regs[2];
6932
-                    $this->message[$pos]['arraySize'] = $regs[3];
6933
-                    $this->message[$pos]['arrayCols'] = $regs[4];
6934
-                }
6935
-                // specifies nil value (or not)
6936
-            } elseif ('nil' === $key_localpart) {
6937
-                $this->message[$pos]['nil'] = ('true' === $value || '1' == $value);
6938
-            // some other attribute
6939
-            } elseif ('href' !== $key && 'xmlns' !== $key && 'encodingStyle' !== $key_localpart && 'root' !== $key_localpart) {
6940
-                $this->message[$pos]['xattrs']['!' . $key] = $value;
6941
-            }
6942
-
6943
-            if ('xmlns' === $key) {
6944
-                $this->default_namespace = $value;
6945
-            }
6946
-            // log id
6947
-            if ('id' === $key) {
6948
-                $this->ids[$value] = $pos;
6949
-            }
6950
-            // root
6951
-            if ('root' === $key_localpart && 1 == $value) {
6952
-                $this->status = 'method';
6953
-                $this->root_struct_name = $name;
6954
-                $this->root_struct = $pos;
6955
-                $this->debug("found root struct $this->root_struct_name, pos $pos");
6956
-            }
6957
-            // for doclit
6958
-            $attstr .= " $key=\"$value\"";
6959
-        }
6960
-        // get namespace - must be done after namespace atts are processed
6961
-        if (isset($prefix)) {
6962
-            $this->message[$pos]['namespace'] = $this->namespaces[$prefix];
6963
-            $this->default_namespace = $this->namespaces[$prefix];
6964
-        } else {
6965
-            $this->message[$pos]['namespace'] = $this->default_namespace;
6966
-        }
6967
-        if ('header' === $this->status) {
6968
-            if ($this->root_header != $pos) {
6969
-                $this->responseHeaders .= '<' . (isset($prefix) ? $prefix . ':' : '') . "$name$attstr>";
6970
-            }
6971
-        } elseif ('' != $this->root_struct_name) {
6972
-            $this->document .= '<' . (isset($prefix) ? $prefix . ':' : '') . "$name$attstr>";
6973
-        }
6974
-    }
6975
-
6976
-    /**
6977
-     * end-element handler
6978
-     *
6979
-     * @param    resource $parser XML parser object
6980
-     * @param    string $name element name
6981
-     * @access   private
6982
-     */
6983
-    private function end_element($parser, $name)
6984
-    {
6985
-        // position of current element is equal to the last value left in depth_array for my depth
6986
-        $pos = $this->depth_array[$this->depth--];
6987
-
6988
-        // get element prefix
6989
-        if (strpos($name, ':')) {
6990
-            // get ns prefix
6991
-            $prefix = substr($name, 0, strpos($name, ':'));
6992
-            // get unqualified name
6993
-            $name = substr(strstr($name, ':'), 1);
6994
-        }
6995
-
6996
-        // build to native type
6997
-        if (isset($this->body_position) && $pos > $this->body_position) {
6998
-            // deal w/ multirefs
6999
-            if (isset($this->message[$pos]['attrs']['href'])) {
7000
-                // get id
7001
-                $id = substr($this->message[$pos]['attrs']['href'], 1);
7002
-                // add placeholder to href array
7003
-                $this->multirefs[$id][$pos] = 'placeholder';
7004
-                // add set a reference to it as the result value
7005
-                $this->message[$pos]['result'] =& $this->multirefs[$id][$pos];
7006
-            // build complexType values
7007
-            } elseif ('' != $this->message[$pos]['children']) {
7008
-                // if result has already been generated (struct/array)
7009
-                if (!isset($this->message[$pos]['result'])) {
7010
-                    $this->message[$pos]['result'] = $this->buildVal($pos);
7011
-                }
7012
-                // build complexType values of attributes and possibly simpleContent
7013
-            } elseif (isset($this->message[$pos]['xattrs'])) {
7014
-                if (isset($this->message[$pos]['nil']) && $this->message[$pos]['nil']) {
7015
-                    $this->message[$pos]['xattrs']['!'] = null;
7016
-                } elseif (isset($this->message[$pos]['cdata']) && '' != trim($this->message[$pos]['cdata'])) {
7017
-                    if (isset($this->message[$pos]['type'])) {
7018
-                        $this->message[$pos]['xattrs']['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
7019
-                    } else {
7020
-                        $parent = $this->message[$pos]['parent'];
7021
-                        if (isset($this->message[$parent]['type']) && ('array' === $this->message[$parent]['type']) && isset($this->message[$parent]['arrayType'])) {
7022
-                            $this->message[$pos]['xattrs']['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
7023
-                        } else {
7024
-                            $this->message[$pos]['xattrs']['!'] = $this->message[$pos]['cdata'];
7025
-                        }
7026
-                    }
7027
-                }
7028
-                $this->message[$pos]['result'] = $this->message[$pos]['xattrs'];
7029
-            // set value of simpleType (or nil complexType)
7030
-            } else {
7031
-                //$this->debug('adding data for scalar value '.$this->message[$pos]['name'].' of value '.$this->message[$pos]['cdata']);
7032
-                if (isset($this->message[$pos]['nil']) && $this->message[$pos]['nil']) {
7033
-                    $this->message[$pos]['xattrs']['!'] = null;
7034
-                } elseif (isset($this->message[$pos]['type'])) {
7035
-                    $this->message[$pos]['result'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
7036
-                } else {
7037
-                    $parent = $this->message[$pos]['parent'];
7038
-                    if (isset($this->message[$parent]['type']) && ('array' === $this->message[$parent]['type']) && isset($this->message[$parent]['arrayType'])) {
7039
-                        $this->message[$pos]['result'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
7040
-                    } else {
7041
-                        $this->message[$pos]['result'] = $this->message[$pos]['cdata'];
7042
-                    }
7043
-                }
6922
+				$expr = '/([A-Za-z0-9_]+):([A-Za-z]+[A-Za-z0-9_]+)\[([0-9]+),?([0-9]*)\]/';
6923
+				if (preg_match($expr, $value, $regs)) {
6924
+					$this->message[$pos]['typePrefix'] = $regs[1];
6925
+					$this->message[$pos]['arrayTypePrefix'] = $regs[1];
6926
+					if (isset($this->namespaces[$regs[1]])) {
6927
+						$this->message[$pos]['arrayTypeNamespace'] = $this->namespaces[$regs[1]];
6928
+					} elseif (isset($attrs['xmlns:' . $regs[1]])) {
6929
+						$this->message[$pos]['arrayTypeNamespace'] = $attrs['xmlns:' . $regs[1]];
6930
+					}
6931
+					$this->message[$pos]['arrayType'] = $regs[2];
6932
+					$this->message[$pos]['arraySize'] = $regs[3];
6933
+					$this->message[$pos]['arrayCols'] = $regs[4];
6934
+				}
6935
+				// specifies nil value (or not)
6936
+			} elseif ('nil' === $key_localpart) {
6937
+				$this->message[$pos]['nil'] = ('true' === $value || '1' == $value);
6938
+			// some other attribute
6939
+			} elseif ('href' !== $key && 'xmlns' !== $key && 'encodingStyle' !== $key_localpart && 'root' !== $key_localpart) {
6940
+				$this->message[$pos]['xattrs']['!' . $key] = $value;
6941
+			}
6942
+
6943
+			if ('xmlns' === $key) {
6944
+				$this->default_namespace = $value;
6945
+			}
6946
+			// log id
6947
+			if ('id' === $key) {
6948
+				$this->ids[$value] = $pos;
6949
+			}
6950
+			// root
6951
+			if ('root' === $key_localpart && 1 == $value) {
6952
+				$this->status = 'method';
6953
+				$this->root_struct_name = $name;
6954
+				$this->root_struct = $pos;
6955
+				$this->debug("found root struct $this->root_struct_name, pos $pos");
6956
+			}
6957
+			// for doclit
6958
+			$attstr .= " $key=\"$value\"";
6959
+		}
6960
+		// get namespace - must be done after namespace atts are processed
6961
+		if (isset($prefix)) {
6962
+			$this->message[$pos]['namespace'] = $this->namespaces[$prefix];
6963
+			$this->default_namespace = $this->namespaces[$prefix];
6964
+		} else {
6965
+			$this->message[$pos]['namespace'] = $this->default_namespace;
6966
+		}
6967
+		if ('header' === $this->status) {
6968
+			if ($this->root_header != $pos) {
6969
+				$this->responseHeaders .= '<' . (isset($prefix) ? $prefix . ':' : '') . "$name$attstr>";
6970
+			}
6971
+		} elseif ('' != $this->root_struct_name) {
6972
+			$this->document .= '<' . (isset($prefix) ? $prefix . ':' : '') . "$name$attstr>";
6973
+		}
6974
+	}
6975
+
6976
+	/**
6977
+	 * end-element handler
6978
+	 *
6979
+	 * @param    resource $parser XML parser object
6980
+	 * @param    string $name element name
6981
+	 * @access   private
6982
+	 */
6983
+	private function end_element($parser, $name)
6984
+	{
6985
+		// position of current element is equal to the last value left in depth_array for my depth
6986
+		$pos = $this->depth_array[$this->depth--];
6987
+
6988
+		// get element prefix
6989
+		if (strpos($name, ':')) {
6990
+			// get ns prefix
6991
+			$prefix = substr($name, 0, strpos($name, ':'));
6992
+			// get unqualified name
6993
+			$name = substr(strstr($name, ':'), 1);
6994
+		}
7044 6995
 
7045
-                /* add value to parent's result, if parent is struct/array
6996
+		// build to native type
6997
+		if (isset($this->body_position) && $pos > $this->body_position) {
6998
+			// deal w/ multirefs
6999
+			if (isset($this->message[$pos]['attrs']['href'])) {
7000
+				// get id
7001
+				$id = substr($this->message[$pos]['attrs']['href'], 1);
7002
+				// add placeholder to href array
7003
+				$this->multirefs[$id][$pos] = 'placeholder';
7004
+				// add set a reference to it as the result value
7005
+				$this->message[$pos]['result'] =& $this->multirefs[$id][$pos];
7006
+			// build complexType values
7007
+			} elseif ('' != $this->message[$pos]['children']) {
7008
+				// if result has already been generated (struct/array)
7009
+				if (!isset($this->message[$pos]['result'])) {
7010
+					$this->message[$pos]['result'] = $this->buildVal($pos);
7011
+				}
7012
+				// build complexType values of attributes and possibly simpleContent
7013
+			} elseif (isset($this->message[$pos]['xattrs'])) {
7014
+				if (isset($this->message[$pos]['nil']) && $this->message[$pos]['nil']) {
7015
+					$this->message[$pos]['xattrs']['!'] = null;
7016
+				} elseif (isset($this->message[$pos]['cdata']) && '' != trim($this->message[$pos]['cdata'])) {
7017
+					if (isset($this->message[$pos]['type'])) {
7018
+						$this->message[$pos]['xattrs']['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
7019
+					} else {
7020
+						$parent = $this->message[$pos]['parent'];
7021
+						if (isset($this->message[$parent]['type']) && ('array' === $this->message[$parent]['type']) && isset($this->message[$parent]['arrayType'])) {
7022
+							$this->message[$pos]['xattrs']['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
7023
+						} else {
7024
+							$this->message[$pos]['xattrs']['!'] = $this->message[$pos]['cdata'];
7025
+						}
7026
+					}
7027
+				}
7028
+				$this->message[$pos]['result'] = $this->message[$pos]['xattrs'];
7029
+			// set value of simpleType (or nil complexType)
7030
+			} else {
7031
+				//$this->debug('adding data for scalar value '.$this->message[$pos]['name'].' of value '.$this->message[$pos]['cdata']);
7032
+				if (isset($this->message[$pos]['nil']) && $this->message[$pos]['nil']) {
7033
+					$this->message[$pos]['xattrs']['!'] = null;
7034
+				} elseif (isset($this->message[$pos]['type'])) {
7035
+					$this->message[$pos]['result'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
7036
+				} else {
7037
+					$parent = $this->message[$pos]['parent'];
7038
+					if (isset($this->message[$parent]['type']) && ('array' === $this->message[$parent]['type']) && isset($this->message[$parent]['arrayType'])) {
7039
+						$this->message[$pos]['result'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
7040
+					} else {
7041
+						$this->message[$pos]['result'] = $this->message[$pos]['cdata'];
7042
+					}
7043
+				}
7044
+
7045
+				/* add value to parent's result, if parent is struct/array
7046 7046
                 $parent = $this->message[$pos]['parent'];
7047 7047
                 if($this->message[$parent]['type'] != 'map'){
7048 7048
                     if(strtolower($this->message[$parent]['type']) == 'array'){
@@ -7052,270 +7052,270 @@  discard block
 block discarded – undo
7052 7052
                     }
7053 7053
                 }
7054 7054
                 */
7055
-            }
7056
-        }
7057
-
7058
-        // for doclit
7059
-        if ('header' === $this->status) {
7060
-            if ($this->root_header != $pos) {
7061
-                $this->responseHeaders .= '</' . (isset($prefix) ? $prefix . ':' : '') . "$name>";
7062
-            }
7063
-        } elseif ($pos >= $this->root_struct) {
7064
-            $this->document .= '</' . (isset($prefix) ? $prefix . ':' : '') . "$name>";
7065
-        }
7066
-        // switch status
7067
-        if ($pos == $this->root_struct) {
7068
-            $this->status = 'body';
7069
-            $this->root_struct_namespace = $this->message[$pos]['namespace'];
7070
-        } elseif ($pos == $this->root_header) {
7071
-            $this->status = 'envelope';
7072
-        } elseif ('Body' === $name && 'body' === $this->status) {
7073
-            $this->status = 'envelope';
7074
-        } elseif ('Header' === $name && 'header' === $this->status) { // will never happen
7075
-            $this->status = 'envelope';
7076
-        } elseif ('Envelope' === $name && 'envelope' === $this->status) {
7077
-            $this->status = '';
7078
-        }
7079
-        // set parent back to my parent
7080
-        $this->parent = $this->message[$pos]['parent'];
7081
-    }
7082
-
7083
-    /**
7084
-     * element content handler
7085
-     *
7086
-     * @param    resource $parser XML parser object
7087
-     * @param    string $data element content
7088
-     * @access   private
7089
-     */
7090
-    private function character_data($parser, $data)
7091
-    {
7092
-        $pos = $this->depth_array[$this->depth];
7093
-        if ('UTF-8' === $this->xml_encoding) {
7094
-            // TODO: add an option to disable this for folks who want
7095
-            // raw UTF-8 that, e.g., might not map to iso-8859-1
7096
-            // TODO: this can also be handled with xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, "ISO-8859-1");
7097
-            if ($this->decode_utf8) {
7098
-                $data = utf8_decode($data);
7099
-            }
7100
-        }
7101
-        $this->message[$pos]['cdata'] .= $data;
7102
-        // for doclit
7103
-        if ('header' === $this->status) {
7104
-            $this->responseHeaders .= $data;
7105
-        } else {
7106
-            $this->document .= $data;
7107
-        }
7108
-    }
7109
-
7110
-    /**
7111
-     * get the parsed message (SOAP Body)
7112
-     *
7113
-     * @return    mixed
7114
-     * @access   public
7115
-     * @deprecated    use get_soapbody instead
7116
-     */
7117
-    public function get_response()
7118
-    {
7119
-        return $this->soapresponse;
7120
-    }
7121
-
7122
-    /**
7123
-     * get the parsed SOAP Body (null if there was none)
7124
-     *
7125
-     * @return    mixed
7126
-     * @access   public
7127
-     */
7128
-    public function get_soapbody()
7129
-    {
7130
-        return $this->soapresponse;
7131
-    }
7132
-
7133
-    /**
7134
-     * get the parsed SOAP Header (null if there was none)
7135
-     *
7136
-     * @return    mixed
7137
-     * @access   public
7138
-     */
7139
-    public function get_soapheader()
7140
-    {
7141
-        return $this->soapheader;
7142
-    }
7143
-
7144
-    /**
7145
-     * get the unparsed SOAP Header
7146
-     *
7147
-     * @return    string XML or empty if no Header
7148
-     * @access   public
7149
-     */
7150
-    public function getHeaders()
7151
-    {
7152
-        return $this->responseHeaders;
7153
-    }
7154
-
7155
-    /**
7156
-     * decodes simple types into PHP variables
7157
-     *
7158
-     * @param    string $value value to decode
7159
-     * @param    string $type XML type to decode
7160
-     * @param    string $typens XML type namespace to decode
7161
-     * @return    mixed PHP value
7162
-     * @access   private
7163
-     */
7164
-    private function decodeSimple($value, $type, $typens)
7165
-    {
7166
-        // TODO: use the namespace!
7167
-        if ((!isset($type)) || 'string' === $type || 'long' === $type || 'unsignedLong' === $type) {
7168
-            return (string) $value;
7169
-        }
7170
-        if ('int' === $type || 'integer' === $type || 'short' === $type || 'byte' === $type) {
7171
-            return (int) $value;
7172
-        }
7173
-        if ('float' === $type || 'double' === $type || 'decimal' === $type) {
7174
-            return (double) $value;
7175
-        }
7176
-        if ('boolean' === $type) {
7177
-            if ('false' === strtolower($value) || 'f' === strtolower($value)) {
7178
-                return false;
7179
-            }
7180
-            return (boolean) $value;
7181
-        }
7182
-        if ('base64' === $type || 'base64Binary' === $type) {
7183
-            $this->debug('Decode base64 value');
7184
-            return base64_decode($value);
7185
-        }
7186
-        // obscure numeric types
7187
-        if ('nonPositiveInteger' === $type || 'negativeInteger' === $type
7188
-            || 'nonNegativeInteger' === $type
7189
-            || 'positiveInteger' === $type
7190
-            || 'unsignedInt' === $type
7191
-            || 'unsignedShort' === $type
7192
-            || 'unsignedByte' === $type
7193
-        ) {
7194
-            return (int) $value;
7195
-        }
7196
-        // bogus: parser treats array with no elements as a simple type
7197
-        if ('array' === $type) {
7198
-            return [];
7199
-        }
7200
-        // everything else
7201
-        return (string) $value;
7202
-    }
7203
-
7204
-    /**
7205
-     * builds response structures for compound values (arrays/structs)
7206
-     * and scalars
7207
-     *
7208
-     * @param    integer $pos position in node tree
7209
-     * @return    mixed    PHP value
7210
-     * @access   private
7211
-     */
7212
-    private function buildVal($pos)
7213
-    {
7214
-        if (!isset($this->message[$pos]['type'])) {
7215
-            $this->message[$pos]['type'] = '';
7216
-        }
7217
-        $this->debug('in buildVal() for ' . $this->message[$pos]['name'] . "(pos $pos) of type " . $this->message[$pos]['type']);
7218
-        // if there are children...
7219
-        if ('' != $this->message[$pos]['children']) {
7220
-            $this->debug('in buildVal, there are children');
7221
-            $children = explode('|', $this->message[$pos]['children']);
7222
-            array_shift($children); // knock off empty
7223
-            // md array
7224
-            if (isset($this->message[$pos]['arrayCols']) && '' != $this->message[$pos]['arrayCols']) {
7225
-                $r = 0; // rowcount
7226
-                $c = 0; // colcount
7227
-                foreach ($children as $child_pos) {
7228
-                    $this->debug("in buildVal, got an MD array element: $r, $c");
7229
-                    $params[$r][] = $this->message[$child_pos]['result'];
7230
-                    $c++;
7231
-                    if ($c == $this->message[$pos]['arrayCols']) {
7232
-                        $c = 0;
7233
-                        $r++;
7234
-                    }
7235
-                }
7236
-                // array
7237
-            } elseif ('array' === $this->message[$pos]['type'] || 'Array' === $this->message[$pos]['type']) {
7238
-                $this->debug('in buildVal, adding array ' . $this->message[$pos]['name']);
7239
-                foreach ($children as $child_pos) {
7240
-                    $params[] = &$this->message[$child_pos]['result'];
7241
-                }
7242
-                // apache Map type: java hashtable
7243
-            } elseif ('Map' === $this->message[$pos]['type'] && 'http://xml.apache.org/xml-soap' === $this->message[$pos]['type_namespace']) {
7244
-                $this->debug('in buildVal, Java Map ' . $this->message[$pos]['name']);
7245
-                foreach ($children as $child_pos) {
7246
-                    $kv = explode('|', $this->message[$child_pos]['children']);
7247
-                    $params[$this->message[$kv[1]]['result']] = &$this->message[$kv[2]]['result'];
7248
-                }
7249
-                // generic compound type
7250
-                //} elseif($this->message[$pos]['type'] == 'SOAPStruct' || $this->message[$pos]['type'] == 'struct') {
7251
-            } else {
7252
-                // Apache Vector type: treat as an array
7253
-                $this->debug('in buildVal, adding Java Vector or generic compound type ' . $this->message[$pos]['name']);
7254
-                if ('Vector' === $this->message[$pos]['type'] && 'http://xml.apache.org/xml-soap' === $this->message[$pos]['type_namespace']) {
7255
-                    $notstruct = 1;
7256
-                } else {
7257
-                    $notstruct = 0;
7258
-                }
7259
-                //
7260
-                foreach ($children as $child_pos) {
7261
-                    if ($notstruct) {
7262
-                        $params[] = &$this->message[$child_pos]['result'];
7263
-                    } else {
7264
-                        if (isset($params[$this->message[$child_pos]['name']])) {
7265
-                            // de-serialize repeated element name into an array
7266
-                            if ((!is_array($params[$this->message[$child_pos]['name']])) || (!isset($params[$this->message[$child_pos]['name']][0]))) {
7267
-                                $params[$this->message[$child_pos]['name']] = [$params[$this->message[$child_pos]['name']]];
7268
-                            }
7269
-                            $params[$this->message[$child_pos]['name']][] = &$this->message[$child_pos]['result'];
7270
-                        } else {
7271
-                            $params[$this->message[$child_pos]['name']] = &$this->message[$child_pos]['result'];
7272
-                        }
7273
-                    }
7274
-                }
7275
-            }
7276
-            if (isset($this->message[$pos]['xattrs'])) {
7277
-                $this->debug('in buildVal, handling attributes');
7278
-                foreach ($this->message[$pos]['xattrs'] as $n => $v) {
7279
-                    $params[$n] = $v;
7280
-                }
7281
-            }
7282
-            // handle simpleContent
7283
-            if (isset($this->message[$pos]['cdata']) && '' != trim($this->message[$pos]['cdata'])) {
7284
-                $this->debug('in buildVal, handling simpleContent');
7285
-                if (isset($this->message[$pos]['type'])) {
7286
-                    $params['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
7287
-                } else {
7288
-                    $parent = $this->message[$pos]['parent'];
7289
-                    if (isset($this->message[$parent]['type']) && ('array' === $this->message[$parent]['type']) && isset($this->message[$parent]['arrayType'])) {
7290
-                        $params['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
7291
-                    } else {
7292
-                        $params['!'] = $this->message[$pos]['cdata'];
7293
-                    }
7294
-                }
7295
-            }
7296
-            $ret = is_array($params) ? $params : [];
7297
-            $this->debug('in buildVal, return:');
7298
-            $this->appendDebug($this->varDump($ret));
7299
-            return $ret;
7300
-        } else {
7301
-            $this->debug('in buildVal, no children, building scalar');
7302
-            $cdata = isset($this->message[$pos]['cdata']) ? $this->message[$pos]['cdata'] : '';
7303
-            if (isset($this->message[$pos]['type'])) {
7304
-                $ret = $this->decodeSimple($cdata, $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
7305
-                $this->debug("in buildVal, return: $ret");
7306
-                return $ret;
7307
-            }
7308
-            $parent = $this->message[$pos]['parent'];
7309
-            if (isset($this->message[$parent]['type']) && ('array' === $this->message[$parent]['type']) && isset($this->message[$parent]['arrayType'])) {
7310
-                $ret = $this->decodeSimple($cdata, $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
7311
-                $this->debug("in buildVal, return: $ret");
7312
-                return $ret;
7313
-            }
7314
-            $ret = $this->message[$pos]['cdata'];
7315
-            $this->debug("in buildVal, return: $ret");
7316
-            return $ret;
7317
-        }
7318
-    }
7055
+			}
7056
+		}
7057
+
7058
+		// for doclit
7059
+		if ('header' === $this->status) {
7060
+			if ($this->root_header != $pos) {
7061
+				$this->responseHeaders .= '</' . (isset($prefix) ? $prefix . ':' : '') . "$name>";
7062
+			}
7063
+		} elseif ($pos >= $this->root_struct) {
7064
+			$this->document .= '</' . (isset($prefix) ? $prefix . ':' : '') . "$name>";
7065
+		}
7066
+		// switch status
7067
+		if ($pos == $this->root_struct) {
7068
+			$this->status = 'body';
7069
+			$this->root_struct_namespace = $this->message[$pos]['namespace'];
7070
+		} elseif ($pos == $this->root_header) {
7071
+			$this->status = 'envelope';
7072
+		} elseif ('Body' === $name && 'body' === $this->status) {
7073
+			$this->status = 'envelope';
7074
+		} elseif ('Header' === $name && 'header' === $this->status) { // will never happen
7075
+			$this->status = 'envelope';
7076
+		} elseif ('Envelope' === $name && 'envelope' === $this->status) {
7077
+			$this->status = '';
7078
+		}
7079
+		// set parent back to my parent
7080
+		$this->parent = $this->message[$pos]['parent'];
7081
+	}
7082
+
7083
+	/**
7084
+	 * element content handler
7085
+	 *
7086
+	 * @param    resource $parser XML parser object
7087
+	 * @param    string $data element content
7088
+	 * @access   private
7089
+	 */
7090
+	private function character_data($parser, $data)
7091
+	{
7092
+		$pos = $this->depth_array[$this->depth];
7093
+		if ('UTF-8' === $this->xml_encoding) {
7094
+			// TODO: add an option to disable this for folks who want
7095
+			// raw UTF-8 that, e.g., might not map to iso-8859-1
7096
+			// TODO: this can also be handled with xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, "ISO-8859-1");
7097
+			if ($this->decode_utf8) {
7098
+				$data = utf8_decode($data);
7099
+			}
7100
+		}
7101
+		$this->message[$pos]['cdata'] .= $data;
7102
+		// for doclit
7103
+		if ('header' === $this->status) {
7104
+			$this->responseHeaders .= $data;
7105
+		} else {
7106
+			$this->document .= $data;
7107
+		}
7108
+	}
7109
+
7110
+	/**
7111
+	 * get the parsed message (SOAP Body)
7112
+	 *
7113
+	 * @return    mixed
7114
+	 * @access   public
7115
+	 * @deprecated    use get_soapbody instead
7116
+	 */
7117
+	public function get_response()
7118
+	{
7119
+		return $this->soapresponse;
7120
+	}
7121
+
7122
+	/**
7123
+	 * get the parsed SOAP Body (null if there was none)
7124
+	 *
7125
+	 * @return    mixed
7126
+	 * @access   public
7127
+	 */
7128
+	public function get_soapbody()
7129
+	{
7130
+		return $this->soapresponse;
7131
+	}
7132
+
7133
+	/**
7134
+	 * get the parsed SOAP Header (null if there was none)
7135
+	 *
7136
+	 * @return    mixed
7137
+	 * @access   public
7138
+	 */
7139
+	public function get_soapheader()
7140
+	{
7141
+		return $this->soapheader;
7142
+	}
7143
+
7144
+	/**
7145
+	 * get the unparsed SOAP Header
7146
+	 *
7147
+	 * @return    string XML or empty if no Header
7148
+	 * @access   public
7149
+	 */
7150
+	public function getHeaders()
7151
+	{
7152
+		return $this->responseHeaders;
7153
+	}
7154
+
7155
+	/**
7156
+	 * decodes simple types into PHP variables
7157
+	 *
7158
+	 * @param    string $value value to decode
7159
+	 * @param    string $type XML type to decode
7160
+	 * @param    string $typens XML type namespace to decode
7161
+	 * @return    mixed PHP value
7162
+	 * @access   private
7163
+	 */
7164
+	private function decodeSimple($value, $type, $typens)
7165
+	{
7166
+		// TODO: use the namespace!
7167
+		if ((!isset($type)) || 'string' === $type || 'long' === $type || 'unsignedLong' === $type) {
7168
+			return (string) $value;
7169
+		}
7170
+		if ('int' === $type || 'integer' === $type || 'short' === $type || 'byte' === $type) {
7171
+			return (int) $value;
7172
+		}
7173
+		if ('float' === $type || 'double' === $type || 'decimal' === $type) {
7174
+			return (double) $value;
7175
+		}
7176
+		if ('boolean' === $type) {
7177
+			if ('false' === strtolower($value) || 'f' === strtolower($value)) {
7178
+				return false;
7179
+			}
7180
+			return (boolean) $value;
7181
+		}
7182
+		if ('base64' === $type || 'base64Binary' === $type) {
7183
+			$this->debug('Decode base64 value');
7184
+			return base64_decode($value);
7185
+		}
7186
+		// obscure numeric types
7187
+		if ('nonPositiveInteger' === $type || 'negativeInteger' === $type
7188
+			|| 'nonNegativeInteger' === $type
7189
+			|| 'positiveInteger' === $type
7190
+			|| 'unsignedInt' === $type
7191
+			|| 'unsignedShort' === $type
7192
+			|| 'unsignedByte' === $type
7193
+		) {
7194
+			return (int) $value;
7195
+		}
7196
+		// bogus: parser treats array with no elements as a simple type
7197
+		if ('array' === $type) {
7198
+			return [];
7199
+		}
7200
+		// everything else
7201
+		return (string) $value;
7202
+	}
7203
+
7204
+	/**
7205
+	 * builds response structures for compound values (arrays/structs)
7206
+	 * and scalars
7207
+	 *
7208
+	 * @param    integer $pos position in node tree
7209
+	 * @return    mixed    PHP value
7210
+	 * @access   private
7211
+	 */
7212
+	private function buildVal($pos)
7213
+	{
7214
+		if (!isset($this->message[$pos]['type'])) {
7215
+			$this->message[$pos]['type'] = '';
7216
+		}
7217
+		$this->debug('in buildVal() for ' . $this->message[$pos]['name'] . "(pos $pos) of type " . $this->message[$pos]['type']);
7218
+		// if there are children...
7219
+		if ('' != $this->message[$pos]['children']) {
7220
+			$this->debug('in buildVal, there are children');
7221
+			$children = explode('|', $this->message[$pos]['children']);
7222
+			array_shift($children); // knock off empty
7223
+			// md array
7224
+			if (isset($this->message[$pos]['arrayCols']) && '' != $this->message[$pos]['arrayCols']) {
7225
+				$r = 0; // rowcount
7226
+				$c = 0; // colcount
7227
+				foreach ($children as $child_pos) {
7228
+					$this->debug("in buildVal, got an MD array element: $r, $c");
7229
+					$params[$r][] = $this->message[$child_pos]['result'];
7230
+					$c++;
7231
+					if ($c == $this->message[$pos]['arrayCols']) {
7232
+						$c = 0;
7233
+						$r++;
7234
+					}
7235
+				}
7236
+				// array
7237
+			} elseif ('array' === $this->message[$pos]['type'] || 'Array' === $this->message[$pos]['type']) {
7238
+				$this->debug('in buildVal, adding array ' . $this->message[$pos]['name']);
7239
+				foreach ($children as $child_pos) {
7240
+					$params[] = &$this->message[$child_pos]['result'];
7241
+				}
7242
+				// apache Map type: java hashtable
7243
+			} elseif ('Map' === $this->message[$pos]['type'] && 'http://xml.apache.org/xml-soap' === $this->message[$pos]['type_namespace']) {
7244
+				$this->debug('in buildVal, Java Map ' . $this->message[$pos]['name']);
7245
+				foreach ($children as $child_pos) {
7246
+					$kv = explode('|', $this->message[$child_pos]['children']);
7247
+					$params[$this->message[$kv[1]]['result']] = &$this->message[$kv[2]]['result'];
7248
+				}
7249
+				// generic compound type
7250
+				//} elseif($this->message[$pos]['type'] == 'SOAPStruct' || $this->message[$pos]['type'] == 'struct') {
7251
+			} else {
7252
+				// Apache Vector type: treat as an array
7253
+				$this->debug('in buildVal, adding Java Vector or generic compound type ' . $this->message[$pos]['name']);
7254
+				if ('Vector' === $this->message[$pos]['type'] && 'http://xml.apache.org/xml-soap' === $this->message[$pos]['type_namespace']) {
7255
+					$notstruct = 1;
7256
+				} else {
7257
+					$notstruct = 0;
7258
+				}
7259
+				//
7260
+				foreach ($children as $child_pos) {
7261
+					if ($notstruct) {
7262
+						$params[] = &$this->message[$child_pos]['result'];
7263
+					} else {
7264
+						if (isset($params[$this->message[$child_pos]['name']])) {
7265
+							// de-serialize repeated element name into an array
7266
+							if ((!is_array($params[$this->message[$child_pos]['name']])) || (!isset($params[$this->message[$child_pos]['name']][0]))) {
7267
+								$params[$this->message[$child_pos]['name']] = [$params[$this->message[$child_pos]['name']]];
7268
+							}
7269
+							$params[$this->message[$child_pos]['name']][] = &$this->message[$child_pos]['result'];
7270
+						} else {
7271
+							$params[$this->message[$child_pos]['name']] = &$this->message[$child_pos]['result'];
7272
+						}
7273
+					}
7274
+				}
7275
+			}
7276
+			if (isset($this->message[$pos]['xattrs'])) {
7277
+				$this->debug('in buildVal, handling attributes');
7278
+				foreach ($this->message[$pos]['xattrs'] as $n => $v) {
7279
+					$params[$n] = $v;
7280
+				}
7281
+			}
7282
+			// handle simpleContent
7283
+			if (isset($this->message[$pos]['cdata']) && '' != trim($this->message[$pos]['cdata'])) {
7284
+				$this->debug('in buildVal, handling simpleContent');
7285
+				if (isset($this->message[$pos]['type'])) {
7286
+					$params['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
7287
+				} else {
7288
+					$parent = $this->message[$pos]['parent'];
7289
+					if (isset($this->message[$parent]['type']) && ('array' === $this->message[$parent]['type']) && isset($this->message[$parent]['arrayType'])) {
7290
+						$params['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
7291
+					} else {
7292
+						$params['!'] = $this->message[$pos]['cdata'];
7293
+					}
7294
+				}
7295
+			}
7296
+			$ret = is_array($params) ? $params : [];
7297
+			$this->debug('in buildVal, return:');
7298
+			$this->appendDebug($this->varDump($ret));
7299
+			return $ret;
7300
+		} else {
7301
+			$this->debug('in buildVal, no children, building scalar');
7302
+			$cdata = isset($this->message[$pos]['cdata']) ? $this->message[$pos]['cdata'] : '';
7303
+			if (isset($this->message[$pos]['type'])) {
7304
+				$ret = $this->decodeSimple($cdata, $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
7305
+				$this->debug("in buildVal, return: $ret");
7306
+				return $ret;
7307
+			}
7308
+			$parent = $this->message[$pos]['parent'];
7309
+			if (isset($this->message[$parent]['type']) && ('array' === $this->message[$parent]['type']) && isset($this->message[$parent]['arrayType'])) {
7310
+				$ret = $this->decodeSimple($cdata, $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
7311
+				$this->debug("in buildVal, return: $ret");
7312
+				return $ret;
7313
+			}
7314
+			$ret = $this->message[$pos]['cdata'];
7315
+			$this->debug("in buildVal, return: $ret");
7316
+			return $ret;
7317
+		}
7318
+	}
7319 7319
 }
7320 7320
 
7321 7321
 
@@ -7349,1009 +7349,1009 @@  discard block
 block discarded – undo
7349 7349
  */
7350 7350
 class nusoap_client extends nusoap_base
7351 7351
 {
7352
-    public $username = '';                // Username for HTTP authentication
7353
-    public $password = '';                // Password for HTTP authentication
7354
-    public $authtype = '';                // Type of HTTP authentication
7355
-    public $certRequest = [];        // Certificate for HTTP SSL authentication
7356
-    public $requestHeaders = false;    // SOAP headers in request (text)
7357
-    public $responseHeaders = '';        // SOAP headers from response (incomplete namespace resolution) (text)
7358
-    public $responseHeader;        // SOAP Header from response (parsed)
7359
-    public $document = '';                // SOAP body response portion (incomplete namespace resolution) (text)
7360
-    public $endpoint;
7361
-    public $forceEndpoint = '';        // overrides WSDL endpoint
7362
-    public $proxyhost = '';
7363
-    public $proxyport = '';
7364
-    public $proxyusername = '';
7365
-    public $proxypassword = '';
7366
-    public $portName = '';                // port name to use in WSDL
7367
-    public $xml_encoding = '';            // character set encoding of incoming (response) messages
7368
-    public $http_encoding = false;
7369
-    public $timeout = 0;                // HTTP connection timeout
7370
-    public $response_timeout = 30;        // HTTP response timeout
7371
-    public $endpointType = '';            // soap|wsdl, empty for WSDL initialization error
7372
-    public $persistentConnection = false;
7373
-    public $defaultRpcParams = false;    // This is no longer used
7374
-    public $request = '';                // HTTP request
7375
-    public $response = '';                // HTTP response
7376
-    public $responseData = '';            // SOAP payload of response
7377
-    public $cookies = [];            // Cookies from response or for request
7378
-    public $decode_utf8 = true;        // toggles whether the parser decodes element content w/ utf8_decode()
7379
-    public $operations = [];        // WSDL operations, empty for WSDL initialization error
7380
-    public $curl_options = [];    // User-specified cURL options
7381
-    public $bindingType = '';            // WSDL operation binding type
7382
-    public $use_curl = false;            // whether to always try to use cURL
7383
-
7384
-    /*
7352
+	public $username = '';                // Username for HTTP authentication
7353
+	public $password = '';                // Password for HTTP authentication
7354
+	public $authtype = '';                // Type of HTTP authentication
7355
+	public $certRequest = [];        // Certificate for HTTP SSL authentication
7356
+	public $requestHeaders = false;    // SOAP headers in request (text)
7357
+	public $responseHeaders = '';        // SOAP headers from response (incomplete namespace resolution) (text)
7358
+	public $responseHeader;        // SOAP Header from response (parsed)
7359
+	public $document = '';                // SOAP body response portion (incomplete namespace resolution) (text)
7360
+	public $endpoint;
7361
+	public $forceEndpoint = '';        // overrides WSDL endpoint
7362
+	public $proxyhost = '';
7363
+	public $proxyport = '';
7364
+	public $proxyusername = '';
7365
+	public $proxypassword = '';
7366
+	public $portName = '';                // port name to use in WSDL
7367
+	public $xml_encoding = '';            // character set encoding of incoming (response) messages
7368
+	public $http_encoding = false;
7369
+	public $timeout = 0;                // HTTP connection timeout
7370
+	public $response_timeout = 30;        // HTTP response timeout
7371
+	public $endpointType = '';            // soap|wsdl, empty for WSDL initialization error
7372
+	public $persistentConnection = false;
7373
+	public $defaultRpcParams = false;    // This is no longer used
7374
+	public $request = '';                // HTTP request
7375
+	public $response = '';                // HTTP response
7376
+	public $responseData = '';            // SOAP payload of response
7377
+	public $cookies = [];            // Cookies from response or for request
7378
+	public $decode_utf8 = true;        // toggles whether the parser decodes element content w/ utf8_decode()
7379
+	public $operations = [];        // WSDL operations, empty for WSDL initialization error
7380
+	public $curl_options = [];    // User-specified cURL options
7381
+	public $bindingType = '';            // WSDL operation binding type
7382
+	public $use_curl = false;            // whether to always try to use cURL
7383
+
7384
+	/*
7385 7385
      * fault related variables
7386 7386
      */
7387
-    /**
7388
-     * @var  string|bool    $fault
7389
-     * @access   public
7390
-     */
7391
-    public $fault;
7392
-    /**
7393
-     * @var  string $faultcode
7394
-     * @access   public
7395
-     */
7396
-    public $faultcode;
7397
-    /**
7398
-     * @var string $faultstring
7399
-     * @access   public
7400
-     */
7401
-    public $faultstring;
7402
-    /**
7403
-     * @var string $faultdetail
7404
-     * @access   public
7405
-     */
7406
-    public $faultdetail;
7407
-
7408
-    /**
7409
-     * constructor
7410
-     *
7411
-     * @param    mixed   $endpoint         SOAP server or WSDL URL (string), or wsdl instance (object)
7412
-     * @param    mixed   $wsdl             optional, set to 'wsdl' or true if using WSDL
7413
-     * @param    bool|string $proxyhost optional
7414
-     * @param    bool|string $proxyport optional
7415
-     * @param    bool|string $proxyusername optional
7416
-     * @param    bool|string $proxypassword optional
7417
-     * @param    integer $timeout          set the connection timeout
7418
-     * @param    integer $response_timeout set the response timeout
7419
-     * @param    string  $portName         optional portName in WSDL document
7420
-     * @access   public
7421
-     */
7422
-    public function __construct($endpoint, $wsdl = false, $proxyhost = false, $proxyport = false, $proxyusername = false, $proxypassword = false, $timeout = 0, $response_timeout = 30, $portName = '')
7423
-    {
7424
-        parent::__construct();
7425
-        $this->endpoint = $endpoint;
7426
-        $this->proxyhost = $proxyhost;
7427
-        $this->proxyport = $proxyport;
7428
-        $this->proxyusername = $proxyusername;
7429
-        $this->proxypassword = $proxypassword;
7430
-        $this->timeout = $timeout;
7431
-        $this->response_timeout = $response_timeout;
7432
-        $this->portName = $portName;
7433
-
7434
-        $this->debug("ctor wsdl=$wsdl timeout=$timeout response_timeout=$response_timeout");
7435
-        $this->appendDebug('endpoint=' . $this->varDump($endpoint));
7436
-
7437
-        // make values
7438
-        if ($wsdl) {
7439
-            if (is_object($endpoint) && ('wsdl' === get_class($endpoint))) {
7440
-                $this->wsdl = $endpoint;
7441
-                $this->endpoint = $this->wsdl->wsdl;
7442
-                $this->wsdlFile = $this->endpoint;
7443
-                $this->debug('existing wsdl instance created from ' . $this->endpoint);
7444
-                $this->checkWSDL();
7445
-            } else {
7446
-                $this->wsdlFile = $this->endpoint;
7447
-                $this->wsdl = null;
7448
-                $this->debug('will use lazy evaluation of wsdl from ' . $this->endpoint);
7449
-            }
7450
-            $this->endpointType = 'wsdl';
7451
-        } else {
7452
-            $this->debug("instantiate SOAP with endpoint at $endpoint");
7453
-            $this->endpointType = 'soap';
7454
-        }
7455
-    }
7456
-
7457
-    /**
7458
-     * calls method, returns PHP native type
7459
-     *
7460
-     * @param    string $operation SOAP server URL or path
7461
-     * @param    mixed $params An array, associative or simple, of the parameters
7462
-     *                          for the method call, or a string that is the XML
7463
-     *                          for the call.  For rpc style, this call will
7464
-     *                          wrap the XML in a tag named after the method, as
7465
-     *                          well as the SOAP Envelope and Body.  For document
7466
-     *                          style, this will only wrap with the Envelope and Body.
7467
-     *                          IMPORTANT: when using an array with document style,
7468
-     *                          in which case there
7469
-     *                         is really one parameter, the root of the fragment
7470
-     *                         used in the call, which encloses what programmers
7471
-     *                         normally think of parameters.  A parameter array
7472
-     *                         *must* include the wrapper.
7473
-     * @param    string $namespace optional method namespace (WSDL can override)
7474
-     * @param    string $soapAction optional SOAPAction value (WSDL can override)
7475
-     * @param    mixed $headers optional string of XML with SOAP header content, or array of soapval objects for SOAP headers, or associative array
7476
-     * @param    boolean $rpcParams optional (no longer used)
7477
-     * @param    string $style optional (rpc|document) the style to use when serializing parameters (WSDL can override)
7478
-     * @param    string $use optional (encoded|literal) the use when serializing parameters (WSDL can override)
7479
-     * @return    mixed    response from SOAP call, normally an associative array mirroring the structure of the XML response, false for certain fatal errors
7480
-     * @access   public
7481
-     */
7482
-    public function call($operation, $params = [], $namespace = 'http://tempuri.org', $soapAction = '', $headers = false, $rpcParams = null, $style = 'rpc', $use = 'encoded')
7483
-    {
7484
-        $this->operation = $operation;
7485
-        $this->fault = false;
7486
-        $this->setError('');
7487
-        $this->request = '';
7488
-        $this->response = '';
7489
-        $this->responseData = '';
7490
-        $this->faultstring = '';
7491
-        $this->faultcode = '';
7492
-        $this->opData = [];
7493
-
7494
-        $this->debug("call: operation=$operation, namespace=$namespace, soapAction=$soapAction, rpcParams=$rpcParams, style=$style, use=$use, endpointType=$this->endpointType");
7495
-        $this->appendDebug('params=' . $this->varDump($params));
7496
-        $this->appendDebug('headers=' . $this->varDump($headers));
7497
-        if ($headers) {
7498
-            $this->requestHeaders = $headers;
7499
-        }
7500
-        if ('wsdl' === $this->endpointType && null === $this->wsdl) {
7501
-            $this->loadWSDL();
7502
-            if ($this->getError()) {
7503
-                return false;
7504
-            }
7505
-        }
7506
-        // serialize parameters
7507
-        if ('wsdl' === $this->endpointType && $opData = $this->getOperationData($operation)) {
7508
-            // use WSDL for operation
7509
-            $this->opData = $opData;
7510
-            $this->debug('found operation');
7511
-            $this->appendDebug('opData=' . $this->varDump($opData));
7512
-            if (isset($opData['soapAction'])) {
7513
-                $soapAction = $opData['soapAction'];
7514
-            }
7515
-            if (!$this->forceEndpoint) {
7516
-                $this->endpoint = $opData['endpoint'];
7517
-            } else {
7518
-                $this->endpoint = $this->forceEndpoint;
7519
-            }
7520
-            $namespace = isset($opData['input']['namespace']) ? $opData['input']['namespace'] : $namespace;
7521
-            $style = $opData['style'];
7522
-            $use = $opData['input']['use'];
7523
-            // add ns to ns array
7524
-            if ('' != $namespace && !isset($this->wsdl->namespaces[$namespace])) {
7525
-                $nsPrefix = 'ns' . mt_rand(1000, 9999);
7526
-                $this->wsdl->namespaces[$nsPrefix] = $namespace;
7527
-            }
7528
-            $nsPrefix = $this->wsdl->getPrefixFromNamespace($namespace);
7529
-            // serialize payload
7530
-            if (is_string($params)) {
7531
-                $this->debug("serializing param string for WSDL operation $operation");
7532
-                $payload = $params;
7533
-            } elseif (is_array($params)) {
7534
-                $this->debug("serializing param array for WSDL operation $operation");
7535
-                $payload = $this->wsdl->serializeRPCParameters($operation, 'input', $params, $this->bindingType);
7536
-            } else {
7537
-                $this->debug('params must be array or string');
7538
-                $this->setError('params must be array or string');
7539
-                return false;
7540
-            }
7541
-            $usedNamespaces = $this->wsdl->usedNamespaces;
7542
-            if (isset($opData['input']['encodingStyle'])) {
7543
-                $encodingStyle = $opData['input']['encodingStyle'];
7544
-            } else {
7545
-                $encodingStyle = '';
7546
-            }
7547
-            $this->appendDebug($this->wsdl->getDebug());
7548
-            $this->wsdl->clearDebug();
7549
-            if (false !== ($errstr = $this->wsdl->getError())) {
7550
-                $this->debug('got wsdl error: ' . $errstr);
7551
-                $this->setError('wsdl error: ' . $errstr);
7552
-                return false;
7553
-            }
7554
-        } elseif ('wsdl' === $this->endpointType) {
7555
-            // operation not in WSDL
7556
-            $this->appendDebug($this->wsdl->getDebug());
7557
-            $this->wsdl->clearDebug();
7558
-            $this->setError('operation ' . $operation . ' not present in WSDL.');
7559
-            $this->debug("operation '$operation' not present in WSDL.");
7560
-            return false;
7561
-        } else {
7562
-            // no WSDL
7563
-            //$this->namespaces['ns1'] = $namespace;
7564
-            $nsPrefix = 'ns' . mt_rand(1000, 9999);
7565
-            // serialize
7566
-            $payload = '';
7567
-            if (is_string($params)) {
7568
-                $this->debug("serializing param string for operation $operation");
7569
-                $payload = $params;
7570
-            } elseif (is_array($params)) {
7571
-                $this->debug("serializing param array for operation $operation");
7572
-                foreach ($params as $k => $v) {
7573
-                    $payload .= $this->serialize_val($v, $k, false, false, false, false, $use);
7574
-                }
7575
-            } else {
7576
-                $this->debug('params must be array or string');
7577
-                $this->setError('params must be array or string');
7578
-                return false;
7579
-            }
7580
-            $usedNamespaces = [];
7581
-            if ('encoded' === $use) {
7582
-                $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
7583
-            } else {
7584
-                $encodingStyle = '';
7585
-            }
7586
-        }
7587
-        // wrap RPC calls with method element
7588
-        if ('rpc' === $style) {
7589
-            if ('literal' === $use) {
7590
-                $this->debug('wrapping RPC request with literal method element');
7591
-                if ($namespace) {
7592
-                    // http://www.ws-i.org/Profiles/BasicProfile-1.1-2004-08-24.html R2735 says rpc/literal accessor elements should not be in a namespace
7593
-                    $payload = "<$nsPrefix:$operation xmlns:$nsPrefix=\"$namespace\">" .
7594
-                        $payload .
7595
-                        "</$nsPrefix:$operation>";
7596
-                } else {
7597
-                    $payload = "<$operation>" . $payload . "</$operation>";
7598
-                }
7599
-            } else {
7600
-                $this->debug('wrapping RPC request with encoded method element');
7601
-                if ($namespace) {
7602
-                    $payload = "<$nsPrefix:$operation xmlns:$nsPrefix=\"$namespace\">" .
7603
-                        $payload .
7604
-                        "</$nsPrefix:$operation>";
7605
-                } else {
7606
-                    $payload = "<$operation>" .
7607
-                        $payload .
7608
-                        "</$operation>";
7609
-                }
7610
-            }
7611
-        }
7612
-        // serialize envelope
7613
-        $soapmsg = $this->serializeEnvelope($payload, $this->requestHeaders, $usedNamespaces, $style, $use, $encodingStyle);
7614
-        $this->debug("endpoint=$this->endpoint, soapAction=$soapAction, namespace=$namespace, style=$style, use=$use, encodingStyle=$encodingStyle");
7615
-        $this->debug('SOAP message length=' . strlen($soapmsg) . ' contents (max 1000 bytes)=' . substr($soapmsg, 0, 1000));
7616
-        // send
7617
-        $return = $this->send($this->getHTTPBody($soapmsg), $soapAction, $this->timeout, $this->response_timeout);
7618
-        if (false !== ($errstr = $this->getError())) {
7619
-            $this->debug('Error: ' . $errstr);
7620
-            return false;
7621
-        } else {
7622
-            $this->return = $return;
7623
-            $this->debug('sent message successfully and got a(n) ' . gettype($return));
7624
-            $this->appendDebug('return=' . $this->varDump($return));
7625
-
7626
-            // fault?
7627
-            if (is_array($return) && isset($return['faultcode'])) {
7628
-                $this->debug('got fault');
7629
-                $this->setError($return['faultcode'] . ': ' . $return['faultstring']);
7630
-                $this->fault = true;
7631
-                foreach ($return as $k => $v) {
7632
-                    $this->$k = $v;
7633
-                    if (is_array($v)) {
7634
-                        $this->debug("$k = " . json_encode($v));
7635
-                    } else {
7636
-                        $this->debug("$k = $v<br>");
7637
-                    }
7638
-                }
7639
-                return $return;
7640
-            } elseif ('document' === $style) {
7641
-                // NOTE: if the response is defined to have multiple parts (i.e. unwrapped),
7642
-                // we are only going to return the first part here...sorry about that
7643
-                return $return;
7644
-            } else {
7645
-                // array of return values
7646
-                if (is_array($return)) {
7647
-                    // multiple 'out' parameters, which we return wrapped up
7648
-                    // in the array
7649
-                    if (is_array($return) && count($return) > 1) {
7650
-                        return $return;
7651
-                    }
7652
-                    // single 'out' parameter (normally the return value)
7653
-                    $return = array_shift($return);
7654
-                    $this->debug('return shifted value: ');
7655
-                    $this->appendDebug($this->varDump($return));
7656
-                    return $return;
7657
-                // nothing returned (ie, echoVoid)
7658
-                } else {
7659
-                    return '';
7660
-                }
7661
-            }
7662
-        }
7663
-    }
7664
-
7665
-    /**
7666
-     * check WSDL passed as an instance or pulled from an endpoint
7667
-     *
7668
-     * @access   private
7669
-     */
7670
-    private function checkWSDL()
7671
-    {
7672
-        $this->appendDebug($this->wsdl->getDebug());
7673
-        $this->wsdl->clearDebug();
7674
-        $this->debug('checkWSDL');
7675
-        // catch errors
7676
-        if (false !== ($errstr = $this->wsdl->getError())) {
7677
-            $this->appendDebug($this->wsdl->getDebug());
7678
-            $this->wsdl->clearDebug();
7679
-            $this->debug('got wsdl error: ' . $errstr);
7680
-            $this->setError('wsdl error: ' . $errstr);
7681
-        } elseif (false !== ($this->operations = $this->wsdl->getOperations($this->portName, 'soap'))) {
7682
-            $this->appendDebug($this->wsdl->getDebug());
7683
-            $this->wsdl->clearDebug();
7684
-            $this->bindingType = 'soap';
7685
-            $this->debug('got ' . count($this->operations) . ' operations from wsdl ' . $this->wsdlFile . ' for binding type ' . $this->bindingType);
7686
-        } elseif (false !== ($this->operations = $this->wsdl->getOperations($this->portName, 'soap12'))) {
7687
-            $this->appendDebug($this->wsdl->getDebug());
7688
-            $this->wsdl->clearDebug();
7689
-            $this->bindingType = 'soap12';
7690
-            $this->debug('got ' . count($this->operations) . ' operations from wsdl ' . $this->wsdlFile . ' for binding type ' . $this->bindingType);
7691
-            $this->debug('**************** WARNING: SOAP 1.2 BINDING *****************');
7692
-        } else {
7693
-            $this->appendDebug($this->wsdl->getDebug());
7694
-            $this->wsdl->clearDebug();
7695
-            $this->debug('getOperations returned false');
7696
-            $this->setError('no operations defined in the WSDL document!');
7697
-        }
7698
-    }
7699
-
7700
-    /**
7701
-     * instantiate wsdl object and parse wsdl file
7702
-     *
7703
-     * @access    public
7704
-     */
7705
-    public function loadWSDL()
7706
-    {
7707
-        $this->debug('instantiating wsdl class with doc: ' . $this->wsdlFile);
7708
-        $this->wsdl = new wsdl('', $this->proxyhost, $this->proxyport, $this->proxyusername, $this->proxypassword, $this->timeout, $this->response_timeout, $this->curl_options, $this->use_curl);
7709
-        $this->wsdl->setCredentials($this->username, $this->password, $this->authtype, $this->certRequest);
7710
-        $this->wsdl->fetchWSDL($this->wsdlFile);
7711
-        $this->checkWSDL();
7712
-    }
7713
-
7714
-    /**
7715
-     * get available data pertaining to an operation
7716
-     *
7717
-     * @param    string $operation operation name
7718
-     * @return   bool|array array of data pertaining to the operation
7719
-     * @access   public
7720
-     */
7721
-    public function getOperationData($operation)
7722
-    {
7723
-        if ('wsdl' === $this->endpointType && null === $this->wsdl) {
7724
-            $this->loadWSDL();
7725
-            if ($this->getError()) {
7726
-                return false;
7727
-            }
7728
-        }
7729
-        if (isset($this->operations[$operation])) {
7730
-            return $this->operations[$operation];
7731
-        }
7732
-        $this->debug("No data for operation: $operation");
7733
-    }
7734
-
7735
-    /**
7736
-     * send the SOAP message
7737
-     *
7738
-     * Note: if the operation has multiple return values
7739
-     * the return value of this method will be an array
7740
-     * of those values.
7741
-     *
7742
-     * @param    string $msg a SOAPx4 soapmsg object
7743
-     * @param    string $soapaction SOAPAction value
7744
-     * @param    integer $timeout set connection timeout in seconds
7745
-     * @param    integer $response_timeout set response timeout in seconds
7746
-     * @return    mixed native PHP types.
7747
-     * @access   private
7748
-     */
7749
-    private function send($msg, $soapaction = '', $timeout = 0, $response_timeout = 30)
7750
-    {
7751
-        $this->checkCookies();
7752
-        // detect transport
7753
-        switch (true) {
7754
-            // http(s)
7755
-            case preg_match('/^http/', $this->endpoint):
7756
-                $this->debug('transporting via HTTP');
7757
-                if (true == $this->persistentConnection && is_object($this->persistentConnection)) {
7758
-                    $http =& $this->persistentConnection;
7759
-                } else {
7760
-                    $http = new soap_transport_http($this->endpoint, $this->curl_options, $this->use_curl);
7761
-                    if ($this->persistentConnection) {
7762
-                        $http->usePersistentConnection();
7763
-                    }
7764
-                }
7765
-                $http->setContentType($this->getHTTPContentType(), $this->getHTTPContentTypeCharset());
7766
-                $http->setSOAPAction($soapaction);
7767
-                if ($this->proxyhost && $this->proxyport) {
7768
-                    $http->setProxy($this->proxyhost, $this->proxyport, $this->proxyusername, $this->proxypassword);
7769
-                }
7770
-                if ('' != $this->authtype) {
7771
-                    $http->setCredentials($this->username, $this->password, $this->authtype, [], $this->certRequest);
7772
-                }
7773
-                if ('' != $this->http_encoding) {
7774
-                    $http->setEncoding($this->http_encoding);
7775
-                }
7776
-                $this->debug('sending message, length=' . strlen($msg));
7777
-                if (preg_match('/^http:/', $this->endpoint)) {
7778
-                    //if(strpos($this->endpoint,'http:')){
7779
-                    $this->responseData = $http->send($msg, $timeout, $response_timeout, $this->cookies);
7780
-                } elseif (preg_match('/^https/', $this->endpoint)) {
7781
-                    //} elseif(strpos($this->endpoint,'https:')){
7782
-                    //if(phpversion() == '4.3.0-dev'){
7783
-                    //$response = $http->send($msg,$timeout,$response_timeout);
7784
-                    //$this->request = $http->outgoing_payload;
7785
-                    //$this->response = $http->incoming_payload;
7786
-                    //} else
7787
-                    $this->responseData = $http->sendHTTPS($msg, $timeout, $response_timeout, $this->cookies);
7788
-                } else {
7789
-                    $this->setError('no http/s in endpoint url');
7790
-                }
7791
-                $this->request = $http->outgoing_payload;
7792
-                $this->response = $http->incoming_payload;
7793
-                $this->appendDebug($http->getDebug());
7794
-                $this->UpdateCookies($http->incoming_cookies);
7795
-
7796
-                // save transport object if using persistent connections
7797
-                if ($this->persistentConnection) {
7798
-                    $http->clearDebug();
7799
-                    if (!is_object($this->persistentConnection)) {
7800
-                        $this->persistentConnection = $http;
7801
-                    }
7802
-                }
7387
+	/**
7388
+	 * @var  string|bool    $fault
7389
+	 * @access   public
7390
+	 */
7391
+	public $fault;
7392
+	/**
7393
+	 * @var  string $faultcode
7394
+	 * @access   public
7395
+	 */
7396
+	public $faultcode;
7397
+	/**
7398
+	 * @var string $faultstring
7399
+	 * @access   public
7400
+	 */
7401
+	public $faultstring;
7402
+	/**
7403
+	 * @var string $faultdetail
7404
+	 * @access   public
7405
+	 */
7406
+	public $faultdetail;
7407
+
7408
+	/**
7409
+	 * constructor
7410
+	 *
7411
+	 * @param    mixed   $endpoint         SOAP server or WSDL URL (string), or wsdl instance (object)
7412
+	 * @param    mixed   $wsdl             optional, set to 'wsdl' or true if using WSDL
7413
+	 * @param    bool|string $proxyhost optional
7414
+	 * @param    bool|string $proxyport optional
7415
+	 * @param    bool|string $proxyusername optional
7416
+	 * @param    bool|string $proxypassword optional
7417
+	 * @param    integer $timeout          set the connection timeout
7418
+	 * @param    integer $response_timeout set the response timeout
7419
+	 * @param    string  $portName         optional portName in WSDL document
7420
+	 * @access   public
7421
+	 */
7422
+	public function __construct($endpoint, $wsdl = false, $proxyhost = false, $proxyport = false, $proxyusername = false, $proxypassword = false, $timeout = 0, $response_timeout = 30, $portName = '')
7423
+	{
7424
+		parent::__construct();
7425
+		$this->endpoint = $endpoint;
7426
+		$this->proxyhost = $proxyhost;
7427
+		$this->proxyport = $proxyport;
7428
+		$this->proxyusername = $proxyusername;
7429
+		$this->proxypassword = $proxypassword;
7430
+		$this->timeout = $timeout;
7431
+		$this->response_timeout = $response_timeout;
7432
+		$this->portName = $portName;
7433
+
7434
+		$this->debug("ctor wsdl=$wsdl timeout=$timeout response_timeout=$response_timeout");
7435
+		$this->appendDebug('endpoint=' . $this->varDump($endpoint));
7436
+
7437
+		// make values
7438
+		if ($wsdl) {
7439
+			if (is_object($endpoint) && ('wsdl' === get_class($endpoint))) {
7440
+				$this->wsdl = $endpoint;
7441
+				$this->endpoint = $this->wsdl->wsdl;
7442
+				$this->wsdlFile = $this->endpoint;
7443
+				$this->debug('existing wsdl instance created from ' . $this->endpoint);
7444
+				$this->checkWSDL();
7445
+			} else {
7446
+				$this->wsdlFile = $this->endpoint;
7447
+				$this->wsdl = null;
7448
+				$this->debug('will use lazy evaluation of wsdl from ' . $this->endpoint);
7449
+			}
7450
+			$this->endpointType = 'wsdl';
7451
+		} else {
7452
+			$this->debug("instantiate SOAP with endpoint at $endpoint");
7453
+			$this->endpointType = 'soap';
7454
+		}
7455
+	}
7803 7456
 
7804
-                if (false !== ($err = $http->getError())) {
7805
-                    $this->setError('HTTP Error: ' . $err);
7806
-                    return false;
7807
-                } elseif ($this->getError()) {
7808
-                    return false;
7809
-                } else {
7810
-                    $this->debug('got response, length=' . strlen($this->responseData) . ' type=' . $http->incoming_headers['content-type']);
7811
-                    return $this->parseResponse($http->incoming_headers, $this->responseData);
7812
-                }
7813
-                break;
7814
-            default:
7815
-                $this->setError('no transport found, or selected transport is not yet supported!');
7816
-                return false;
7817
-                break;
7818
-        }
7819
-    }
7820
-
7821
-    /**
7822
-     * processes SOAP message returned from server
7823
-     *
7824
-     * @param    array $headers The HTTP headers
7825
-     * @param    string $data unprocessed response data from server
7826
-     * @return    mixed    value of the message, decoded into a PHP type
7827
-     * @access   private
7828
-     */
7829
-    private function parseResponse($headers, $data)
7830
-    {
7831
-        $this->debug('Entering parseResponse() for data of length ' . strlen($data) . ' headers:');
7832
-        $this->appendDebug($this->varDump($headers));
7833
-        if (!isset($headers['content-type'])) {
7834
-            $this->setError('Response not of type text/xml (no content-type header)');
7835
-            return false;
7836
-        }
7837
-        if (false === strpos($headers['content-type'], 'text/xml')) {
7838
-            $this->setError('Response not of type text/xml: ' . $headers['content-type']);
7839
-            return false;
7840
-        }
7841
-        if (strpos($headers['content-type'], '=')) {
7842
-            $enc = str_replace('"', '', substr(strstr($headers['content-type'], '='), 1));
7843
-            $this->debug('Got response encoding: ' . $enc);
7844
-            if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i', $enc)) {
7845
-                $this->xml_encoding = strtoupper($enc);
7846
-            } else {
7847
-                $this->xml_encoding = 'US-ASCII';
7848
-            }
7849
-        } else {
7850
-            // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
7851
-            $this->xml_encoding = 'ISO-8859-1';
7852
-        }
7853
-        $this->debug('Use encoding: ' . $this->xml_encoding . ' when creating nusoap_parser');
7854
-        $parser = new nusoap_parser($data, $this->xml_encoding, $this->operations, $this->decode_utf8);
7855
-        // add parser debug data to our debug
7856
-        $this->appendDebug($parser->getDebug());
7857
-        // if parse errors
7858
-        if (false !== ($errstr = $parser->getError())) {
7859
-            $this->setError($errstr);
7860
-            // destroy the parser object
7861
-            unset($parser);
7862
-            return false;
7863
-        } else {
7864
-            // get SOAP headers
7865
-            $this->responseHeaders = $parser->getHeaders();
7866
-            // get SOAP headers
7867
-            $this->responseHeader = $parser->get_soapheader();
7868
-            // get decoded message
7869
-            $return = $parser->get_soapbody();
7870
-            // add document for doclit support
7871
-            $this->document = $parser->document;
7872
-            // destroy the parser object
7873
-            unset($parser);
7874
-            // return decode message
7875
-            return $return;
7876
-        }
7877
-    }
7878
-
7879
-    /**
7880
-     * sets user-specified cURL options
7881
-     *
7882
-     * @param    mixed $option The cURL option (always integer?)
7883
-     * @param    mixed $value The cURL option value
7884
-     * @access   public
7885
-     */
7886
-    public function setCurlOption($option, $value)
7887
-    {
7888
-        $this->debug("setCurlOption option=$option, value=");
7889
-        $this->appendDebug($this->varDump($value));
7890
-        $this->curl_options[$option] = $value;
7891
-    }
7892
-
7893
-    /**
7894
-     * sets the SOAP endpoint, which can override WSDL
7895
-     *
7896
-     * @param    string $endpoint The endpoint URL to use, or empty string or false to prevent override
7897
-     * @access   public
7898
-     */
7899
-    public function setEndpoint($endpoint)
7900
-    {
7901
-        $this->debug("setEndpoint(\"$endpoint\")");
7902
-        $this->forceEndpoint = $endpoint;
7903
-    }
7904
-
7905
-    /**
7906
-     * set the SOAP headers
7907
-     *
7908
-     * @param    mixed $headers String of XML with SOAP header content, or array of soapval objects for SOAP headers
7909
-     * @access   public
7910
-     */
7911
-    public function setHeaders($headers)
7912
-    {
7913
-        $this->debug('setHeaders headers=');
7914
-        $this->appendDebug($this->varDump($headers));
7915
-        $this->requestHeaders = $headers;
7916
-    }
7917
-
7918
-    /**
7919
-     * get the SOAP response headers (namespace resolution incomplete)
7920
-     *
7921
-     * @return    string
7922
-     * @access   public
7923
-     */
7924
-    public function getHeaders()
7925
-    {
7926
-        return $this->responseHeaders;
7927
-    }
7928
-
7929
-    /**
7930
-     * get the SOAP response Header (parsed)
7931
-     *
7932
-     * @return    mixed
7933
-     * @access   public
7934
-     */
7935
-    public function getHeader()
7936
-    {
7937
-        return $this->responseHeader;
7938
-    }
7939
-
7940
-    /**
7941
-     * set proxy info here
7942
-     *
7943
-     * @param    string $proxyhost
7944
-     * @param    string $proxyport
7945
-     * @param    string $proxyusername
7946
-     * @param    string $proxypassword
7947
-     * @access   public
7948
-     */
7949
-    public function setHTTPProxy($proxyhost, $proxyport, $proxyusername = '', $proxypassword = '')
7950
-    {
7951
-        $this->proxyhost = $proxyhost;
7952
-        $this->proxyport = $proxyport;
7953
-        $this->proxyusername = $proxyusername;
7954
-        $this->proxypassword = $proxypassword;
7955
-    }
7956
-
7957
-    /**
7958
-     * if authenticating, set user credentials here
7959
-     *
7960
-     * @param    string $username
7961
-     * @param    string $password
7962
-     * @param    string $authtype (basic|digest|certificate|ntlm)
7963
-     * @param    array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs)
7964
-     * @access   public
7965
-     */
7966
-    public function setCredentials($username, $password, $authtype = 'basic', $certRequest = [])
7967
-    {
7968
-        $this->debug("setCredentials username=$username authtype=$authtype certRequest=");
7969
-        $this->appendDebug($this->varDump($certRequest));
7970
-        $this->username = $username;
7971
-        $this->password = $password;
7972
-        $this->authtype = $authtype;
7973
-        $this->certRequest = $certRequest;
7974
-    }
7975
-
7976
-    /**
7977
-     * use HTTP encoding
7978
-     *
7979
-     * @param    string $enc HTTP encoding
7980
-     * @access   public
7981
-     */
7982
-    public function setHTTPEncoding($enc = 'gzip, deflate')
7983
-    {
7984
-        $this->debug("setHTTPEncoding(\"$enc\")");
7985
-        $this->http_encoding = $enc;
7986
-    }
7987
-
7988
-    /**
7989
-     * Set whether to try to use cURL connections if possible
7990
-     *
7991
-     * @param    boolean $use Whether to try to use cURL
7992
-     * @access   public
7993
-     */
7994
-    public function setUseCURL($use)
7995
-    {
7996
-        $this->debug("setUseCURL($use)");
7997
-        $this->use_curl = $use;
7998
-    }
7999
-
8000
-    /**
8001
-     * use HTTP persistent connections if possible
8002
-     *
8003
-     * @access   public
8004
-     */
8005
-    public function useHTTPPersistentConnection()
8006
-    {
8007
-        $this->debug('useHTTPPersistentConnection');
8008
-        $this->persistentConnection = true;
8009
-    }
8010
-
8011
-    /**
8012
-     * gets the default RPC parameter setting.
8013
-     * If true, default is that call params are like RPC even for document style.
8014
-     * Each call() can override this value.
8015
-     *
8016
-     * This is no longer used.
8017
-     *
8018
-     * @return boolean
8019
-     * @access public
8020
-     * @deprecated
8021
-     */
8022
-    public function getDefaultRpcParams()
8023
-    {
8024
-        return $this->defaultRpcParams;
8025
-    }
8026
-
8027
-    /**
8028
-     * sets the default RPC parameter setting.
8029
-     * If true, default is that call params are like RPC even for document style
8030
-     * Each call() can override this value.
8031
-     *
8032
-     * This is no longer used.
8033
-     *
8034
-     * @param    boolean $rpcParams
8035
-     * @access public
8036
-     * @deprecated
8037
-     */
8038
-    public function setDefaultRpcParams($rpcParams)
8039
-    {
8040
-        $this->defaultRpcParams = $rpcParams;
8041
-    }
8042
-
8043
-    /**
8044
-     * dynamically creates an instance of a proxy class,
8045
-     * allowing user to directly call methods from wsdl
8046
-     *
8047
-     * @return   object soap_proxy object
8048
-     * @access   public
8049
-     */
8050
-    public function getProxy()
8051
-    {
8052
-        $r = mt_rand();
8053
-        $evalStr = $this->_getProxyClassCode($r);
8054
-        //$this->debug("proxy class: $evalStr");
8055
-        if ($this->getError()) {
8056
-            $this->debug('Error from _getProxyClassCode, so return null');
8057
-            return null;
8058
-        }
8059
-        // eval the class
8060
-        eval($evalStr);
8061
-        // instantiate proxy object
8062
-        eval("\$proxy = new nusoap_proxy_$r('');");
8063
-        // transfer current wsdl data to the proxy thereby avoiding parsing the wsdl twice
8064
-        $proxy->endpointType = 'wsdl';
8065
-        $proxy->wsdlFile = $this->wsdlFile;
8066
-        $proxy->wsdl = $this->wsdl;
8067
-        $proxy->operations = $this->operations;
8068
-        $proxy->defaultRpcParams = $this->defaultRpcParams;
8069
-        // transfer other state
8070
-        $proxy->soap_defencoding = $this->soap_defencoding;
8071
-        $proxy->username = $this->username;
8072
-        $proxy->password = $this->password;
8073
-        $proxy->authtype = $this->authtype;
8074
-        $proxy->certRequest = $this->certRequest;
8075
-        $proxy->requestHeaders = $this->requestHeaders;
8076
-        $proxy->endpoint = $this->endpoint;
8077
-        $proxy->forceEndpoint = $this->forceEndpoint;
8078
-        $proxy->proxyhost = $this->proxyhost;
8079
-        $proxy->proxyport = $this->proxyport;
8080
-        $proxy->proxyusername = $this->proxyusername;
8081
-        $proxy->proxypassword = $this->proxypassword;
8082
-        $proxy->http_encoding = $this->http_encoding;
8083
-        $proxy->timeout = $this->timeout;
8084
-        $proxy->response_timeout = $this->response_timeout;
8085
-        $proxy->persistentConnection = &$this->persistentConnection;
8086
-        $proxy->decode_utf8 = $this->decode_utf8;
8087
-        $proxy->curl_options = $this->curl_options;
8088
-        $proxy->bindingType = $this->bindingType;
8089
-        $proxy->use_curl = $this->use_curl;
8090
-        return $proxy;
8091
-    }
8092
-
8093
-    /**
8094
-     * dynamically creates proxy class code
8095
-     *
8096
-     * @param string $r
8097
-     * @return   string PHP/NuSOAP code for the proxy class
8098
-     * @access   private
8099
-     */
8100
-    private function _getProxyClassCode($r)
8101
-    {
8102
-        $this->debug("in getProxy endpointType=$this->endpointType");
8103
-        $this->appendDebug('wsdl=' . $this->varDump($this->wsdl));
8104
-        if ('wsdl' !== $this->endpointType) {
8105
-            $evalStr = 'A proxy can only be created for a WSDL client';
8106
-            $this->setError($evalStr);
8107
-            $evalStr = "echo \"$evalStr\";";
8108
-            return $evalStr;
8109
-        }
8110
-        if ('wsdl' === $this->endpointType && null === $this->wsdl) {
8111
-            $this->loadWSDL();
8112
-            if ($this->getError()) {
8113
-                return 'echo "' . $this->getError() . '";';
8114
-            }
8115
-        }
8116
-        $evalStr = '';
8117
-        foreach ($this->operations as $operation => $opData) {
8118
-            if ('' != $operation) {
8119
-                // create param string and param comment string
8120
-                if (is_array($opData['input']['parts']) && count($opData['input']['parts']) > 0) {
8121
-                    $paramStr = '';
8122
-                    $paramArrayStr = '';
8123
-                    $paramCommentStr = '';
8124
-                    foreach ($opData['input']['parts'] as $name => $type) {
8125
-                        $paramStr .= "\$$name, ";
8126
-                        $paramArrayStr .= "'$name' => \$$name, ";
8127
-                        $paramCommentStr .= "$type \$$name, ";
8128
-                    }
8129
-                    $paramStr = substr($paramStr, 0, -2);
8130
-                    $paramArrayStr = substr($paramArrayStr, 0, -2);
8131
-                    $paramCommentStr = substr($paramCommentStr, 0, -2);
8132
-                } else {
8133
-                    $paramStr = '';
8134
-                    $paramArrayStr = '';
8135
-                    $paramCommentStr = 'void';
8136
-                }
8137
-                $opData['namespace'] = !isset($opData['namespace']) ? 'http://testuri.com' : $opData['namespace'];
8138
-                $evalStr .= "// $paramCommentStr
7457
+	/**
7458
+	 * calls method, returns PHP native type
7459
+	 *
7460
+	 * @param    string $operation SOAP server URL or path
7461
+	 * @param    mixed $params An array, associative or simple, of the parameters
7462
+	 *                          for the method call, or a string that is the XML
7463
+	 *                          for the call.  For rpc style, this call will
7464
+	 *                          wrap the XML in a tag named after the method, as
7465
+	 *                          well as the SOAP Envelope and Body.  For document
7466
+	 *                          style, this will only wrap with the Envelope and Body.
7467
+	 *                          IMPORTANT: when using an array with document style,
7468
+	 *                          in which case there
7469
+	 *                         is really one parameter, the root of the fragment
7470
+	 *                         used in the call, which encloses what programmers
7471
+	 *                         normally think of parameters.  A parameter array
7472
+	 *                         *must* include the wrapper.
7473
+	 * @param    string $namespace optional method namespace (WSDL can override)
7474
+	 * @param    string $soapAction optional SOAPAction value (WSDL can override)
7475
+	 * @param    mixed $headers optional string of XML with SOAP header content, or array of soapval objects for SOAP headers, or associative array
7476
+	 * @param    boolean $rpcParams optional (no longer used)
7477
+	 * @param    string $style optional (rpc|document) the style to use when serializing parameters (WSDL can override)
7478
+	 * @param    string $use optional (encoded|literal) the use when serializing parameters (WSDL can override)
7479
+	 * @return    mixed    response from SOAP call, normally an associative array mirroring the structure of the XML response, false for certain fatal errors
7480
+	 * @access   public
7481
+	 */
7482
+	public function call($operation, $params = [], $namespace = 'http://tempuri.org', $soapAction = '', $headers = false, $rpcParams = null, $style = 'rpc', $use = 'encoded')
7483
+	{
7484
+		$this->operation = $operation;
7485
+		$this->fault = false;
7486
+		$this->setError('');
7487
+		$this->request = '';
7488
+		$this->response = '';
7489
+		$this->responseData = '';
7490
+		$this->faultstring = '';
7491
+		$this->faultcode = '';
7492
+		$this->opData = [];
7493
+
7494
+		$this->debug("call: operation=$operation, namespace=$namespace, soapAction=$soapAction, rpcParams=$rpcParams, style=$style, use=$use, endpointType=$this->endpointType");
7495
+		$this->appendDebug('params=' . $this->varDump($params));
7496
+		$this->appendDebug('headers=' . $this->varDump($headers));
7497
+		if ($headers) {
7498
+			$this->requestHeaders = $headers;
7499
+		}
7500
+		if ('wsdl' === $this->endpointType && null === $this->wsdl) {
7501
+			$this->loadWSDL();
7502
+			if ($this->getError()) {
7503
+				return false;
7504
+			}
7505
+		}
7506
+		// serialize parameters
7507
+		if ('wsdl' === $this->endpointType && $opData = $this->getOperationData($operation)) {
7508
+			// use WSDL for operation
7509
+			$this->opData = $opData;
7510
+			$this->debug('found operation');
7511
+			$this->appendDebug('opData=' . $this->varDump($opData));
7512
+			if (isset($opData['soapAction'])) {
7513
+				$soapAction = $opData['soapAction'];
7514
+			}
7515
+			if (!$this->forceEndpoint) {
7516
+				$this->endpoint = $opData['endpoint'];
7517
+			} else {
7518
+				$this->endpoint = $this->forceEndpoint;
7519
+			}
7520
+			$namespace = isset($opData['input']['namespace']) ? $opData['input']['namespace'] : $namespace;
7521
+			$style = $opData['style'];
7522
+			$use = $opData['input']['use'];
7523
+			// add ns to ns array
7524
+			if ('' != $namespace && !isset($this->wsdl->namespaces[$namespace])) {
7525
+				$nsPrefix = 'ns' . mt_rand(1000, 9999);
7526
+				$this->wsdl->namespaces[$nsPrefix] = $namespace;
7527
+			}
7528
+			$nsPrefix = $this->wsdl->getPrefixFromNamespace($namespace);
7529
+			// serialize payload
7530
+			if (is_string($params)) {
7531
+				$this->debug("serializing param string for WSDL operation $operation");
7532
+				$payload = $params;
7533
+			} elseif (is_array($params)) {
7534
+				$this->debug("serializing param array for WSDL operation $operation");
7535
+				$payload = $this->wsdl->serializeRPCParameters($operation, 'input', $params, $this->bindingType);
7536
+			} else {
7537
+				$this->debug('params must be array or string');
7538
+				$this->setError('params must be array or string');
7539
+				return false;
7540
+			}
7541
+			$usedNamespaces = $this->wsdl->usedNamespaces;
7542
+			if (isset($opData['input']['encodingStyle'])) {
7543
+				$encodingStyle = $opData['input']['encodingStyle'];
7544
+			} else {
7545
+				$encodingStyle = '';
7546
+			}
7547
+			$this->appendDebug($this->wsdl->getDebug());
7548
+			$this->wsdl->clearDebug();
7549
+			if (false !== ($errstr = $this->wsdl->getError())) {
7550
+				$this->debug('got wsdl error: ' . $errstr);
7551
+				$this->setError('wsdl error: ' . $errstr);
7552
+				return false;
7553
+			}
7554
+		} elseif ('wsdl' === $this->endpointType) {
7555
+			// operation not in WSDL
7556
+			$this->appendDebug($this->wsdl->getDebug());
7557
+			$this->wsdl->clearDebug();
7558
+			$this->setError('operation ' . $operation . ' not present in WSDL.');
7559
+			$this->debug("operation '$operation' not present in WSDL.");
7560
+			return false;
7561
+		} else {
7562
+			// no WSDL
7563
+			//$this->namespaces['ns1'] = $namespace;
7564
+			$nsPrefix = 'ns' . mt_rand(1000, 9999);
7565
+			// serialize
7566
+			$payload = '';
7567
+			if (is_string($params)) {
7568
+				$this->debug("serializing param string for operation $operation");
7569
+				$payload = $params;
7570
+			} elseif (is_array($params)) {
7571
+				$this->debug("serializing param array for operation $operation");
7572
+				foreach ($params as $k => $v) {
7573
+					$payload .= $this->serialize_val($v, $k, false, false, false, false, $use);
7574
+				}
7575
+			} else {
7576
+				$this->debug('params must be array or string');
7577
+				$this->setError('params must be array or string');
7578
+				return false;
7579
+			}
7580
+			$usedNamespaces = [];
7581
+			if ('encoded' === $use) {
7582
+				$encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
7583
+			} else {
7584
+				$encodingStyle = '';
7585
+			}
7586
+		}
7587
+		// wrap RPC calls with method element
7588
+		if ('rpc' === $style) {
7589
+			if ('literal' === $use) {
7590
+				$this->debug('wrapping RPC request with literal method element');
7591
+				if ($namespace) {
7592
+					// http://www.ws-i.org/Profiles/BasicProfile-1.1-2004-08-24.html R2735 says rpc/literal accessor elements should not be in a namespace
7593
+					$payload = "<$nsPrefix:$operation xmlns:$nsPrefix=\"$namespace\">" .
7594
+						$payload .
7595
+						"</$nsPrefix:$operation>";
7596
+				} else {
7597
+					$payload = "<$operation>" . $payload . "</$operation>";
7598
+				}
7599
+			} else {
7600
+				$this->debug('wrapping RPC request with encoded method element');
7601
+				if ($namespace) {
7602
+					$payload = "<$nsPrefix:$operation xmlns:$nsPrefix=\"$namespace\">" .
7603
+						$payload .
7604
+						"</$nsPrefix:$operation>";
7605
+				} else {
7606
+					$payload = "<$operation>" .
7607
+						$payload .
7608
+						"</$operation>";
7609
+				}
7610
+			}
7611
+		}
7612
+		// serialize envelope
7613
+		$soapmsg = $this->serializeEnvelope($payload, $this->requestHeaders, $usedNamespaces, $style, $use, $encodingStyle);
7614
+		$this->debug("endpoint=$this->endpoint, soapAction=$soapAction, namespace=$namespace, style=$style, use=$use, encodingStyle=$encodingStyle");
7615
+		$this->debug('SOAP message length=' . strlen($soapmsg) . ' contents (max 1000 bytes)=' . substr($soapmsg, 0, 1000));
7616
+		// send
7617
+		$return = $this->send($this->getHTTPBody($soapmsg), $soapAction, $this->timeout, $this->response_timeout);
7618
+		if (false !== ($errstr = $this->getError())) {
7619
+			$this->debug('Error: ' . $errstr);
7620
+			return false;
7621
+		} else {
7622
+			$this->return = $return;
7623
+			$this->debug('sent message successfully and got a(n) ' . gettype($return));
7624
+			$this->appendDebug('return=' . $this->varDump($return));
7625
+
7626
+			// fault?
7627
+			if (is_array($return) && isset($return['faultcode'])) {
7628
+				$this->debug('got fault');
7629
+				$this->setError($return['faultcode'] . ': ' . $return['faultstring']);
7630
+				$this->fault = true;
7631
+				foreach ($return as $k => $v) {
7632
+					$this->$k = $v;
7633
+					if (is_array($v)) {
7634
+						$this->debug("$k = " . json_encode($v));
7635
+					} else {
7636
+						$this->debug("$k = $v<br>");
7637
+					}
7638
+				}
7639
+				return $return;
7640
+			} elseif ('document' === $style) {
7641
+				// NOTE: if the response is defined to have multiple parts (i.e. unwrapped),
7642
+				// we are only going to return the first part here...sorry about that
7643
+				return $return;
7644
+			} else {
7645
+				// array of return values
7646
+				if (is_array($return)) {
7647
+					// multiple 'out' parameters, which we return wrapped up
7648
+					// in the array
7649
+					if (is_array($return) && count($return) > 1) {
7650
+						return $return;
7651
+					}
7652
+					// single 'out' parameter (normally the return value)
7653
+					$return = array_shift($return);
7654
+					$this->debug('return shifted value: ');
7655
+					$this->appendDebug($this->varDump($return));
7656
+					return $return;
7657
+				// nothing returned (ie, echoVoid)
7658
+				} else {
7659
+					return '';
7660
+				}
7661
+			}
7662
+		}
7663
+	}
7664
+
7665
+	/**
7666
+	 * check WSDL passed as an instance or pulled from an endpoint
7667
+	 *
7668
+	 * @access   private
7669
+	 */
7670
+	private function checkWSDL()
7671
+	{
7672
+		$this->appendDebug($this->wsdl->getDebug());
7673
+		$this->wsdl->clearDebug();
7674
+		$this->debug('checkWSDL');
7675
+		// catch errors
7676
+		if (false !== ($errstr = $this->wsdl->getError())) {
7677
+			$this->appendDebug($this->wsdl->getDebug());
7678
+			$this->wsdl->clearDebug();
7679
+			$this->debug('got wsdl error: ' . $errstr);
7680
+			$this->setError('wsdl error: ' . $errstr);
7681
+		} elseif (false !== ($this->operations = $this->wsdl->getOperations($this->portName, 'soap'))) {
7682
+			$this->appendDebug($this->wsdl->getDebug());
7683
+			$this->wsdl->clearDebug();
7684
+			$this->bindingType = 'soap';
7685
+			$this->debug('got ' . count($this->operations) . ' operations from wsdl ' . $this->wsdlFile . ' for binding type ' . $this->bindingType);
7686
+		} elseif (false !== ($this->operations = $this->wsdl->getOperations($this->portName, 'soap12'))) {
7687
+			$this->appendDebug($this->wsdl->getDebug());
7688
+			$this->wsdl->clearDebug();
7689
+			$this->bindingType = 'soap12';
7690
+			$this->debug('got ' . count($this->operations) . ' operations from wsdl ' . $this->wsdlFile . ' for binding type ' . $this->bindingType);
7691
+			$this->debug('**************** WARNING: SOAP 1.2 BINDING *****************');
7692
+		} else {
7693
+			$this->appendDebug($this->wsdl->getDebug());
7694
+			$this->wsdl->clearDebug();
7695
+			$this->debug('getOperations returned false');
7696
+			$this->setError('no operations defined in the WSDL document!');
7697
+		}
7698
+	}
7699
+
7700
+	/**
7701
+	 * instantiate wsdl object and parse wsdl file
7702
+	 *
7703
+	 * @access    public
7704
+	 */
7705
+	public function loadWSDL()
7706
+	{
7707
+		$this->debug('instantiating wsdl class with doc: ' . $this->wsdlFile);
7708
+		$this->wsdl = new wsdl('', $this->proxyhost, $this->proxyport, $this->proxyusername, $this->proxypassword, $this->timeout, $this->response_timeout, $this->curl_options, $this->use_curl);
7709
+		$this->wsdl->setCredentials($this->username, $this->password, $this->authtype, $this->certRequest);
7710
+		$this->wsdl->fetchWSDL($this->wsdlFile);
7711
+		$this->checkWSDL();
7712
+	}
7713
+
7714
+	/**
7715
+	 * get available data pertaining to an operation
7716
+	 *
7717
+	 * @param    string $operation operation name
7718
+	 * @return   bool|array array of data pertaining to the operation
7719
+	 * @access   public
7720
+	 */
7721
+	public function getOperationData($operation)
7722
+	{
7723
+		if ('wsdl' === $this->endpointType && null === $this->wsdl) {
7724
+			$this->loadWSDL();
7725
+			if ($this->getError()) {
7726
+				return false;
7727
+			}
7728
+		}
7729
+		if (isset($this->operations[$operation])) {
7730
+			return $this->operations[$operation];
7731
+		}
7732
+		$this->debug("No data for operation: $operation");
7733
+	}
7734
+
7735
+	/**
7736
+	 * send the SOAP message
7737
+	 *
7738
+	 * Note: if the operation has multiple return values
7739
+	 * the return value of this method will be an array
7740
+	 * of those values.
7741
+	 *
7742
+	 * @param    string $msg a SOAPx4 soapmsg object
7743
+	 * @param    string $soapaction SOAPAction value
7744
+	 * @param    integer $timeout set connection timeout in seconds
7745
+	 * @param    integer $response_timeout set response timeout in seconds
7746
+	 * @return    mixed native PHP types.
7747
+	 * @access   private
7748
+	 */
7749
+	private function send($msg, $soapaction = '', $timeout = 0, $response_timeout = 30)
7750
+	{
7751
+		$this->checkCookies();
7752
+		// detect transport
7753
+		switch (true) {
7754
+			// http(s)
7755
+			case preg_match('/^http/', $this->endpoint):
7756
+				$this->debug('transporting via HTTP');
7757
+				if (true == $this->persistentConnection && is_object($this->persistentConnection)) {
7758
+					$http =& $this->persistentConnection;
7759
+				} else {
7760
+					$http = new soap_transport_http($this->endpoint, $this->curl_options, $this->use_curl);
7761
+					if ($this->persistentConnection) {
7762
+						$http->usePersistentConnection();
7763
+					}
7764
+				}
7765
+				$http->setContentType($this->getHTTPContentType(), $this->getHTTPContentTypeCharset());
7766
+				$http->setSOAPAction($soapaction);
7767
+				if ($this->proxyhost && $this->proxyport) {
7768
+					$http->setProxy($this->proxyhost, $this->proxyport, $this->proxyusername, $this->proxypassword);
7769
+				}
7770
+				if ('' != $this->authtype) {
7771
+					$http->setCredentials($this->username, $this->password, $this->authtype, [], $this->certRequest);
7772
+				}
7773
+				if ('' != $this->http_encoding) {
7774
+					$http->setEncoding($this->http_encoding);
7775
+				}
7776
+				$this->debug('sending message, length=' . strlen($msg));
7777
+				if (preg_match('/^http:/', $this->endpoint)) {
7778
+					//if(strpos($this->endpoint,'http:')){
7779
+					$this->responseData = $http->send($msg, $timeout, $response_timeout, $this->cookies);
7780
+				} elseif (preg_match('/^https/', $this->endpoint)) {
7781
+					//} elseif(strpos($this->endpoint,'https:')){
7782
+					//if(phpversion() == '4.3.0-dev'){
7783
+					//$response = $http->send($msg,$timeout,$response_timeout);
7784
+					//$this->request = $http->outgoing_payload;
7785
+					//$this->response = $http->incoming_payload;
7786
+					//} else
7787
+					$this->responseData = $http->sendHTTPS($msg, $timeout, $response_timeout, $this->cookies);
7788
+				} else {
7789
+					$this->setError('no http/s in endpoint url');
7790
+				}
7791
+				$this->request = $http->outgoing_payload;
7792
+				$this->response = $http->incoming_payload;
7793
+				$this->appendDebug($http->getDebug());
7794
+				$this->UpdateCookies($http->incoming_cookies);
7795
+
7796
+				// save transport object if using persistent connections
7797
+				if ($this->persistentConnection) {
7798
+					$http->clearDebug();
7799
+					if (!is_object($this->persistentConnection)) {
7800
+						$this->persistentConnection = $http;
7801
+					}
7802
+				}
7803
+
7804
+				if (false !== ($err = $http->getError())) {
7805
+					$this->setError('HTTP Error: ' . $err);
7806
+					return false;
7807
+				} elseif ($this->getError()) {
7808
+					return false;
7809
+				} else {
7810
+					$this->debug('got response, length=' . strlen($this->responseData) . ' type=' . $http->incoming_headers['content-type']);
7811
+					return $this->parseResponse($http->incoming_headers, $this->responseData);
7812
+				}
7813
+				break;
7814
+			default:
7815
+				$this->setError('no transport found, or selected transport is not yet supported!');
7816
+				return false;
7817
+				break;
7818
+		}
7819
+	}
7820
+
7821
+	/**
7822
+	 * processes SOAP message returned from server
7823
+	 *
7824
+	 * @param    array $headers The HTTP headers
7825
+	 * @param    string $data unprocessed response data from server
7826
+	 * @return    mixed    value of the message, decoded into a PHP type
7827
+	 * @access   private
7828
+	 */
7829
+	private function parseResponse($headers, $data)
7830
+	{
7831
+		$this->debug('Entering parseResponse() for data of length ' . strlen($data) . ' headers:');
7832
+		$this->appendDebug($this->varDump($headers));
7833
+		if (!isset($headers['content-type'])) {
7834
+			$this->setError('Response not of type text/xml (no content-type header)');
7835
+			return false;
7836
+		}
7837
+		if (false === strpos($headers['content-type'], 'text/xml')) {
7838
+			$this->setError('Response not of type text/xml: ' . $headers['content-type']);
7839
+			return false;
7840
+		}
7841
+		if (strpos($headers['content-type'], '=')) {
7842
+			$enc = str_replace('"', '', substr(strstr($headers['content-type'], '='), 1));
7843
+			$this->debug('Got response encoding: ' . $enc);
7844
+			if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i', $enc)) {
7845
+				$this->xml_encoding = strtoupper($enc);
7846
+			} else {
7847
+				$this->xml_encoding = 'US-ASCII';
7848
+			}
7849
+		} else {
7850
+			// should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
7851
+			$this->xml_encoding = 'ISO-8859-1';
7852
+		}
7853
+		$this->debug('Use encoding: ' . $this->xml_encoding . ' when creating nusoap_parser');
7854
+		$parser = new nusoap_parser($data, $this->xml_encoding, $this->operations, $this->decode_utf8);
7855
+		// add parser debug data to our debug
7856
+		$this->appendDebug($parser->getDebug());
7857
+		// if parse errors
7858
+		if (false !== ($errstr = $parser->getError())) {
7859
+			$this->setError($errstr);
7860
+			// destroy the parser object
7861
+			unset($parser);
7862
+			return false;
7863
+		} else {
7864
+			// get SOAP headers
7865
+			$this->responseHeaders = $parser->getHeaders();
7866
+			// get SOAP headers
7867
+			$this->responseHeader = $parser->get_soapheader();
7868
+			// get decoded message
7869
+			$return = $parser->get_soapbody();
7870
+			// add document for doclit support
7871
+			$this->document = $parser->document;
7872
+			// destroy the parser object
7873
+			unset($parser);
7874
+			// return decode message
7875
+			return $return;
7876
+		}
7877
+	}
7878
+
7879
+	/**
7880
+	 * sets user-specified cURL options
7881
+	 *
7882
+	 * @param    mixed $option The cURL option (always integer?)
7883
+	 * @param    mixed $value The cURL option value
7884
+	 * @access   public
7885
+	 */
7886
+	public function setCurlOption($option, $value)
7887
+	{
7888
+		$this->debug("setCurlOption option=$option, value=");
7889
+		$this->appendDebug($this->varDump($value));
7890
+		$this->curl_options[$option] = $value;
7891
+	}
7892
+
7893
+	/**
7894
+	 * sets the SOAP endpoint, which can override WSDL
7895
+	 *
7896
+	 * @param    string $endpoint The endpoint URL to use, or empty string or false to prevent override
7897
+	 * @access   public
7898
+	 */
7899
+	public function setEndpoint($endpoint)
7900
+	{
7901
+		$this->debug("setEndpoint(\"$endpoint\")");
7902
+		$this->forceEndpoint = $endpoint;
7903
+	}
7904
+
7905
+	/**
7906
+	 * set the SOAP headers
7907
+	 *
7908
+	 * @param    mixed $headers String of XML with SOAP header content, or array of soapval objects for SOAP headers
7909
+	 * @access   public
7910
+	 */
7911
+	public function setHeaders($headers)
7912
+	{
7913
+		$this->debug('setHeaders headers=');
7914
+		$this->appendDebug($this->varDump($headers));
7915
+		$this->requestHeaders = $headers;
7916
+	}
7917
+
7918
+	/**
7919
+	 * get the SOAP response headers (namespace resolution incomplete)
7920
+	 *
7921
+	 * @return    string
7922
+	 * @access   public
7923
+	 */
7924
+	public function getHeaders()
7925
+	{
7926
+		return $this->responseHeaders;
7927
+	}
7928
+
7929
+	/**
7930
+	 * get the SOAP response Header (parsed)
7931
+	 *
7932
+	 * @return    mixed
7933
+	 * @access   public
7934
+	 */
7935
+	public function getHeader()
7936
+	{
7937
+		return $this->responseHeader;
7938
+	}
7939
+
7940
+	/**
7941
+	 * set proxy info here
7942
+	 *
7943
+	 * @param    string $proxyhost
7944
+	 * @param    string $proxyport
7945
+	 * @param    string $proxyusername
7946
+	 * @param    string $proxypassword
7947
+	 * @access   public
7948
+	 */
7949
+	public function setHTTPProxy($proxyhost, $proxyport, $proxyusername = '', $proxypassword = '')
7950
+	{
7951
+		$this->proxyhost = $proxyhost;
7952
+		$this->proxyport = $proxyport;
7953
+		$this->proxyusername = $proxyusername;
7954
+		$this->proxypassword = $proxypassword;
7955
+	}
7956
+
7957
+	/**
7958
+	 * if authenticating, set user credentials here
7959
+	 *
7960
+	 * @param    string $username
7961
+	 * @param    string $password
7962
+	 * @param    string $authtype (basic|digest|certificate|ntlm)
7963
+	 * @param    array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs)
7964
+	 * @access   public
7965
+	 */
7966
+	public function setCredentials($username, $password, $authtype = 'basic', $certRequest = [])
7967
+	{
7968
+		$this->debug("setCredentials username=$username authtype=$authtype certRequest=");
7969
+		$this->appendDebug($this->varDump($certRequest));
7970
+		$this->username = $username;
7971
+		$this->password = $password;
7972
+		$this->authtype = $authtype;
7973
+		$this->certRequest = $certRequest;
7974
+	}
7975
+
7976
+	/**
7977
+	 * use HTTP encoding
7978
+	 *
7979
+	 * @param    string $enc HTTP encoding
7980
+	 * @access   public
7981
+	 */
7982
+	public function setHTTPEncoding($enc = 'gzip, deflate')
7983
+	{
7984
+		$this->debug("setHTTPEncoding(\"$enc\")");
7985
+		$this->http_encoding = $enc;
7986
+	}
7987
+
7988
+	/**
7989
+	 * Set whether to try to use cURL connections if possible
7990
+	 *
7991
+	 * @param    boolean $use Whether to try to use cURL
7992
+	 * @access   public
7993
+	 */
7994
+	public function setUseCURL($use)
7995
+	{
7996
+		$this->debug("setUseCURL($use)");
7997
+		$this->use_curl = $use;
7998
+	}
7999
+
8000
+	/**
8001
+	 * use HTTP persistent connections if possible
8002
+	 *
8003
+	 * @access   public
8004
+	 */
8005
+	public function useHTTPPersistentConnection()
8006
+	{
8007
+		$this->debug('useHTTPPersistentConnection');
8008
+		$this->persistentConnection = true;
8009
+	}
8010
+
8011
+	/**
8012
+	 * gets the default RPC parameter setting.
8013
+	 * If true, default is that call params are like RPC even for document style.
8014
+	 * Each call() can override this value.
8015
+	 *
8016
+	 * This is no longer used.
8017
+	 *
8018
+	 * @return boolean
8019
+	 * @access public
8020
+	 * @deprecated
8021
+	 */
8022
+	public function getDefaultRpcParams()
8023
+	{
8024
+		return $this->defaultRpcParams;
8025
+	}
8026
+
8027
+	/**
8028
+	 * sets the default RPC parameter setting.
8029
+	 * If true, default is that call params are like RPC even for document style
8030
+	 * Each call() can override this value.
8031
+	 *
8032
+	 * This is no longer used.
8033
+	 *
8034
+	 * @param    boolean $rpcParams
8035
+	 * @access public
8036
+	 * @deprecated
8037
+	 */
8038
+	public function setDefaultRpcParams($rpcParams)
8039
+	{
8040
+		$this->defaultRpcParams = $rpcParams;
8041
+	}
8042
+
8043
+	/**
8044
+	 * dynamically creates an instance of a proxy class,
8045
+	 * allowing user to directly call methods from wsdl
8046
+	 *
8047
+	 * @return   object soap_proxy object
8048
+	 * @access   public
8049
+	 */
8050
+	public function getProxy()
8051
+	{
8052
+		$r = mt_rand();
8053
+		$evalStr = $this->_getProxyClassCode($r);
8054
+		//$this->debug("proxy class: $evalStr");
8055
+		if ($this->getError()) {
8056
+			$this->debug('Error from _getProxyClassCode, so return null');
8057
+			return null;
8058
+		}
8059
+		// eval the class
8060
+		eval($evalStr);
8061
+		// instantiate proxy object
8062
+		eval("\$proxy = new nusoap_proxy_$r('');");
8063
+		// transfer current wsdl data to the proxy thereby avoiding parsing the wsdl twice
8064
+		$proxy->endpointType = 'wsdl';
8065
+		$proxy->wsdlFile = $this->wsdlFile;
8066
+		$proxy->wsdl = $this->wsdl;
8067
+		$proxy->operations = $this->operations;
8068
+		$proxy->defaultRpcParams = $this->defaultRpcParams;
8069
+		// transfer other state
8070
+		$proxy->soap_defencoding = $this->soap_defencoding;
8071
+		$proxy->username = $this->username;
8072
+		$proxy->password = $this->password;
8073
+		$proxy->authtype = $this->authtype;
8074
+		$proxy->certRequest = $this->certRequest;
8075
+		$proxy->requestHeaders = $this->requestHeaders;
8076
+		$proxy->endpoint = $this->endpoint;
8077
+		$proxy->forceEndpoint = $this->forceEndpoint;
8078
+		$proxy->proxyhost = $this->proxyhost;
8079
+		$proxy->proxyport = $this->proxyport;
8080
+		$proxy->proxyusername = $this->proxyusername;
8081
+		$proxy->proxypassword = $this->proxypassword;
8082
+		$proxy->http_encoding = $this->http_encoding;
8083
+		$proxy->timeout = $this->timeout;
8084
+		$proxy->response_timeout = $this->response_timeout;
8085
+		$proxy->persistentConnection = &$this->persistentConnection;
8086
+		$proxy->decode_utf8 = $this->decode_utf8;
8087
+		$proxy->curl_options = $this->curl_options;
8088
+		$proxy->bindingType = $this->bindingType;
8089
+		$proxy->use_curl = $this->use_curl;
8090
+		return $proxy;
8091
+	}
8092
+
8093
+	/**
8094
+	 * dynamically creates proxy class code
8095
+	 *
8096
+	 * @param string $r
8097
+	 * @return   string PHP/NuSOAP code for the proxy class
8098
+	 * @access   private
8099
+	 */
8100
+	private function _getProxyClassCode($r)
8101
+	{
8102
+		$this->debug("in getProxy endpointType=$this->endpointType");
8103
+		$this->appendDebug('wsdl=' . $this->varDump($this->wsdl));
8104
+		if ('wsdl' !== $this->endpointType) {
8105
+			$evalStr = 'A proxy can only be created for a WSDL client';
8106
+			$this->setError($evalStr);
8107
+			$evalStr = "echo \"$evalStr\";";
8108
+			return $evalStr;
8109
+		}
8110
+		if ('wsdl' === $this->endpointType && null === $this->wsdl) {
8111
+			$this->loadWSDL();
8112
+			if ($this->getError()) {
8113
+				return 'echo "' . $this->getError() . '";';
8114
+			}
8115
+		}
8116
+		$evalStr = '';
8117
+		foreach ($this->operations as $operation => $opData) {
8118
+			if ('' != $operation) {
8119
+				// create param string and param comment string
8120
+				if (is_array($opData['input']['parts']) && count($opData['input']['parts']) > 0) {
8121
+					$paramStr = '';
8122
+					$paramArrayStr = '';
8123
+					$paramCommentStr = '';
8124
+					foreach ($opData['input']['parts'] as $name => $type) {
8125
+						$paramStr .= "\$$name, ";
8126
+						$paramArrayStr .= "'$name' => \$$name, ";
8127
+						$paramCommentStr .= "$type \$$name, ";
8128
+					}
8129
+					$paramStr = substr($paramStr, 0, -2);
8130
+					$paramArrayStr = substr($paramArrayStr, 0, -2);
8131
+					$paramCommentStr = substr($paramCommentStr, 0, -2);
8132
+				} else {
8133
+					$paramStr = '';
8134
+					$paramArrayStr = '';
8135
+					$paramCommentStr = 'void';
8136
+				}
8137
+				$opData['namespace'] = !isset($opData['namespace']) ? 'http://testuri.com' : $opData['namespace'];
8138
+				$evalStr .= "// $paramCommentStr
8139 8139
 	function " . str_replace('.', '__', $operation) . "($paramStr) {
8140 8140
 		\$params = array($paramArrayStr);
8141 8141
 		return \$this->call('$operation', \$params, '" . $opData['namespace'] . "', '" . (isset($opData['soapAction']) ? $opData['soapAction'] : '') . "');
8142 8142
 	}
8143 8143
 	";
8144
-                unset($paramStr);
8145
-                unset($paramCommentStr);
8146
-            }
8147
-        }
8148
-        $evalStr = 'class nusoap_proxy_' . $r . ' extends nusoap_client {
8144
+				unset($paramStr);
8145
+				unset($paramCommentStr);
8146
+			}
8147
+		}
8148
+		$evalStr = 'class nusoap_proxy_' . $r . ' extends nusoap_client {
8149 8149
 	' . $evalStr . '
8150 8150
 }';
8151
-        return $evalStr;
8152
-    }
8153
-
8154
-    /**
8155
-     * dynamically creates proxy class code
8156
-     *
8157
-     * @return   string PHP/NuSOAP code for the proxy class
8158
-     * @access   public
8159
-     */
8160
-    public function getProxyClassCode()
8161
-    {
8162
-        $r = mt_rand();
8163
-        return $this->_getProxyClassCode($r);
8164
-    }
8165
-
8166
-    /**
8167
-     * gets the HTTP body for the current request.
8168
-     *
8169
-     * @param string $soapmsg The SOAP payload
8170
-     * @return string The HTTP body, which includes the SOAP payload
8171
-     * @access private
8172
-     */
8173
-    private function getHTTPBody($soapmsg)
8174
-    {
8175
-        return $soapmsg;
8176
-    }
8177
-
8178
-    /**
8179
-     * gets the HTTP content type for the current request.
8180
-     *
8181
-     * Note: getHTTPBody must be called before this.
8182
-     *
8183
-     * @return string the HTTP content type for the current request.
8184
-     * @access private
8185
-     */
8186
-    private function getHTTPContentType()
8187
-    {
8188
-        return 'text/xml';
8189
-    }
8190
-
8191
-    /**
8192
-     * gets the HTTP content type charset for the current request.
8193
-     * returns false for non-text content types.
8194
-     *
8195
-     * Note: getHTTPBody must be called before this.
8196
-     *
8197
-     * @return string the HTTP content type charset for the current request.
8198
-     * @access private
8199
-     */
8200
-    private function getHTTPContentTypeCharset()
8201
-    {
8202
-        return $this->soap_defencoding;
8203
-    }
8151
+		return $evalStr;
8152
+	}
8153
+
8154
+	/**
8155
+	 * dynamically creates proxy class code
8156
+	 *
8157
+	 * @return   string PHP/NuSOAP code for the proxy class
8158
+	 * @access   public
8159
+	 */
8160
+	public function getProxyClassCode()
8161
+	{
8162
+		$r = mt_rand();
8163
+		return $this->_getProxyClassCode($r);
8164
+	}
8165
+
8166
+	/**
8167
+	 * gets the HTTP body for the current request.
8168
+	 *
8169
+	 * @param string $soapmsg The SOAP payload
8170
+	 * @return string The HTTP body, which includes the SOAP payload
8171
+	 * @access private
8172
+	 */
8173
+	private function getHTTPBody($soapmsg)
8174
+	{
8175
+		return $soapmsg;
8176
+	}
8204 8177
 
8205
-    /*
8178
+	/**
8179
+	 * gets the HTTP content type for the current request.
8180
+	 *
8181
+	 * Note: getHTTPBody must be called before this.
8182
+	 *
8183
+	 * @return string the HTTP content type for the current request.
8184
+	 * @access private
8185
+	 */
8186
+	private function getHTTPContentType()
8187
+	{
8188
+		return 'text/xml';
8189
+	}
8190
+
8191
+	/**
8192
+	 * gets the HTTP content type charset for the current request.
8193
+	 * returns false for non-text content types.
8194
+	 *
8195
+	 * Note: getHTTPBody must be called before this.
8196
+	 *
8197
+	 * @return string the HTTP content type charset for the current request.
8198
+	 * @access private
8199
+	 */
8200
+	private function getHTTPContentTypeCharset()
8201
+	{
8202
+		return $this->soap_defencoding;
8203
+	}
8204
+
8205
+	/*
8206 8206
     * whether or not parser should decode utf8 element content
8207 8207
     *
8208 8208
     * @return   always returns true
8209 8209
     * @access   public
8210 8210
     */
8211
-    /**
8212
-     * @param $bool
8213
-     * @return bool
8214
-     */
8215
-    public function decodeUTF8($bool)
8216
-    {
8217
-        $this->decode_utf8 = $bool;
8218
-        return true;
8219
-    }
8220
-
8221
-    /**
8222
-     * adds a new Cookie into $this->cookies array
8223
-     *
8224
-     * @param    string $name Cookie Name
8225
-     * @param    string $value Cookie Value
8226
-     * @return    boolean if cookie-set was successful returns true, else false
8227
-     * @access    public
8228
-     */
8229
-    public function setCookie($name, $value)
8230
-    {
8231
-        if (0 == strlen($name)) {
8232
-            return false;
8233
-        }
8234
-        $this->cookies[] = ['name' => $name, 'value' => $value];
8235
-        return true;
8236
-    }
8237
-
8238
-    /**
8239
-     * gets all Cookies
8240
-     *
8241
-     * @return   array with all internal cookies
8242
-     * @access   public
8243
-     */
8244
-    public function getCookies()
8245
-    {
8246
-        return $this->cookies;
8247
-    }
8248
-
8249
-    /**
8250
-     * checks all Cookies and delete those which are expired
8251
-     *
8252
-     * @return   boolean always return true
8253
-     * @access   private
8254
-     */
8255
-    private function checkCookies()
8256
-    {
8257
-        if (0 == count($this->cookies)) {
8258
-            return true;
8259
-        }
8260
-        $this->debug('checkCookie: check ' . count($this->cookies) . ' cookies');
8261
-        $curr_cookies = $this->cookies;
8262
-        $this->cookies = [];
8263
-        foreach ($curr_cookies as $cookie) {
8264
-            if (!is_array($cookie)) {
8265
-                $this->debug('Remove cookie that is not an array');
8266
-                continue;
8267
-            }
8268
-            if ((isset($cookie['expires'])) && (!empty($cookie['expires']))) {
8269
-                if (strtotime($cookie['expires']) > time()) {
8270
-                    $this->cookies[] = $cookie;
8271
-                } else {
8272
-                    $this->debug('Remove expired cookie ' . $cookie['name']);
8273
-                }
8274
-            } else {
8275
-                $this->cookies[] = $cookie;
8276
-            }
8277
-        }
8278
-        $this->debug('checkCookie: ' . count($this->cookies) . ' cookies left in array');
8279
-        return true;
8280
-    }
8281
-
8282
-    /**
8283
-     * updates the current cookies with a new set
8284
-     *
8285
-     * @param    array $cookies new cookies with which to update current ones
8286
-     * @return    boolean always return true
8287
-     * @access    private
8288
-     */
8289
-    private function UpdateCookies($cookies)
8290
-    {
8291
-        if (0 == count($this->cookies)) {
8292
-            // no existing cookies: take whatever is new
8293
-            if (is_array($cookies) && count($cookies) > 0) {
8294
-                $this->debug('Setting new cookie(s)');
8295
-                $this->cookies = $cookies;
8296
-            }
8297
-            return true;
8298
-        }
8299
-        if (0 == count($cookies)) {
8300
-            // no new cookies: keep what we've got
8301
-            return true;
8302
-        }
8303
-        // merge
8304
-        foreach ($cookies as $newCookie) {
8305
-            if (!is_array($newCookie)) {
8306
-                continue;
8307
-            }
8308
-            if ((!isset($newCookie['name'])) || (!isset($newCookie['value']))) {
8309
-                continue;
8310
-            }
8311
-            $newName = $newCookie['name'];
8312
-
8313
-            $found = false;
8314
-            for ($i = 0, $iMax = count($this->cookies); $i < $iMax; $i++) {
8315
-                $cookie = $this->cookies[$i];
8316
-                if (!is_array($cookie)) {
8317
-                    continue;
8318
-                }
8319
-                if (!isset($cookie['name'])) {
8320
-                    continue;
8321
-                }
8322
-                if ($newName != $cookie['name']) {
8323
-                    continue;
8324
-                }
8325
-                $newDomain = isset($newCookie['domain']) ? $newCookie['domain'] : 'NODOMAIN';
8326
-                $domain = isset($cookie['domain']) ? $cookie['domain'] : 'NODOMAIN';
8327
-                if ($newDomain != $domain) {
8328
-                    continue;
8329
-                }
8330
-                $newPath = isset($newCookie['path']) ? $newCookie['path'] : 'NOPATH';
8331
-                $path = isset($cookie['path']) ? $cookie['path'] : 'NOPATH';
8332
-                if ($newPath != $path) {
8333
-                    continue;
8334
-                }
8335
-                $this->cookies[$i] = $newCookie;
8336
-                $found = true;
8337
-                $this->debug('Update cookie ' . $newName . '=' . $newCookie['value']);
8338
-                break;
8339
-            }
8340
-            if (!$found) {
8341
-                $this->debug('Add cookie ' . $newName . '=' . $newCookie['value']);
8342
-                $this->cookies[] = $newCookie;
8343
-            }
8344
-        }
8345
-        return true;
8346
-    }
8211
+	/**
8212
+	 * @param $bool
8213
+	 * @return bool
8214
+	 */
8215
+	public function decodeUTF8($bool)
8216
+	{
8217
+		$this->decode_utf8 = $bool;
8218
+		return true;
8219
+	}
8220
+
8221
+	/**
8222
+	 * adds a new Cookie into $this->cookies array
8223
+	 *
8224
+	 * @param    string $name Cookie Name
8225
+	 * @param    string $value Cookie Value
8226
+	 * @return    boolean if cookie-set was successful returns true, else false
8227
+	 * @access    public
8228
+	 */
8229
+	public function setCookie($name, $value)
8230
+	{
8231
+		if (0 == strlen($name)) {
8232
+			return false;
8233
+		}
8234
+		$this->cookies[] = ['name' => $name, 'value' => $value];
8235
+		return true;
8236
+	}
8237
+
8238
+	/**
8239
+	 * gets all Cookies
8240
+	 *
8241
+	 * @return   array with all internal cookies
8242
+	 * @access   public
8243
+	 */
8244
+	public function getCookies()
8245
+	{
8246
+		return $this->cookies;
8247
+	}
8248
+
8249
+	/**
8250
+	 * checks all Cookies and delete those which are expired
8251
+	 *
8252
+	 * @return   boolean always return true
8253
+	 * @access   private
8254
+	 */
8255
+	private function checkCookies()
8256
+	{
8257
+		if (0 == count($this->cookies)) {
8258
+			return true;
8259
+		}
8260
+		$this->debug('checkCookie: check ' . count($this->cookies) . ' cookies');
8261
+		$curr_cookies = $this->cookies;
8262
+		$this->cookies = [];
8263
+		foreach ($curr_cookies as $cookie) {
8264
+			if (!is_array($cookie)) {
8265
+				$this->debug('Remove cookie that is not an array');
8266
+				continue;
8267
+			}
8268
+			if ((isset($cookie['expires'])) && (!empty($cookie['expires']))) {
8269
+				if (strtotime($cookie['expires']) > time()) {
8270
+					$this->cookies[] = $cookie;
8271
+				} else {
8272
+					$this->debug('Remove expired cookie ' . $cookie['name']);
8273
+				}
8274
+			} else {
8275
+				$this->cookies[] = $cookie;
8276
+			}
8277
+		}
8278
+		$this->debug('checkCookie: ' . count($this->cookies) . ' cookies left in array');
8279
+		return true;
8280
+	}
8281
+
8282
+	/**
8283
+	 * updates the current cookies with a new set
8284
+	 *
8285
+	 * @param    array $cookies new cookies with which to update current ones
8286
+	 * @return    boolean always return true
8287
+	 * @access    private
8288
+	 */
8289
+	private function UpdateCookies($cookies)
8290
+	{
8291
+		if (0 == count($this->cookies)) {
8292
+			// no existing cookies: take whatever is new
8293
+			if (is_array($cookies) && count($cookies) > 0) {
8294
+				$this->debug('Setting new cookie(s)');
8295
+				$this->cookies = $cookies;
8296
+			}
8297
+			return true;
8298
+		}
8299
+		if (0 == count($cookies)) {
8300
+			// no new cookies: keep what we've got
8301
+			return true;
8302
+		}
8303
+		// merge
8304
+		foreach ($cookies as $newCookie) {
8305
+			if (!is_array($newCookie)) {
8306
+				continue;
8307
+			}
8308
+			if ((!isset($newCookie['name'])) || (!isset($newCookie['value']))) {
8309
+				continue;
8310
+			}
8311
+			$newName = $newCookie['name'];
8312
+
8313
+			$found = false;
8314
+			for ($i = 0, $iMax = count($this->cookies); $i < $iMax; $i++) {
8315
+				$cookie = $this->cookies[$i];
8316
+				if (!is_array($cookie)) {
8317
+					continue;
8318
+				}
8319
+				if (!isset($cookie['name'])) {
8320
+					continue;
8321
+				}
8322
+				if ($newName != $cookie['name']) {
8323
+					continue;
8324
+				}
8325
+				$newDomain = isset($newCookie['domain']) ? $newCookie['domain'] : 'NODOMAIN';
8326
+				$domain = isset($cookie['domain']) ? $cookie['domain'] : 'NODOMAIN';
8327
+				if ($newDomain != $domain) {
8328
+					continue;
8329
+				}
8330
+				$newPath = isset($newCookie['path']) ? $newCookie['path'] : 'NOPATH';
8331
+				$path = isset($cookie['path']) ? $cookie['path'] : 'NOPATH';
8332
+				if ($newPath != $path) {
8333
+					continue;
8334
+				}
8335
+				$this->cookies[$i] = $newCookie;
8336
+				$found = true;
8337
+				$this->debug('Update cookie ' . $newName . '=' . $newCookie['value']);
8338
+				break;
8339
+			}
8340
+			if (!$found) {
8341
+				$this->debug('Add cookie ' . $newName . '=' . $newCookie['value']);
8342
+				$this->cookies[] = $newCookie;
8343
+			}
8344
+		}
8345
+		return true;
8346
+	}
8347 8347
 }
8348 8348
 
8349 8349
 
8350 8350
 if (!extension_loaded('soap')) {
8351
-    /**
8352
-     *    For backwards compatiblity, define soapclient unless the PHP SOAP extension is loaded.
8353
-     */
8354
-    class soapclient extends nusoap_client
8355
-    {
8356
-    }
8351
+	/**
8352
+	 *    For backwards compatiblity, define soapclient unless the PHP SOAP extension is loaded.
8353
+	 */
8354
+	class soapclient extends nusoap_client
8355
+	{
8356
+	}
8357 8357
 }
Please login to merge, or discard this patch.