-
Notifications
You must be signed in to change notification settings - Fork 0
/
CURLWSSUserNameTokenSoapClient.class.php
85 lines (68 loc) · 2.57 KB
/
CURLWSSUserNameTokenSoapClient.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?PHP
/*****************************************************/
/* Class: CURLWSSUserNameTokenSoapClient */
/* Author: Martin Holden, SkillSoft */
/* Date: Aug 2018 */
/* */
/* Extends the WSSUserNameTokenSoapClient to use CURL*/
/*****************************************************/
class CURLWSSUserNameTokenSoapClient extends WSSUserNameTokenSoapClient{
private $proxy;
public function __getLastRequestHeaders() {
return implode("\n", $this->__last_request_headers)."\n";
}
public function __construct($endpoint,$options) {
if (array_key_exists("context",$options))
{
$contexts = stream_context_get_options($options["context"]);
$context = $contexts['CURLWSSUserNameTokenSoapClient'];
if (array_key_exists("proxy",$context))
{
$this->proxy=$context["proxy"];
}
}
$result = parent::__construct($endpoint, $options);
return $result;
}
function __doRequest($request, $location, $action, $version) {
$headers = array(
'Method: POST',
'Connection: Keep-Alive',
'User-Agent: PHP-SOAP-CURL',
'Content-Type: text/xml; charset=utf-8',
'SOAPAction: "'.$action.'"',
);
$this->__last_request_headers = $headers;
$ch = curl_init($location);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true );
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//Force TLS 1.2
curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
if (isset($this->proxy)) {
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, false);
if (empty($this->proxy->proxyport)) {
curl_setopt($ch, CURLOPT_PROXY, $this->proxy->proxyhost);
} else {
curl_setopt($ch, CURLOPT_PROXY, $this->proxy->proxyhost.':'.$this->proxy->proxyport);
}
if (!empty($this->proxy->proxyuser) and !empty($this->proxy->proxypassword)) {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $this->proxy->proxyuser.':'.$this->proxy->proxypassword);
if (defined('CURLOPT_PROXYAUTH')) {
// any proxy authentication if PHP 5.1
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC | CURLAUTH_NTLM);
}
}
}
$response = curl_exec($ch);
if($errno = curl_errno($ch)) {
$error_message = curl_strerror($errno);
throw new Exception("[CURLWSSUserNameTokenSoapClient::__doRequest] ({$errno}):\n {$error_message}");
}
return $response;
}
}
?>