egroupware/phpgwapi/inc/class.soapclient.inc.php

186 lines
4.8 KiB
PHP
Raw Normal View History

2001-07-16 08:05:33 +02:00
<?php
2001-09-28 23:31:39 +02:00
/*
SOAPx4
by Dietrich Ayala (C) 2001 dietrich@ganx4.com
This project began based on code from the 2 projects below,
and still contains some original code. The licenses of both must be respected.
XML-RPC for PHP
originally by Edd Dumbill (C) 1999-2000
SOAP for PHP
by Victor Zou (C) 2000-2001 <victor@gigaideas.com.cn>
*/
/* changelog:
2001-07-04
- abstract type system to support either 1999 or 2001 schema (arg, typing still needs much
solidification.)
- implemented proxy support, based on sample code from miles lott <milos@speakeasy.net>
- much general cleanup of code & cleaned out what was left of original xml-rpc/gigaideas code
- implemented a transport argument into send() that allows you to specify different transports
(assuming you have implemented the function, and added it to the conditional statement in send()
- abstracted the determination of charset in Content-type header
2001-07-5
- fixed more weird type/namespace issues
*/
// $path can be a complete endpoint url, with the other parameters left blank:
// $soap_client = new soap_client("http://path/to/soap/server");
2001-07-16 08:05:33 +02:00
/* soapx4 high level class
2001-08-18 16:37:52 +02:00
usage:
2001-07-16 08:05:33 +02:00
2001-08-18 16:37:52 +02:00
// instantiate client with server info
$soapclient = new soapclient( string path [ ,boolean wsdl] );
2001-07-16 08:05:33 +02:00
2001-08-18 16:37:52 +02:00
// call method, get results
echo $soapclient->call( string methodname [ ,array parameters] );
2001-07-16 08:05:33 +02:00
2001-08-18 16:37:52 +02:00
// bye bye client
unset($soapclient);
2001-07-16 08:05:33 +02:00
*/
2001-08-18 16:37:52 +02:00
/* $Id$ */
2001-07-16 08:05:33 +02:00
2001-08-18 16:37:52 +02:00
class soapclient
2001-07-16 08:05:33 +02:00
{
2001-08-18 16:37:52 +02:00
function soapclient($endpoint,$wsdl=False,$portName=False)
2001-07-16 08:05:33 +02:00
{
2001-08-18 16:37:52 +02:00
$this->debug_flag = True;
$this->endpoint = $endpoint;
$this->portName = False;
2001-07-16 08:05:33 +02:00
2001-08-18 16:37:52 +02:00
// make values
if($wsdl)
2001-07-16 08:05:33 +02:00
{
2001-08-18 16:37:52 +02:00
$this->endpointType = 'wsdl';
if($portName)
{
$this->portName = $portName;
}
2001-07-16 08:05:33 +02:00
}
}
2001-08-18 16:37:52 +02:00
function call($method,$params='',$namespace=false,$soapAction=false)
2001-07-16 08:05:33 +02:00
{
2001-08-18 16:37:52 +02:00
if($this->endpointType == 'wsdl')
2001-07-16 08:05:33 +02:00
{
2001-08-18 16:37:52 +02:00
// instantiate wsdl class
$this->wsdl = CreateObject('phpgwapi.wsdl',$this->endpoint);
// get portName
if(!$this->portName)
{
$this->portName = $this->wsdl->getPortName($method);
}
// get endpoint
if(!$this->endpoint = $this->wsdl->getEndpoint($this->portName))
{
die("no port of name '$this->portName' in the wsdl at that location!");
}
$this->debug("endpoint: $this->endpoint");
$this->debug("portName: $this->portName");
2001-07-16 08:05:33 +02:00
}
2001-08-18 16:37:52 +02:00
// get soapAction
if(!$soapAction)
2001-07-16 08:05:33 +02:00
{
2001-08-18 16:37:52 +02:00
if($this->endpointType != 'wsdl')
{
die("method call requires soapAction if wsdl is not available!");
}
if(!$soapAction = $this->wsdl->getSoapAction($this->portName,$method))
{
die("no soapAction for operation: $method!");
}
2001-07-16 08:05:33 +02:00
}
2001-08-18 16:37:52 +02:00
$this->debug("soapAction: $soapAction");
// get namespace
if(!$namespace)
2001-07-16 08:05:33 +02:00
{
2001-08-18 16:37:52 +02:00
if($this->endpointType != 'wsdl')
{
die("method call requires namespace if wsdl is not available!");
}
if(!$namespace = $this->wsdl->getNamespace($this->portName,$method))
{
die("no soapAction for operation: $method!");
}
2001-07-16 08:05:33 +02:00
}
2001-08-18 16:37:52 +02:00
$this->debug("namespace: $namespace");
2001-07-16 08:05:33 +02:00
2001-08-18 16:37:52 +02:00
// make message
$soapmsg = CreateObject('phpgwapi.soapmsg',$method,$params,$namespace);
/* _debug_array($soapmsg); */
// instantiate client
$dbg = "calling server at '$this->endpoint'...";
if($soap_client = CreateObject('phpgwapi.soap_client',$this->endpoint))
2001-07-16 08:05:33 +02:00
{
2001-08-18 16:37:52 +02:00
//$soap_client->debug_flag = true;
$this->debug($dbg.'instantiated client successfully');
$this->debug("client data:<br>server: $soap_client->server<br>path: $soap_client->path<br>port: $soap_client->port");
// send
$dbg = "sending msg w/ soapaction '$soapAction'...";
if($return = $soap_client->send($soapmsg,$soapAction))
2001-07-16 08:05:33 +02:00
{
2001-08-18 16:37:52 +02:00
$this->request = $soap_client->outgoing_payload;
$this->response = $soap_client->incoming_payload;
$this->debug($dbg . "sent message successfully and got a '$return' back");
// check for valid response
if(get_class($return) == 'soapval')
2001-07-16 08:05:33 +02:00
{
2001-08-18 16:37:52 +02:00
// fault?
if(eregi('fault',$return->name))
2001-07-16 08:05:33 +02:00
{
2001-08-18 16:37:52 +02:00
$this->debug('got fault');
$faultArray = $return->decode();
@reset($faultArray);
while(list($k,$v) = @each($faultArray))
/* foreach($faultArray as $k => $v) */
{
print "$k = $v<br>";
}
return false;
2001-07-16 08:05:33 +02:00
}
else
{
2001-08-18 16:37:52 +02:00
$returnArray = $return->decode();
if(is_array($returnArray))
{
return array_shift($returnArray);
}
else
{
$this->debug("didn't get array back from decode() for $return->name");
return false;
}
2001-07-16 08:05:33 +02:00
}
}
2001-08-18 16:37:52 +02:00
else
{
$this->debug("didn't get soapval object back from client");
return false;
}
2001-07-16 08:05:33 +02:00
}
else
{
2001-08-18 16:37:52 +02:00
$this->debug('client send/recieve error');
2001-07-16 08:05:33 +02:00
return false;
}
}
}
2001-08-18 16:37:52 +02:00
function debug($string)
2001-07-16 08:05:33 +02:00
{
2001-08-18 16:37:52 +02:00
if($this->debug_flag)
{
print $string . '<br>';
}
2001-07-16 08:05:33 +02:00
}
}
?>