-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.phpwsdlproxy.php
90 lines (83 loc) · 3.04 KB
/
class.phpwsdlproxy.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
<?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;
// This proxy can handle missing parameters with NULL values. This will only
// work, if the PhpWsdl class doesn't promote the WSDL to the SoapServer. But
// then returning complex types won't be easy anymore: You have to encode the
// return value with PHPs SoapVar object by yourself.
class PhpWsdlProxy{
public function __call($method,$param){
if(PhpWsdl::$Debugging)
PhpWsdl::Debug('Proxy call method '.$method.': '.print_r($param,true));
PhpWsdl::$ProxyServer->CreateWsdl();
$m=PhpWsdl::$ProxyServer->GetMethod($method);
if(is_null($m))
throw(new SoapFault('MissingMethod','Method "'.$method.'" not found'));
// Try to fix the missing parameters issue if the SoapServer is not running in WSDL mode
if(!PhpWsdl::$UseProxyWsdl){
$pLen=sizeof($m->Param);
$temp=sizeof($param);
if($pLen!=$temp){
PhpWsdl::Debug('Wrong parameter count ('.$temp.'/'.$pLen.')');
$req=new DOMDocument();
if($req->loadXml(file_get_contents('php://input'))){
$x=new DOMXPath($req);
$temp=$param;
$param=Array();
$pos=0;// Current index in the received parameter array
$i=-1;
while(++$i<$pLen){
$p=$m->Param[$i];
if($x->query("/*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='".$m->Name."']/*[local-name()='".$p->Name."']")->length>0){
PhpWsdl::Debug('Parameter "'.$p->Name.'" was received');
$param[]=$temp[$pos];
$pos++;
}else{
PhpWsdl::Debug('Parameter "'.$p->Name.'" was missing');
$param[]=null;
}
}
}else{
PhpWsdl::Debug('Could not parse SOAP request XML');
}
}
}
// Prepare the method call
$call=($m->IsGlobal)
?$method // Global method
:Array( // Class method
(is_null($m->Class))?PhpWsdl::$ProxyObject:$m->Class,
$method
);
// Call the target method
PhpWsdl::Debug('Call the target method');
$res=(sizeof($param)<1)
?call_user_func(
$call
)
:call_user_func_array(
$call,
$param
);
// Return the encoded response
$type=(is_null($m->Return))
?null
:$m->Return->Name;
return (PhpWsdl::$EncodeProxyReturn&&!is_null($type))
?PhpWsdl::DoEncoding($type,$res,false,PhpWsdl::$ProxyServer)
:$res;
}
}