This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Server.php
1348 lines (1246 loc) · 45.7 KB
/
Server.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
====================================================================
Original EULA
====================================================================
NuSOAP - Web Services Toolkit for PHP
Copyright (c) 2002 NuSphere Corporation
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
The NuSOAP project home is:
http://sourceforge.net/projects/nusoap/
The primary support for NuSOAP is the Help forum on the project home page.
If you have any questions or comments, please email:
Dietrich Ayala
http://dietrich.ganx4.com/nusoap
NuSphere Corporation
http://www.nusphere.com
*/
/*
* Some of the standards implmented in whole or part by NuSOAP:
*
* SOAP 1.1 (http://www.w3.org/TR/2000/NOTE-SOAP-20000508/)
* WSDL 1.1 (http://www.w3.org/TR/2001/NOTE-wsdl-20010315)
* SOAP Messages With Attachments (http://www.w3.org/TR/SOAP-attachments)
* XML 1.0 (http://www.w3.org/TR/2006/REC-xml-20060816/)
* Namespaces in XML 1.0 (http://www.w3.org/TR/2006/REC-xml-names-20060816/)
* XML Schema 1.0 (http://www.w3.org/TR/xmlschema-0/)
* RFC 2045 Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies
* RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1
* RFC 2617 HTTP Authentication: Basic and Digest Access Authentication
*/
/**
* =======================================================================
* PHP 5 Rewrite
* =======================================================================
*
* @author Daniel Carbone ([email protected])
* @version 1.0
* @link https://github.com/dcarbone
*
* This rewrite is intended to bring the NuSOAP library up to more modern PHP
* standards, including the removal of the use of $GLOBALS and same-name
* class constructors.
*
* It also implements Namespacing to keep things clean
*
* For now additional functionality is not the focus, this is a
* modernization effort only.
*
*/
namespace NuSOAP;
/**
*
* nusoap_server allows the user to create a SOAP server
* that is capable of receiving messages and returning responses
*
* @author Dietrich Ayala <[email protected]>
* @author Scott Nichol <[email protected]>
* @author Daniel Carbone <[email protected]>
* @access public
*/
class Server extends Base
{
/**
* HTTP headers of request
* @var array
* @access protected
*/
protected $headers = array();
/**
* HTTP request
* @var string
* @access protected
*/
protected $request = '';
/**
* SOAP headers from request (incomplete namespace resolution; special characters not escaped) (text)
* @var string
* @access public
*/
public $requestHeaders = '';
/**
* SOAP Headers from request (parsed)
* @var mixed
* @access public
*/
public $requestHeader = NULL;
/**
* SOAP body request portion (incomplete namespace resolution; special characters not escaped) (text)
* @var string
* @access public
*/
public $document = '';
/**
* SOAP payload for request (text)
* @var string
* @access public
*/
public $requestSOAP = '';
/**
* requested method namespace URI
* @var string
* @access protected
*/
protected $methodURI = '';
/**
* name of method requested
* @var string
* @access protected
*/
protected $methodName = '';
/**
* method parameters from request
* @var array
* @access protected
*/
protected $methodParams = array();
/**
* SOAP Action from request
* @var string
* @access protected
*/
protected $SOAPAction = '';
/**
* character set encoding of incoming (request) messages
* @var string
* @access public
*/
public $xmlEncoding = '';
/**
* toggles whether the parser decodes element content w/ utf8_decode()
* @var boolean
* @access public
*/
public $decodeUTF8 = true;
/**
* HTTP headers of response
* @var array
* @access public
*/
public $outgoingHeaders = array();
/**
* HTTP response
* @var string
* @access protected
*/
protected $response = '';
/**
* SOAP headers for response (text or array of Val or associative array)
* @var mixed
* @access public
*/
public $responseHeaders = '';
/**
* SOAP payload for response (text)
* @var string
* @access protected
*/
protected $responseSOAP = '';
/**
* method return value to place in response
* @var mixed
* @access protected
*/
protected $methodReturn = false;
/**
* whether $methodreturn is a string of literal XML
* @var boolean
* @access public
*/
public $methodReturnIsLiteralXML = false;
/**
* SOAP fault for response (or false)
* @var mixed
* @access protected
*/
protected $fault = false;
/**
* text indication of result (for debugging)
* @var string
* @access protected
*/
protected $result = 'successful';
/**
* assoc array of operations => opData; operations are added by the register()
* method or by parsing an external WSDL definition
* @var array
* @access protected
*/
protected $operations = array();
/**
* wsdl instance (if one)
* @var mixed
* @access protected
*/
protected $wsdl = false;
/**
* URL for WSDL (if one)
* @var mixed
* @access protected
*/
protected $externalWSDLURL = false;
/**
* whether to append debug to response as XML comment
* @var boolean
* @access public
*/
public $debugFlag = false;
/**
* constructor
* the optional parameter is a path to a WSDL file that you'd like to bind the server instance to.
*
* @param mixed $wsdl file path or URL (string), or wsdl instance (object)
* @access public
*/
public function __construct($wsdl = false, $debug = false)
{
parent::__construct();
$this->appendDebug($this->varDump($_SERVER));
if (static::$debug)
{
$this->debug("In nusoap_server, set debugFlag=$debug based on global flag");
$this->debugFlag = static::$debug;
}
else if (isset($_SERVER['QUERY_STRING']))
{
$qs = explode('&', $_SERVER['QUERY_STRING']);
foreach ($qs as $v)
{
if (substr($v, 0, 6) == 'debug=')
{
$this->debug("In nusoap_server, set debugFlag=" . substr($v, 6) . " based on query string #1");
$this->debugFlag = substr($v, 6);
}
}
}
// wsdl
if ($wsdl)
{
$this->debug("In nusoap_server, WSDL is specified");
if (is_object($wsdl) && (get_class($wsdl) == 'wsdl'))
{
$this->wsdl = $wsdl;
$this->externalWSDLURL = $this->wsdl->wsdl;
$this->debug('Use existing wsdl instance from ' . $this->externalWSDLURL);
}
else
{
$this->debug('Create wsdl from ' . $wsdl);
$this->wsdl = new WSDL($wsdl);
$this->externalWSDLURL = $wsdl;
}
$this->appendDebug($this->wsdl->getDebug());
$this->wsdl->clearDebug();
if ($err = $this->wsdl->getError())
{
die('WSDL ERROR: '.$err);
}
}
}
/**
* processes request and returns response
*
* @param string $data usually is the value of $HTTP_RAW_POST_DATA
* @access public
*/
public function service($data)
{
if (isset($_SERVER['REQUEST_METHOD']))
{
$rm = $_SERVER['REQUEST_METHOD'];
}
else
{
$rm = '';
}
if (isset($_SERVER['QUERY_STRING']))
{
$qs = $_SERVER['QUERY_STRING'];
}
else
{
$qs = '';
}
$this->debug("In service, request method=$rm query string=$qs strlen(\$data)=" . strlen($data));
if ($rm == 'POST')
{
$this->debug("In service, invoke the request");
$this->_parseRequest($data);
if (! $this->fault)
{
$this->invokeMethod();
}
if (! $this->fault)
{
$this->serializeReturn();
}
$this->sendResponse();
}
else if (preg_match('/wsdl/', $qs) )
{
$this->debug("In service, this is a request for WSDL");
if ($this->externalWSDLURL)
{
if (strpos($this->externalWSDLURL, "http://") !== false) // assume URL
{
$this->debug("In service, re-direct for WSDL");
header('Location: '.$this->externalWSDLURL);
}
else // assume file
{
$this->debug("In service, use file passthru for WSDL");
header("Content-Type: text/xml\r\n");
$pos = strpos($this->externalWSDLURL, "file://");
if ($pos === false)
{
$filename = $this->externalWSDLURL;
}
else
{
$filename = substr($this->externalWSDLURL, $pos + 7);
}
$fp = fopen($this->externalWSDLURL, 'r');
fpassthru($fp);
}
}
else if ($this->wsdl)
{
$this->debug("In service, serialize WSDL");
header("Content-Type: text/xml; charset=ISO-8859-1\r\n");
print $this->wsdl->serialize($this->debugFlag);
if ($this->debugFlag)
{
$this->debug('wsdl:');
$this->appendDebug($this->varDump($this->wsdl));
print $this->getDebugAsXMLComment();
}
}
else
{
$this->debug("In service, there is no WSDL");
header("Content-Type: text/html; charset=ISO-8859-1\r\n");
print "This service does not provide WSDL";
}
}
else if ($this->wsdl)
{
$this->debug("In service, return Web description");
print $this->wsdl->webDescription();
}
else
{
$this->debug("In service, no Web description");
header("Content-Type: text/html; charset=ISO-8859-1\r\n");
print "This service does not provide a Web description";
}
}
/**
* parses HTTP request headers.
*
* The following fields are set by this function (when successful)
*
* headers
* request
* xml_encoding
* SOAPAction
*
* @access protected
*/
protected function parseHTTPHeaders()
{
$this->request = '';
$this->SOAPAction = '';
if (function_exists('getallheaders'))
{
$this->debug("In _parseHTTPHeaders, use getallheaders");
$headers = getallheaders();
foreach ($headers as $k=>$v)
{
$k = strtolower($k);
$this->headers[$k] = $v;
$this->request .= "$k: $v\r\n";
$this->debug("$k: $v");
}
// get SOAPAction header
if (isset($this->headers['soapaction']))
{
$this->SOAPAction = str_replace('"','',$this->headers['soapaction']);
}
// get the character encoding of the incoming request
if (isset($this->headers['content-type']) && strpos($this->headers['content-type'],'='))
{
$enc = str_replace('"','',substr(strstr($this->headers["content-type"],'='),1));
if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i',$enc))
{
$this->xmlEncoding = strtoupper($enc);
}
else
{
$this->xmlEncoding = 'US-ASCII';
}
}
else
{
// should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
$this->xmlEncoding = 'ISO-8859-1';
}
}
else if (isset($_SERVER) && is_array($_SERVER))
{
$this->debug("In _parseHTTPHeaders, use _SERVER");
foreach ($_SERVER as $k => $v)
{
if (substr($k, 0, 5) == 'HTTP_')
{
$k = str_replace(' ', '-', strtolower(str_replace('_', ' ', substr($k, 5))));
}
else
{
$k = str_replace(' ', '-', strtolower(str_replace('_', ' ', $k)));
}
if ($k == 'soapaction')
{
// get SOAPAction header
$k = 'SOAPAction';
$v = str_replace('"', '', $v);
$v = str_replace('\\', '', $v);
$this->SOAPAction = $v;
}
else if ($k == 'content-type')
{
// get the character encoding of the incoming request
if (strpos($v, '='))
{
$enc = substr(strstr($v, '='), 1);
$enc = str_replace('"', '', $enc);
$enc = str_replace('\\', '', $enc);
if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i',$enc))
{
$this->xmlEncoding = strtoupper($enc);
}
else
{
$this->xmlEncoding = 'US-ASCII';
}
}
else
{
// should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
$this->xmlEncoding = 'ISO-8859-1';
}
}
$this->headers[$k] = $v;
$this->request .= "$k: $v\r\n";
$this->debug("$k: $v");
}
}
else
{
$this->debug("In _parseHTTPHeaders, HTTP headers not accessible");
$this->setError("HTTP headers not accessible");
}
}
/**
* parses a request
*
* The following fields are set by this function (when successful)
*
* headers
* request
* xml_encoding
* SOAPAction
* request
* requestSOAP
* methodURI
* methodname
* methodparams
* requestHeaders
* document
*
* This sets the fault field on error
*
* @param string $data XML string
* @access protected
*/
protected function _parseRequest($data = '')
{
$this->debug('entering __parseRequest()');
$this->parseHTTPHeaders();
$this->debug('got character encoding: '.$this->xmlEncoding);
// uncompress if necessary
if (isset($this->headers['content-encoding']) && $this->headers['content-encoding'] != '')
{
$this->debug('got content encoding: ' . $this->headers['content-encoding']);
if ($this->headers['content-encoding'] == 'deflate' || $this->headers['content-encoding'] == 'gzip')
{
// if decoding works, use it. else assume data wasn't gzencoded
if (function_exists('gzuncompress'))
{
if ($this->headers['content-encoding'] == 'deflate' && $degzdata = @gzuncompress($data))
{
$data = $degzdata;
}
else if ($this->headers['content-encoding'] == 'gzip' && $degzdata = gzinflate(substr($data, 10)))
{
$data = $degzdata;
}
else
{
$this->fault('SOAP-ENV:Client', 'Errors occurred when trying to decode the data');
return;
}
}
else
{
$this->fault('SOAP-ENV:Client', 'This Server does not support compressed data');
return;
}
}
}
$this->request .= "\r\n".$data;
$data = $this->parseRequest($this->headers, $data);
$this->requestSOAP = $data;
$this->debug('leaving __parseRequest');
}
/**
* invokes a PHP function for the requested SOAP method
*
* The following fields are set by this function (when successful)
*
* methodreturn
*
* Note that the PHP function that is called may also set the following
* fields to affect the response sent to the client
*
* responseHeaders
* outgoing_headers
*
* This sets the fault field on error
*
* @access protected
*/
protected function invokeMethod() {
$this->debug('in _invokeMethod, methodname=' . $this->methodName . ' methodURI=' . $this->methodURI . ' SOAPAction=' . $this->SOAPAction);
//
// if you are debugging in this area of the code, your service uses a class to implement methods,
// you use SOAP RPC, and the client is .NET, please be aware of the following...
// when the .NET wsdl.exe utility generates a proxy, it will remove the '.' or '..' from the
// method name. that is fine for naming the .NET methods. it is not fine for properly constructing
// the XML request and reading the XML response. you need to add the RequestElementName and
// ResponseElementName to the System.Web.Services.Protocols.SoapRpcMethodAttribute that wsdl.exe
// generates for the method. these parameters are used to specify the correct XML element names
// for .NET to use, i.e. the names with the '.' in them.
//
$orig_methodname = $this->methodName;
if ($this->wsdl)
{
if ($this->opData = $this->wsdl->getOperationData($this->methodName))
{
$this->debug('in _invokeMethod, found WSDL operation=' . $this->methodName);
$this->appendDebug('opData=' . $this->varDump($this->opData));
}
else if ($this->opData = $this->wsdl->getOperationDataForSoapAction($this->SOAPAction))
{
// Note: hopefully this case will only be used for doc/lit, since rpc services should have wrapper element
$this->debug('in _invokeMethod, found WSDL soapAction=' . $this->SOAPAction . ' for operation=' . $this->opData['name']);
$this->appendDebug('opData=' . $this->varDump($this->opData));
$this->methodName = $this->opData['name'];
}
else
{
$this->debug('in _invokeMethod, no WSDL for operation=' . $this->methodName);
$this->fault('SOAP-ENV:Client', "Operation '" . $this->methodName . "' is not defined in the WSDL for this service");
return;
}
}
else
{
$this->debug('in _invokeMethod, no WSDL to validate method');
}
// if a . is present in $this->methodName, we see if there is a class in scope,
// which could be referred to. We will also distinguish between two deliminators,
// to allow methods to be called a the class or an instance
if (strpos($this->methodName, '..') > 0)
{
$delim = '..';
}
else if (strpos($this->methodName, '.') > 0)
{
$delim = '.';
}
else
{
$delim = '';
}
$this->debug("in _invokeMethod, delim=$delim");
$class = '';
$method = '';
if (strlen($delim) > 0 && substr_count($this->methodName, $delim) == 1)
{
$try_class = substr($this->methodName, 0, strpos($this->methodName, $delim));
if (class_exists($try_class))
{
// get the class and method name
$class = $try_class;
$method = substr($this->methodName, strpos($this->methodName, $delim) + strlen($delim));
$this->debug("in _invokeMethod, class=$class method=$method delim=$delim");
}
else
{
$this->debug("in _invokeMethod, class=$try_class not found");
}
}
else
{
$try_class = '';
$this->debug("in _invokeMethod, no class to try");
}
// does method exist?
if ($class == '')
{
if (!function_exists($this->methodName))
{
$this->debug("in _invokeMethod, function '$this->methodName' not found!");
$this->result = 'fault: method not found';
$this->fault('SOAP-ENV:Client',"method '$this->methodName'('$orig_methodname') not defined in service('$try_class' '$delim')");
return;
}
}
else
{
$method_to_compare = (substr(phpversion(), 0, 2) == '4.') ? strtolower($method) : $method;
if (!in_array($method_to_compare, get_class_methods($class)))
{
$this->debug("in _invokeMethod, method '$this->methodName' not found in class '$class'!");
$this->result = 'fault: method not found';
$this->fault('SOAP-ENV:Client',"method '$this->methodName'/'$method_to_compare'('$orig_methodname') not defined in service/'$class'('$try_class' '$delim')");
return;
}
}
// evaluate message, getting back parameters
// verify that request parameters match the method's signature
if (! $this->verifyMethod($this->methodName,$this->methodParams))
{
// debug
$this->debug('ERROR: request not verified against method signature');
$this->result = 'fault: request failed validation against method signature';
// return fault
$this->fault('SOAP-ENV:Client',"Operation '$this->methodName' not defined in service.");
return;
}
// if there are parameters to pass
$this->debug('in _invokeMethod, params:');
$this->appendDebug($this->varDump($this->methodParams));
$this->debug("in _invokeMethod, calling '$this->methodName'");
if ($class == '')
{
$this->debug('in _invokeMethod, calling function using call_user_func_array()');
$call_arg = "$this->methodName"; // straight assignment changes $this->methodName to lower case after call_user_func_array()
}
else if ($delim == '..')
{
$this->debug('in _invokeMethod, calling class method using call_user_func_array()');
$call_arg = array ($class, $method);
}
else
{
$this->debug('in _invokeMethod, calling instance method using call_user_func_array()');
$instance = new $class ();
$call_arg = array(&$instance, $method);
}
if (is_array($this->methodParams))
{
$this->methodReturn = call_user_func_array($call_arg, array_values($this->methodParams));
}
else
{
$this->methodReturn = call_user_func_array($call_arg, array());
}
$this->debug('in _invokeMethod, methodreturn:');
$this->appendDebug($this->varDump($this->methodReturn));
$this->debug("in _invokeMethod, called method $this->methodName, received data of type ".gettype($this->methodReturn));
}
/**
* serializes the return value from a PHP function into a full SOAP Envelope
*
* The following fields are set by this function (when successful)
*
* responseSOAP
*
* This sets the fault field on error
*
* @access protected
*/
protected function serializeReturn()
{
$this->debug('Entering _serializeReturn methodname: ' . $this->methodName . ' methodURI: ' . $this->methodURI);
// if fault
if (isset($this->methodReturn) &&
is_object($this->methodReturn) &&
$this->methodReturn instanceof Fault)
{
$this->debug('got a fault object from method');
$this->fault = $this->methodReturn;
return;
}
else if ($this->methodReturnisliteralxml)
{
$return_val = $this->methodReturn;
// returned value(s)
}
else
{
$this->debug('got a(n) '.gettype($this->methodReturn).' from method');
$this->debug('serializing return value');
if ($this->wsdl)
{
if (sizeof($this->opData['output']['parts']) > 1)
{
$this->debug('more than one output part, so use the method return unchanged');
$opParams = $this->methodReturn;
}
else if (sizeof($this->opData['output']['parts']) == 1)
{
$this->debug('exactly one output part, so wrap the method return in a simple array');
// TODO: verify that it is not already wrapped!
//foreach ($this->opData['output']['parts'] as $name => $type) {
// $this->debug('wrap in element named ' . $name);
//}
$opParams = array($this->methodReturn);
}
$return_val = $this->wsdl->serializeRPCParameters($this->methodName,'output',$opParams);
$this->appendDebug($this->wsdl->getDebug());
$this->wsdl->clearDebug();
if ($errstr = $this->wsdl->getError())
{
$this->debug('got wsdl error: '.$errstr);
$this->fault('SOAP-ENV:Server', 'unable to serialize result');
return;
}
}
else
{
if (isset($this->methodReturn))
{
$return_val = $this->serializeVal($this->methodReturn, 'return');
}
else
{
$return_val = '';
$this->debug('in absence of WSDL, assume void return for backward compatibility');
}
}
}
$this->debug('return value:');
$this->appendDebug($this->varDump($return_val));
$this->debug('serializing response');
if ($this->wsdl)
{
$this->debug('have WSDL for serialization: style is ' . $this->opData['style']);
if ($this->opData['style'] == 'rpc')
{
$this->debug('style is rpc for serialization: use is ' . $this->opData['output']['use']);
if ($this->opData['output']['use'] == 'literal')
{
// 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
if ($this->methodURI)
{
$payload = '<ns1:'.$this->methodName.'Response xmlns:ns1="'.$this->methodURI.'">'.$return_val.'</ns1:'.$this->methodName."Response>";
}
else
{
$payload = '<'.$this->methodName.'Response>'.$return_val.'</'.$this->methodName.'Response>';
}
}
else
{
if ($this->methodURI)
{
$payload = '<ns1:'.$this->methodName.'Response xmlns:ns1="'.$this->methodURI.'">'.$return_val.'</ns1:'.$this->methodName."Response>";
}
else
{
$payload = '<'.$this->methodName.'Response>'.$return_val.'</'.$this->methodName.'Response>';
}
}
}
else
{
$this->debug('style is not rpc for serialization: assume document');
$payload = $return_val;
}
}
else
{
$this->debug('do not have WSDL for serialization: assume rpc/encoded');
$payload = '<ns1:'.$this->methodName.'Response xmlns:ns1="'.$this->methodURI.'">'.$return_val.'</ns1:'.$this->methodName."Response>";
}
$this->result = 'successful';
if ($this->wsdl)
{
//if ($this->debugFlag){
$this->appendDebug($this->wsdl->getDebug());
// }
if (isset($this->opData['output']['encodingStyle']))
{
$encodingStyle = $this->opData['output']['encodingStyle'];
}
else
{
$encodingStyle = '';
}
// Added: In case we use a WSDL, return a serialized env. WITH the usedNamespaces.
$this->responseSOAP = $this->serializeEnvelope($payload,$this->responseHeaders,static::$usedNamespaces,$this->opData['style'],$this->opData['output']['use'],$encodingStyle);
}
else
{
$this->responseSOAP = $this->serializeEnvelope($payload,$this->responseHeaders);
}
$this->debug("Leaving _serializeReturn");
}
/**
* sends an HTTP response
*
* The following fields are set by this function (when successful)
*
* outgoing_headers
* response
*
* @access protected
*/
protected function sendResponse()
{
$this->debug('Enter _sendResponse');
if ($this->fault)
{
$payload = $this->fault->serialize();
$this->outgoingHeaders[] = "HTTP/1.0 500 Internal Server Error";
$this->outgoingHeaders[] = "Status: 500 Internal Server Error";
}
else
{
$payload = $this->responseSOAP;
// Some combinations of PHP+Web server allow the Status
// to come through as a header. Since OK is the default
// just do nothing.
// $this->outgoingHeaders[] = "HTTP/1.0 200 OK";
// $this->outgoingHeaders[] = "Status: 200 OK";
}
// add debug data if in debug mode
if (isset($this->debugFlag) && $this->debugFlag)
{
$payload .= $this->getDebugAsXMLComment();
}
$this->outgoingHeaders[] = "Server: $this->title Server v$this->version";
$this->outgoingHeaders[] = "X-SOAP-Server: $this->title/$this->version";
// Let the Web server decide about this
//$this->outgoingHeaders[] = "Connection: Close\r\n";
$payload = $this->getHTTPBody($payload);
$type = $this->getHTTPContentType();
$charset = $this->getHTTPContentTypeCharset();
$this->outgoingHeaders[] = "Content-Type: $type" . ($charset ? '; charset=' . $charset : '');
//begin code to compress payload - by John
// NOTE: there is no way to know whether the Web server will also compress
// this data.
if (strlen($payload) > 1024 && isset($this->headers) && isset($this->headers['accept-encoding']))
{
if (strstr($this->headers['accept-encoding'], 'gzip'))
{
if (function_exists('gzencode'))
{
if (isset($this->debugFlag) && $this->debugFlag)
{
$payload .= "<!-- Content being gzipped -->";
}
$this->outgoingHeaders[] = "Content-Encoding: gzip";
$payload = gzencode($payload);
}
else
{
if (isset($this->debugFlag) && $this->debugFlag)
{
$payload .= "<!-- Content will not be gzipped: no gzencode -->";
}
}
}
else if (strstr($this->headers['accept-encoding'], 'deflate'))
{
// Note: MSIE requires gzdeflate output (no Zlib header and checksum),
// instead of gzcompress output,
// which conflicts with HTTP 1.1 spec (http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.5)
if (function_exists('gzdeflate'))
{
if (isset($this->debugFlag) && $this->debugFlag)
{
$payload .= "<!-- Content being deflated -->";
}
$this->outgoingHeaders[] = "Content-Encoding: deflate";
$payload = gzdeflate($payload);
}
else
{
if (isset($this->debugFlag) && $this->debugFlag)
{
$payload .= "<!-- Content will not be deflated: no gzcompress -->";
}
}
}
}
//end code
$this->outgoingHeaders[] = "Content-Length: ".strlen($payload);
reset($this->outgoingHeaders);
foreach ($this->outgoingHeaders as $hdr)
{