19declare(strict_types=1);
47 $this->log =
$DIC->logger()->wsrv();
49 $this->use_wsdl =
true;
52 $this->connect_timeout = $timeout;
54 $this->connect_timeout = $timeout;
66 $this->connect_timeout = $a_timeout;
76 $this->response_timeout = $a_timeout;
86 $this->use_wsdl = $a_stat;
94 public function init(): bool
96 $internal_path = $this->
settings->get(
'soap_internal_wsdl_path');
99 $uri = (new \ILIAS\Data\URI($internal_path));
100 parse_str(
$uri->getQuery() ??
'', $query);
101 $this->uri = (string) (isset($query[
'wsdl']) ?
103 $uri->withQuery(http_build_query(array_merge($query, [
'wsdl' =>
'']))));
104 } elseif (trim($this->
settings->get(
'soap_wsdl_path',
'')) !==
'') {
105 $this->uri = $this->
settings->get(
'soap_wsdl_path',
'');
109 if (PHP_SAPI !==
'cli') {
110 $script_path = dirname(
$_SERVER[
'SCRIPT_FILENAME']);
111 while ($depth < self::MAX_DIRECTORY_SEARCH_DEPTH && !is_file($script_path .
'/ilias.php')) {
112 $parent = dirname($script_path);
113 if ($parent === $script_path) {
116 $script_path = $parent;
121 if ($depth > 0 && is_file($script_path .
'/ilias.php')) {
122 $url_parts = parse_url($request_path);
123 $path = $url_parts[
'path'] ??
'';
124 $path_parts = explode(
'/', rtrim(
$path,
'/'));
125 $path_parts = array_slice($path_parts, 0, -$depth);
126 $new_path = implode(
'/', $path_parts);
128 $request_path = $url_parts[
'scheme'] .
'://' . $url_parts[
'host'];
129 if (isset($url_parts[
'port'])) {
130 $request_path .=
':' . $url_parts[
'port'];
132 $request_path .= $new_path;
135 $this->uri = rtrim($request_path,
'/') .
'/soap/server.php?wsdl';
139 $this->log->debug(
'Using wsdl: ' . $this->
getServer());
140 $this->log->debug(
'Using connection timeout: ' . $this->
getTimeout());
144 $this->
client =
new SoapClient(
147 'exceptions' =>
true,
150 'stream_context' => $this->uri === $internal_path ? stream_context_create([
152 'verify_peer' => (
bool) $this->
settings->get(
'soap_internal_wsdl_verify_peer',
'1'),
153 'verify_peer_name' => (
bool) $this->settings->get(
'soap_internal_wsdl_verify_peer_name',
'1'),
154 'allow_self_signed' => (
bool) $this->settings->get(
'soap_internal_wsdl_allow_self_signed',
''),
160 }
catch (SoapFault $ex) {
161 $this->log->warning(
'Soap init failed with message: ' . $ex->getMessage());
171 $this->stored_socket_timeout = (
int) ini_get(
'default_socket_timeout');
172 $this->log->debug(
'Default socket timeout is: ' . $this->stored_socket_timeout);
175 $this->log->debug(
'WSDL mode, using socket timeout: ' . $this->
getTimeout());
176 ini_set(
'default_socket_timeout', (
string) $this->
getTimeout());
178 $this->log->debug(
'Non WSDL mode, using socket timeout: ' . $this->
getResponseTimeout());
190 ini_set(
'default_socket_timeout', (
string) $this->stored_socket_timeout);
191 $this->log->debug(
'Restoring default socket timeout to: ' . $this->stored_socket_timeout);
200 public function call(
string $a_operation, array $a_params)
202 $this->log->debug(
'Calling webservice: ' . $a_operation);
206 return $this->
client->__call($a_operation, $a_params);
207 }
catch (SoapFault $exception) {
208 $this->log->error(
'Calling webservice failed with message: ' . $exception->getMessage());
209 $this->log->debug((
string) $this->
client->__getLastResponseHeaders());
210 $this->log->debug((
string) $this->
client->__getLastResponse());
212 }
catch (Exception $exception) {
213 $this->log->error(
'Caught unknown exception with message: ' . $exception->getMessage());
214 $this->log->debug((
string) $this->
client->__getLastResponseHeaders());
215 $this->log->debug((
string) $this->
client->__getLastResponse());
Component logger with individual log levels by component id.
call(string $a_operation, array $a_params)
setSocketTimeout(bool $a_wsdl_mode)
int $stored_socket_timeout
setTimeout(int $a_timeout)
const DEFAULT_CONNECT_TIMEOUT
const MAX_DIRECTORY_SEARCH_DEPTH
setResponseTimeout(int $a_timeout)
resetSocketTimeout()
Reset socket default timeout to defaults.
__construct(string $a_uri='')
const DEFAULT_RESPONSE_TIMEOUT