|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PhpEws\Ntlm; |
|
4
|
|
|
|
|
5
|
|
|
use PhpEws\Exception\EwsException; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Handles Soap communication with the Exchnage server using NTLM |
|
9
|
|
|
* authentication |
|
10
|
|
|
* |
|
11
|
|
|
* @author James I. Armes <[email protected]> |
|
12
|
|
|
*/ |
|
13
|
|
|
class ExchangeSoapClient extends NtlmSoapClient |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Username for authentication on the exchnage server |
|
17
|
|
|
* |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $user; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Password for authentication on the exchnage server |
|
24
|
|
|
* |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $password; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Constructor |
|
31
|
|
|
* |
|
32
|
|
|
* @param string $wsdl |
|
33
|
|
|
* @param array $options |
|
34
|
|
|
* |
|
35
|
|
|
* @throws EwsException If $options does not contain username and password |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct($wsdl, $options) |
|
38
|
|
|
{ |
|
39
|
|
|
// Verify that a user name and password were entered. |
|
40
|
|
|
if (empty($options['user']) || empty($options['password'])) { |
|
41
|
|
|
throw new EwsException('A username and password is required.'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
// Set the username and password properties. |
|
45
|
|
|
$this->user = $options['user']; |
|
46
|
|
|
$this->password = $options['password']; |
|
47
|
|
|
|
|
48
|
|
|
// If a version was set then add it to the headers. |
|
49
|
|
|
if (!empty($options['version'])) { |
|
50
|
|
|
$this->__default_headers[] = new \SoapHeader( |
|
|
|
|
|
|
51
|
|
|
'http://schemas.microsoft.com/exchange/services/2006/types', |
|
52
|
|
|
'RequestServerVersion Version="' . $options['version'] . '"' |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
// If impersonation was set then add it to the headers. |
|
57
|
|
|
if (!empty($options['impersonation'])) { |
|
58
|
|
|
$this->__default_headers[] = new \SoapHeader( |
|
59
|
|
|
'http://schemas.microsoft.com/exchange/services/2006/types', |
|
60
|
|
|
'ExchangeImpersonation', |
|
61
|
|
|
$options['impersonation'] |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
parent::__construct($wsdl, $options); |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Returns the response code from the last request |
|
70
|
|
|
* |
|
71
|
|
|
* @return integer |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getResponseCode() |
|
74
|
|
|
{ |
|
75
|
|
|
return curl_getinfo($this->ch, CURLINFO_HTTP_CODE); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: