[2] | 1 | <?php |
---|
[5509] | 2 | /*************************************************************************** |
---|
| 3 | * Expresso Livre * |
---|
| 4 | * http://www.expressolivre.org * |
---|
| 5 | * -------------------------------------------- * |
---|
| 6 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 7 | * under the terms of the GNU General Public License as published by the * |
---|
| 8 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 9 | * option) any later version. * |
---|
| 10 | \**************************************************************************/ |
---|
| 11 | |
---|
[2] | 12 | /* |
---|
| 13 | |
---|
| 14 | SOAPx4 |
---|
| 15 | by Dietrich Ayala (C) 2001 dietrich@ganx4.com |
---|
| 16 | |
---|
| 17 | This project began based on code from the 2 projects below, |
---|
| 18 | and still contains some original code. The licenses of both must be respected. |
---|
| 19 | |
---|
| 20 | XML-RPC for PHP |
---|
| 21 | originally by Edd Dumbill (C) 1999-2000 |
---|
| 22 | |
---|
| 23 | SOAP for PHP |
---|
| 24 | by Victor Zou (C) 2000-2001 <victor@gigaideas.com.cn> |
---|
| 25 | |
---|
| 26 | */ |
---|
| 27 | |
---|
| 28 | /* changelog: |
---|
| 29 | 2001-07-04 |
---|
| 30 | - abstract type system to support either 1999 or 2001 schema (arg, typing still needs much |
---|
| 31 | solidification.) |
---|
| 32 | - implemented proxy support, based on sample code from miles lott <milos@speakeasy.net> |
---|
| 33 | - much general cleanup of code & cleaned out what was left of original xml-rpc/gigaideas code |
---|
| 34 | - implemented a transport argument into send() that allows you to specify different transports |
---|
| 35 | (assuming you have implemented the function, and added it to the conditional statement in send() |
---|
| 36 | - abstracted the determination of charset in Content-type header |
---|
| 37 | 2001-07-5 |
---|
| 38 | - fixed more weird type/namespace issues |
---|
| 39 | */ |
---|
| 40 | |
---|
| 41 | // $path can be a complete endpoint url, with the other parameters left blank: |
---|
| 42 | // $soap_client = new soap_client("http://path/to/soap/server"); |
---|
| 43 | |
---|
| 44 | /* soapx4 high level class |
---|
| 45 | |
---|
| 46 | usage: |
---|
| 47 | |
---|
| 48 | // instantiate client with server info |
---|
| 49 | $soapclient = new soapclient( string path [ ,boolean wsdl] ); |
---|
| 50 | |
---|
| 51 | // call method, get results |
---|
| 52 | echo $soapclient->call( string methodname [ ,array parameters] ); |
---|
| 53 | |
---|
| 54 | // bye bye client |
---|
| 55 | unset($soapclient); |
---|
| 56 | |
---|
| 57 | */ |
---|
| 58 | |
---|
| 59 | class soapclient |
---|
| 60 | { |
---|
| 61 | function soapclient($endpoint,$wsdl=False,$portName=False) |
---|
| 62 | { |
---|
| 63 | $this->debug_flag = True; |
---|
| 64 | $this->endpoint = $endpoint; |
---|
| 65 | $this->portName = False; |
---|
| 66 | |
---|
| 67 | // make values |
---|
| 68 | if($wsdl) |
---|
| 69 | { |
---|
| 70 | $this->endpointType = 'wsdl'; |
---|
| 71 | if($portName) |
---|
| 72 | { |
---|
| 73 | $this->portName = $portName; |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | function call($method,$params='',$namespace=false,$soapAction=false) |
---|
| 79 | { |
---|
| 80 | if($this->endpointType == 'wsdl') |
---|
| 81 | { |
---|
| 82 | // instantiate wsdl class |
---|
| 83 | $this->wsdl = CreateObject('phpgwapi.wsdl',$this->endpoint); |
---|
| 84 | // get portName |
---|
| 85 | if(!$this->portName) |
---|
| 86 | { |
---|
| 87 | $this->portName = $this->wsdl->getPortName($method); |
---|
| 88 | } |
---|
| 89 | // get endpoint |
---|
| 90 | if(!$this->endpoint = $this->wsdl->getEndpoint($this->portName)) |
---|
| 91 | { |
---|
| 92 | die("no port of name '$this->portName' in the wsdl at that location!"); |
---|
| 93 | } |
---|
| 94 | $this->debug("endpoint: $this->endpoint"); |
---|
| 95 | $this->debug("portName: $this->portName"); |
---|
| 96 | } |
---|
| 97 | // get soapAction |
---|
| 98 | if(!$soapAction) |
---|
| 99 | { |
---|
| 100 | if($this->endpointType != 'wsdl') |
---|
| 101 | { |
---|
| 102 | die("method call requires soapAction if wsdl is not available!"); |
---|
| 103 | } |
---|
| 104 | if(!$soapAction = $this->wsdl->getSoapAction($this->portName,$method)) |
---|
| 105 | { |
---|
| 106 | die("no soapAction for operation: $method!"); |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | $this->debug("soapAction: $soapAction"); |
---|
| 110 | // get namespace |
---|
| 111 | if(!$namespace) |
---|
| 112 | { |
---|
| 113 | if($this->endpointType != 'wsdl') |
---|
| 114 | { |
---|
| 115 | die("method call requires namespace if wsdl is not available!"); |
---|
| 116 | } |
---|
| 117 | if(!$namespace = $this->wsdl->getNamespace($this->portName,$method)) |
---|
| 118 | { |
---|
| 119 | die("no soapAction for operation: $method!"); |
---|
| 120 | } |
---|
| 121 | } |
---|
| 122 | $this->debug("namespace: $namespace"); |
---|
| 123 | |
---|
| 124 | // make message |
---|
| 125 | $soapmsg = CreateObject('phpgwapi.soapmsg',$method,$params,$namespace); |
---|
| 126 | /* _debug_array($soapmsg); */ |
---|
| 127 | |
---|
| 128 | // instantiate client |
---|
| 129 | $dbg = "calling server at '$this->endpoint'..."; |
---|
| 130 | if($soap_client = CreateObject('phpgwapi.soap_client',$this->endpoint)) |
---|
| 131 | { |
---|
| 132 | //$soap_client->debug_flag = true; |
---|
| 133 | $this->debug($dbg.'instantiated client successfully'); |
---|
| 134 | $this->debug("client data:<br>server: $soap_client->server<br>path: $soap_client->path<br>port: $soap_client->port"); |
---|
| 135 | // send |
---|
| 136 | $dbg = "sending msg w/ soapaction '$soapAction'..."; |
---|
| 137 | if($return = $soap_client->send($soapmsg,$soapAction)) |
---|
| 138 | { |
---|
| 139 | $this->request = $soap_client->outgoing_payload; |
---|
| 140 | $this->response = $soap_client->incoming_payload; |
---|
| 141 | $this->debug($dbg . "sent message successfully and got a '$return' back"); |
---|
| 142 | // check for valid response |
---|
| 143 | if(get_class($return) == 'soapval') |
---|
| 144 | { |
---|
| 145 | // fault? |
---|
[5928] | 146 | if(preg_match('/fault/i',$return->name)) |
---|
[2] | 147 | { |
---|
| 148 | $this->debug('got fault'); |
---|
| 149 | $faultArray = $return->decode(); |
---|
| 150 | @reset($faultArray); |
---|
| 151 | while(list($k,$v) = @each($faultArray)) |
---|
| 152 | /* foreach($faultArray as $k => $v) */ |
---|
| 153 | { |
---|
| 154 | print "$k = $v<br>"; |
---|
| 155 | } |
---|
| 156 | return false; |
---|
| 157 | } |
---|
| 158 | else |
---|
| 159 | { |
---|
| 160 | $returnArray = $return->decode(); |
---|
| 161 | if(is_array($returnArray)) |
---|
| 162 | { |
---|
| 163 | return array_shift($returnArray); |
---|
| 164 | } |
---|
| 165 | else |
---|
| 166 | { |
---|
| 167 | $this->debug("didn't get array back from decode() for $return->name"); |
---|
| 168 | return false; |
---|
| 169 | } |
---|
| 170 | } |
---|
| 171 | } |
---|
| 172 | else |
---|
| 173 | { |
---|
| 174 | $this->debug("didn't get soapval object back from client"); |
---|
| 175 | return false; |
---|
| 176 | } |
---|
| 177 | } |
---|
| 178 | else |
---|
| 179 | { |
---|
| 180 | $this->debug('client send/recieve error'); |
---|
| 181 | return false; |
---|
| 182 | } |
---|
| 183 | } |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | function debug($string) |
---|
| 187 | { |
---|
| 188 | if($this->debug_flag) |
---|
| 189 | { |
---|
| 190 | print $string . '<br>'; |
---|
| 191 | } |
---|
| 192 | } |
---|
| 193 | } |
---|
| 194 | ?> |
---|