-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.phpwsdlmethod.php
400 lines (383 loc) · 11.2 KB
/
class.phpwsdlmethod.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
<?php
/*
PhpWsdl - Generate WSDL from PHP
Copyright (C) 2011 Andreas Müller-Saala, wan24.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 3 of the License, or (at your option) any later
version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, see <http://www.gnu.org/licenses/>.
*/
if(basename($_SERVER['SCRIPT_FILENAME'])==basename(__FILE__))
exit;
PhpWsdl::RegisterHook('InterpretKeywordpw_omitfncHook','internal','PhpWsdlMethod::InterpretOmit');
PhpWsdl::RegisterHook('InterpretKeywordignoreHook','internal','PhpWsdlMethod::InterpretOmit');
PhpWsdl::RegisterHook('CreateObjectHook','internalmethod','PhpWsdlMethod::CreateMethodObject');
/**
* A method definition object
*
* @author Andreas Müller-Saala, wan24.de
*/
class PhpWsdlMethod extends PhpWsdlObject{
/**
* A list of parameters
*
* @var PhpWsdlParam[]
*/
public $Param=Array();
/**
* The return value
*
* @var PhpWsdlParam
*/
public $Return=null;
/**
* A global method?
*
* @var boolean
*/
public $IsGlobal=false;
/**
* The class name or the object that contains this method
*
* @var string|object
*/
public $Class=null;
/**
* The exception type name for this method
* Tip: Set this to an empty string to override the default exception type name
*
* @var string
*/
public $Exception=null;
/**
* A new method is global per default?
*
* @var boolean
*/
public static $IsGlobalDefault=false;
/**
* The name of the default exception type
*
* @var string
*/
public static $DefaultException=null;
/**
* Constructor
*
* @param string $name The name
* @param PhpWsdlParam[] $param Optional the list of parameters (default: NULL)
* @param PhpWsdlParam $return Optional the return value (default: NULL)
* @param array $settings Optional the settings hash array (default: NULL)
*/
public function PhpWsdlMethod($name,$param=null,$return=null,$settings=null){
PhpWsdl::Debug('New method '.$name);
parent::PhpWsdlObject($name,$settings);
if(!is_null($param))
$this->Param=$param;
$this->Return=$return;
$this->IsGlobal=self::$IsGlobalDefault;
$this->Exception=self::$DefaultException;
if(!is_null($settings)){
if(isset($settings['global']))
$this->IsGlobal=$settings['global']=='true'||$settings['global']=='1';
if(isset($settings['class']))
$this->Class=$settings['class'];
if(isset($settings['exception']))
$this->Exception=$settings['exception'];
}
}
/**
* Get the exception type name
*
* @return string The type name or NULL
*/
public function GetExceptionTypeName(){
return (!is_null($this->Exception))
?$this->Exception
:self::$DefaultException;
}
/**
* Create the port type WSDL
*
* @param PhpWsdl $pw The PhpWsdl object
* @return string The WSDL
*/
public function CreatePortType($pw){
PhpWsdl::Debug('Create WSDL port type for method '.$this->Name);
$res=Array();
$res[]='<wsdl:operation name="'.$this->Name.'"';
$o=sizeof($res)-1;
$pLen=sizeof($this->Param);
if($pLen>1){
$temp=Array();
$i=-1;
while(++$i<$pLen)
$temp[]=$this->Param[$i]->Name;
$res[$o].=' parameterOrder="'.implode(' ',$temp).'"';
}
$res[$o].='>';
if($pw->IncludeDocs&&!$pw->Optimize&&!is_null($this->Docs))
$res[]='<wsdl:documentation><![CDATA['.$this->Docs.']]></wsdl:documentation>';
$res[]='<wsdl:input message="tns:'.$this->Name.'SoapIn" />';
$res[]='<wsdl:output message="tns:'.$this->Name.'SoapOut" />';
$ex=$this->GetExceptionTypeName();
if($ex!=null)
$res[]='<wsdl:fault message="tns:'.$this->Name.'Exception" />';
$res[]='</wsdl:operation>';
return implode('',$res);
}
/**
* Create the binding WSDL
*
* @param PhpWsdl $pw The PhpWsdl object
* @return string The WSDL
*/
public function CreateBinding($pw){
PhpWsdl::Debug('Create WSDL binding for method '.$this->Name);
$res=Array();
$res[]='<wsdl:operation name="'.$this->Name.'">';
$res[]='<soap:operation soapAction="'.$pw->NameSpace.$this->Name.'" />';
$res[]='<wsdl:input>';
$res[]='<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="'.$pw->NameSpace.'"';
$pLen=sizeof($this->Param);
if($pLen>0){
$temp=Array();
$i=-1;
while(++$i<$pLen)
$temp[]=$this->Param[$i]->Name;
$res[sizeof($res)-1].=' parts="'.implode(' ',$temp).'"';
}
$res[sizeof($res)-1].=' />';
$res[]='</wsdl:input>';
$res[]='<wsdl:output>';
$res[]='<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="'.$pw->NameSpace.'"';
if(!is_null($this->Return))
$res[sizeof($res)-1].=' parts="'.$this->Return->Name.'"';
$res[sizeof($res)-1].=' />';
$res[]='</wsdl:output>';
$ex=$this->GetExceptionTypeName();
if($ex!=null){
$res[]='<wsdl:fault name="'.$this->Name.'Exception">';
$res[]='<soap:fault name="'.$this->Name.'Exception" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="'.$pw->NameSpace.'" />';
$res[]='</wsdl:fault>';
}
$res[]='</wsdl:operation>';
return implode('',$res);
}
/**
* Create the input/output messages WSDL
*
* @param PhpWsdl $pw The PhpWsdl object
* @return string The WSDL
*/
public function CreateMessages($pw){
PhpWsdl::Debug('Create WSDL message for method '.$this->Name);
$pLen=sizeof($this->Param);
$res=Array();
// Request
if($pLen<1){
$res[]='<wsdl:message name="'.$this->Name.'SoapIn" />';
}else{
$res[]='<wsdl:message name="'.$this->Name.'SoapIn">';
$i=-1;
while(++$i<$pLen)
$res[]=$this->Param[$i]->CreatePart($pw);
$res[]='</wsdl:message>';
}
// Response
if(is_null($this->Return)){
$res[]='<wsdl:message name="'.$this->Name.'SoapOut" />';
}else{
$res[]='<wsdl:message name="'.$this->Name.'SoapOut">';
$res[]=$this->Return->CreatePart($pw);
$res[]='</wsdl:message>';
}
// Exception
$ex=$this->GetExceptionTypeName();
if($ex!=null){
$res[]='<wsdl:message name="'.$this->Name.'Exception">';
$res[]='<wsdl:part name="fault" type="tns:'.$ex.'" />';
$res[]='</wsdl:message>';
}
return implode('',$res);
}
/**
* Find a parameter of this method
*
* @param string $name The parameter name
* @return PhpWsdlParam The parameter or NULL, if not found
*/
public function GetParam($name){
PhpWsdl::Debug('Find parameter '.$name);
$i=-1;
$len=sizeof($this->Param);
while(++$i<$len)
if($this->Param[$i]->Name==$name){
PhpWsdl::Debug('Found parameter at index '.$i);
return $this->Param[$i];
}
return null;
}
/**
* Create HTML docs
*
* @param array $data Some data
*/
public function CreateMethodHtml($data){
PhpWsdl::Debug('CreateMethodHtml for '.$data['method']->Name);
$res=&$data['res'];
$m=&$data['method'];
$res[]='<h3>'.$m->Name.'</h3>';
$res[]='<a name="'.$m->Name.'"></a>';
$res[]='<p class="pre">';
$o=sizeof($res)-1;
if(!is_null($m->Return)){
$type=$m->Return->Type;
if(in_array($type,PhpWsdl::$BasicTypes)){
$res[$o].='<span class="blue">'.$type.'</span>';
}else{
$res[$o].='<a href="#'.$type.'"><span class="lightBlue">'.$type.'</span></a>';
}
}else{
$res[$o].='void';
}
$res[$o].=' <span class="bold">'.$m->Name.'</span> (';
$pLen=sizeof($m->Param);
$spacer='';
if($pLen>1){
$res[$o].='<br>';
$spacer=' ';
}
$hasDocs=false;
if($pLen>0){
$j=-1;
while(++$j<$pLen){
$p=$m->Param[$j];
if(in_array($p->Type,PhpWsdl::$BasicTypes)){
$res[]=$spacer.'<span class="blue">'.$p->Type.'</span> <span class="bold">'.$p->Name.'</span>';
}else{
$res[]=$spacer.'<a href="#'.$p->Type.'"><span class="lightBlue">'.$p->Type.'</span></a> <span class="bold">'.$p->Name.'</span>';
}
$o=sizeof($res)-1;
if($j<$pLen-1)
$res[$o].=', ';
if($pLen>1)
$res[$o].='<br>';
if(!$hasDocs)
if(!is_null($p->Docs))
$hasDocs=true;
}
}
$res[].=')</p>';
// Method documentation
if(!is_null($m->Docs))
$res[]='<p>'.nl2br(htmlentities($m->Docs)).'</p>';
// Parameters documentation
if($hasDocs){
$res[]='<ul>';
$j=-1;
while(++$j<$pLen)
$m->Param[$j]->CreateParamHtml(array_merge(
$data,
Array(
'param' => $m->Param[$j]
)
)
);
$res[]='</ul>';
}
// Return value documentation
if(!is_null($m->Return)&&!is_null($m->Return->Docs))
$m->Return->CreateReturnHtml($data);
PhpWsdl::CallHook(
'CreateMethodHtmlHook',
$data
);
}
/**
* Create method PHP
*
* @param array $data The event data
*/
public function CreateMethodPhp($data){
$server=$data['server'];
$res=&$data['res'];
$res[]="\t/**";
if(!is_null($this->Docs)){
$res[]="\t * ".implode("\n\t * ",explode("\n",$this->Docs));
$res[]="\t *";
}
$param=Array();
$i=-1;
$pLen=sizeof($this->Param);
while(++$i<$pLen){
$p=$this->Param[$i];
$param[]='$'.$p->Name;
$res[]="\t * @param ".$p->Type." \$".$p->Name.((!is_null($p->Docs))?" ".implode("\n\t * ",explode("\n",$p->Docs)):"");
}
if(!is_null($this->Return)){
$res[]="\t * @return ".$this->Return->Type.((!is_null($this->Return->Docs))?" ".implode("\n\t * ",explode("\n",$this->Return->Docs)):"");
}
$res[]="\t */";
$res[]="\tpublic function ".$this->Name."(".implode(',',$param)."){";
if(PhpWsdl::CallHook(
'CreateMethodPhpHook',
array_merge(
$data,
Array(
'method' => $this
)
)
)
){
$res[]="\t\treturn self::_Call('".$this->Name."',Array(";
if($pLen>0)
$res[]="\t\t\t".implode(",\n\t\t\t",$param);
$res[]="\t\t));";
}
$res[]="\t}";
}
/**
* Interpret omit keyword
*
* @param array $data The parser data
* @return boolean Response
*/
public static function InterpretOmit($data){
PhpWsdl::Debug('Interpret omitfnc/ignore');
$data['omit']=true;
return true;
}
/**
* Create method object
*
* @param array $data The parser data
* @return boolean Response
*/
public static function CreateMethodObject($data){
if(!is_null($data['obj']))
return true;
if($data['method']=='')
return true;
if(!is_null($data['type']))
return true;
PhpWsdl::Debug('Add method '.$data['method']);
$server=$data['server'];
if(!is_null($server->GetMethod($data['method']))){
PhpWsdl::Debug('WARNING: Double method detected!');
return true;
}
if($server->ParseDocs)
if(!is_null($data['docs']))
$data['settings']['docs']=$data['docs'];
$data['obj']=new PhpWsdlMethod($data['method'],$data['param'],$data['return'],$data['settings']);
$data['settings']=Array();
$server->Methods[]=$data['obj'];
return true;
}
}