ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSoapClient.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
33 define('DEFAULT_TIMEOUT',5);
34 define('DEFAULT_RESPONSE_TIMEOUT',30);
35 
36 if (version_compare(PHP_VERSION, '5.3.0', '>=') or 1)
37 {
38  include_once './webservice/soap/lib2/nusoap.php';
39 }
40 else
41 {
42  include_once './webservice/soap/lib/nusoap.php';
43 }
44 
45 class ilSoapClient
46 {
47  var $server = '';
48  var $timeout = null;
49  var $response_timeout = null;
50  var $use_wsdl = true;
51 
52  function ilSoapClient($a_server = '')
53  {
54  global $ilLog;
55 
56  $this->log =& $ilLog;
57  $this->__setServer($a_server);
58  }
59 
60  function __setServer($a_server)
61  {
62  global $ilSetting;
63 
64  if(strlen($a_server))
65  {
66  return $this->server = $a_server;
67  }
68 
69  if(strlen(trim($ilSetting->get('soap_wsdl_path'))))
70  {
71  return $this->server = trim($ilSetting->get('soap_wsdl_path'));
72  }
73 
74  $this->server = ILIAS_HTTP_PATH.'/webservice/soap/server.php?wsdl';
75  }
76 
77  function getServer()
78  {
79  return $this->server;
80  }
81 
82  function setTimeout($a_timeout)
83  {
84  $this->timeout = $a_timeout;
85  }
86  function getTimeout()
87  {
88  return $this->timeout ? $this->timeout : DEFAULT_TIMEOUT;
89  }
90 
91  function setResponseTimeout($a_timeout)
92  {
93  $this->response_timeout = $a_timeout;
94  }
95  function getResponseTimeout()
96  {
97  return $this->response_timeout;
98  }
99 
100  function enableWSDL($a_status)
101  {
102  $this->use_wsdl = (bool) $a_status;
103  }
104  function enabledWSDL()
105  {
106  return (bool) $this->use_wsdl;
107  }
108 
109  function init()
110  {
111  $this->client = new soap_client($this->getServer(),
112  $this->enabledWSDL(),
113  false, // no proxy support in the moment
114  false,
115  false,
116  false,
117  $this->getTimeout(),
118  $this->getResponseTimeout());
119 
120  if($error = $this->client->getError())
121  {
122  $this->log->write('Error calling soap server: '.$this->getServer().' Error: '.$error);
123  return false;
124  }
125  return true;
126  }
127 
128  function &call($a_operation,$a_params)
129  {
130  $res = $this->client->call($a_operation,$a_params);
131  if($error = $this->client->getError())
132  {
133  $this->log->write('Error calling soap server: '.$this->getServer().' Error: '.$error);
134  }
135 
136  return $res;
137  // Todo cannot check errors here since it's not possible to distinguish between 'timeout' and other errors.
138  }
139 }
140 
141 ?>