[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/phpgwapi/inc/ -> class.soapclient.inc.php (source)

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


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7