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
|
<?php
/*
* class.delegating_soap_server.php - A SOAP server that delegates invocation.
*
* Copyright (C) 2006 - Marcus Lunzenauer <mlunzena@uos.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
/**
* DelegatingSoapServer extends the basic soap_server and delegates the
* actual invocation of php functions and methods to a another object.
*
*
* @package nusoap
*
* @author Marcus Lunzenauer <mlunzena@uos.de>
* @author Dietrich Ayala <dietrich@ganx4.com>
* @copyright (c) Authors
* @version $Id: class.delegating_soap_server.php 3823 2006-08-29 10:52:08Z mlunzena $
*/
class DelegatingSoapServer extends soap_server {
/**
* The delegate which invokes soap functions.
*
* @access private
* @var mixed
*/
var $delegate;
/**
* Constructor.
* The optional parameter is a path to a WSDL file that you'd like to bind the
* server instance to.
*
* @param mixed file path or URL (string), or wsdl instance (object)
*
* @return void
*/
function __construct(&$delegate, $wsdl = FALSE) {
parent::__construct($wsdl);
$this->delegate =& $delegate;
}
/**
* 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
*
* @return void
*/
function invoke_method() {
$this->debug(
sprintf('in invoke_method, methodname=%s methodURI=%s SOAPAction=%s',
$this->methodname, $this->methodURI, $this->SOAPAction));
if ($this->wsdl) {
if ($this->opData = $this->wsdl->getOperationData($this->methodname)) {
$this->debug('in invoke_method, 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 invoke_method, 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 invoke_method, no WSDL for operation=' .
$this->methodname);
$this->fault('Client', "Operation '" . $this->methodname .
"' is not defined in the WSDL for this service");
return;
}
}
else {
$this->debug('in invoke_method, no WSDL to validate method');
}
# does method exist?
if (!$this->delegate->responds_to($this->methodname)) {
$this->debug("in invoke_method, function '$this->methodname' not found!");
$this->result = 'fault: method not found';
$this->fault('Client',
"method '$this->methodname' not defined in service");
return;
}
# evaluate message, getting back parameters
# verify that request parameters match the method's signature
if (!$this->verify_method($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('Client',
"Operation '$this->methodname' not defined in service.");
return;
}
# if there are parameters to pass
$this->debug('in invoke_method, params:');
$this->appendDebug($this->varDump($this->methodparams));
$this->debug("in invoke_method, calling '$this->methodname'");
$this->methodreturn = $this->delegate->invoke($this->methodname,
$this->methodparams);
$this->debug("in invoke_method, received ".$this->varDump($this->methodreturn)." of type " .
gettype($this->methodreturn));
}
}
|