-
Notifications
You must be signed in to change notification settings - Fork 1
/
webservices.inc.php
executable file
·320 lines (292 loc) · 12.5 KB
/
webservices.inc.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
<?php
/**
* This file is part of the RPCL project
*
* Copyright (c) 2004-2011 Embarcadero Technologies, Inc.
*
* Checkout AUTHORS file for more information on the developers
*
* 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
*
*/
/**
*
*/
require_once("rpcl/rpcl.inc.php");
use_unit("classes.inc.php");
use_unit("nusoap/nusoap.php");
/**
* This component represents a web service.
*
* This component allows you to publish specific application functionality using SOAP
* technology, so you can write clients that consume that functionality in other languages
* that share the same technology.
*
* @link http://www.w3.org/TR/soap/
*
* @example Web Service/soapserver.php Creating web services
* @example Web Service/soapserver.xml.php Creating web services (form)
*
*/
class Service extends Component
{
private $_server = null;
protected $_active = '0';
/**
* Specifies if the webservice is active or not.
*
* If this property is set to true, the component will fire the events
* to get the functions to register and any complex type required and
* will publish the WSDL and process service requests
*
* @return boolean
*/
function getActive() { return $this->_active; }
function setActive($value) { $this->_active = $value; }
function defaultActive() { return '0'; }
protected $_servicename = "RPCL";
/**
* Specifies the Name of the service you want to create
*
* This property determines the name of the service you are going to
* publish. The default value is RPCL
*
* @return string
*/
function getServiceName() { return $this->_servicename; }
function setServiceName($value) { $this->_servicename = $value; }
function defaultServiceName() { return "RPCL"; }
protected $_namespace = "http://localhost";
/**
* Specifies the Name Space for the WSDL
*
* This property is used to provide the namespace used when generating the
* web service description (WSDL)
*
* @return string
*/
function getNameSpace() { return $this->_namespace; }
function setNameSpace($value) { $this->_namespace = $value; }
function defaultNameSpace() { return "http://localhost"; }
protected $_schematargetnamespace = "http://localhost/xsd";
/**
* Specifies the Target Name Space for the WSDL
*
* This property is used to provide the target namespace used when gene3rating
* the webservice description (WSDL)
*
* @return string
*/
function getSchemaTargetNamespace() { return $this->_schematargetnamespace; }
function setSchemaTargetNamespace($value) { $this->_schematargetnamespace = $value; }
function defaultSchemaTargetNamespace() { return "http://localhost/xsd"; }
protected $_onregisterservices = null;
/**
* Fired when the service needs to register the functions to be published by the service.
*
* Use this event to call register method and specify which methods do you want
* to publish so are available by users of the webservice.
*
* <code>
* <?php
* function MyWebServiceRegisterServices($sender, $params)
* {
* //Register the echo service
* $this->MyWebService->register(
* "serviceEcho",
* array('input'=>'xsd:string'),
* array('return'=>'xsd:string'),
* 'http://localhost/'
* );
*
*
* //Register the conversion service
* $this->MyWebService->register(
* "StringArrayToIntArray",
* array('input'=>'tns:ArrayOfstring'),
* array('return'=>'tns:ArrayOfinteger'),
* 'http://localhost/'
* );
*
* }
* ?>
* </code>
* @see register()
* @return mixed
*/
function getOnRegisterServices() { return $this->_onregisterservices; }
function setOnRegisterServices($value) { $this->_onregisterservices = $value; }
function defaultOnRegisterServices() { return null; }
protected $_onaddcomplextypes = null;
/**
* Fired when the service needs to register complex types.
*
* Use this event to register all complex types your functions need by calling
* addComplexType method. Complex types are built using simple types.
*
* <code>
* <?php
* function MyWebServiceAddComplexTypes($sender, $params)
* {
* //Add the complex type array of strings
* $this->MyWebService->addComplexType
* (
* 'ArrayOfstring',
* 'complexType',
* 'array',
* '',
* 'SOAP-ENC:Array',
* array(),
* array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'string[]')),
* 'xsd:string'
* );
*
* //Add the complex type array of integers
* $this->MyWebService->addComplexType
* (
* 'ArrayOfinteger',
* 'complexType',
* 'array',
* '',
* 'SOAP-ENC:Array',
* array(),
* array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'integer[]')),
* 'xsd:integer'
* );
* }
* ?>
* </code>
* @see addComplexType()
* @return mixed
*/
function getOnAddComplexTypes() { return $this->_onaddcomplextypes; }
function setOnAddComplexTypes($value) { $this->_onaddcomplextypes = $value; }
function defaultOnAddComplexTypes() { return null; }
function init()
{
if (($this->ControlState & csDesigning) != csDesigning)
{
if ($this->_active)
{
//If the webservice is active, create the nusoap object
$this->_server = new soap_server();
$this->_server->configureWSDL($this->_servicename, $this->_namespace);
$this->_server->wsdl->schemaTargetNamespace = $this->_schematargetnamespace;
//Call events
$this->callEvent('onaddcomplextypes', array());
$this->callEvent('onregisterservices', array());
global $HTTP_RAW_POST_DATA;
$HTTP_RAW_POST_DATA=isset($HTTP_RAW_POST_DATA)?$HTTP_RAW_POST_DATA:file_get_contents("php://input");
$this->_server->service($HTTP_RAW_POST_DATA);
global $log;
if(isset($log) and $log != '')
{
harness('nusoap_r2_base_server', $this->_server->headers['User-Agent'], $this->_server->methodname, $this->_server->request, $this->_server->response, $this->_server->result);
}
}
}
}
function __construct($aowner = null)
{
//Calls inherited constructor
parent::__construct($aowner);
}
/**
* Register a service function with the server
*
* Use this method on the OnRegisterServices event to register all
* methods you want to publish.
*
* <code>
* <?php
* //Register the echo service
* $this->MyWebService->register(
* "serviceEcho",
* array('input'=>'xsd:string'),
* array('return'=>'xsd:string'),
* 'http://localhost/'
* );
* ?>
* </code>
*
* @param string $name the name of the PHP function, class.method or class..method
* @param array $in assoc array of input values: key = param name, value = param type
* @param array $out assoc array of output values: key = param name, value = param type
* @param mixed $namespace the element namespace for the method or false
* @param mixed $soapaction the soapaction for the method or false
* @param mixed $style optional (rpc|document) or false Note: when 'document' is specified, parameter and return wrappers are created for you automatically
* @param mixed $use optional (encoded|literal) or false
* @param string $documentation optional Description to include in WSDL
* @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
*
*/
function register($name,$in=array(),$out=array(),$namespace=false,$soapaction=false,$style=false,$use=false,$documentation='',$encodingStyle='')
{
if ($namespace==false) $namespace=$this->_namespace;
$this->_server->register($name,$in,$out,$namespace,$soapaction,$style,$use,$documentation,$encodingStyle);
}
/**
* Adds a complex type to the schema
*
* Use this method on the OnAddComplexTypes event to provide a description
* for your complex types.
*
* <code>
* <?php
*
* //Adding a string array type
* addComplexType(
* 'ArrayOfstring',
* 'complexType',
* 'array',
* '',
* 'SOAP-ENC:Array',
* array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'string[]'),
* 'xsd:string'
* );
*
* //Adding a PHP associative array ( SOAP Struct )
* addComplexType(
* 'SOAPStruct',
* 'complexType',
* 'struct',
* 'all',
* array('myVar'=> array('name'=>'myVar','type'=>'string')
* );
* ?>
* </code>
*
* @param string $name Type name
* @param string $typeClass (complexType|simpleType|attribute)
* @param string $phpType currently supported are array and struct (php assoc array)
* @param string $compositor (all|sequence|choice)
* @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
* @param array $elements = array ( name = array(name=>'',type=>'') )
* @param array $attrs = array(
* array(
* 'ref' => "http://schemas.xmlsoap.org/soap/encoding/:arrayType",
* "http://schemas.xmlsoap.org/wsdl/:arrayType" => "string[]"
* )
* )
* @param string $arrayType namespace:name (http://www.w3.org/2001/XMLSchema:string)
*
*/
function addComplexType($name,$typeClass='complexType',$phpType='array',$compositor='',$restrictionBase='',$elements=array(),$attrs=array(),$arrayType='')
{
$this->_server->wsdl->addComplexType($name,$typeClass, $phpType,$compositor,$restrictionBase,$elements,$attrs,$arrayType);
}
}
?>