|
1
|
|
|
<?php |
|
2
|
|
|
namespace Disque\Connection; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Identify a Disque server we can connect to |
|
6
|
|
|
* |
|
7
|
|
|
* @package Disque\Connection |
|
8
|
|
|
*/ |
|
9
|
|
|
class Credentials |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* A sprintf format for creating a node address |
|
13
|
|
|
*/ |
|
14
|
|
|
const ADDRESS_FORMAT = '%s:%d'; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var string A Disque server host or IP address |
|
18
|
|
|
*/ |
|
19
|
|
|
private $host; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var int The server port |
|
23
|
|
|
*/ |
|
24
|
|
|
private $port; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var string|null The password if set for this server |
|
28
|
|
|
*/ |
|
29
|
|
|
private $password; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var int|null The maximum seconds to wait for a connection to the server |
|
33
|
|
|
*/ |
|
34
|
|
|
private $connectionTimeout; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var int|null The maximum seconds to wait for a response from the server |
|
38
|
|
|
*/ |
|
39
|
|
|
private $responseTimeout; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param string $host |
|
43
|
|
|
* @param int $port |
|
44
|
|
|
* @param string|null $password |
|
45
|
|
|
* @param int|null $connectionTimeout |
|
46
|
|
|
* @param int|null $responseTimeout |
|
47
|
|
|
*/ |
|
48
|
|
|
public function __construct( |
|
49
|
|
|
$host, |
|
50
|
|
|
$port, |
|
51
|
|
|
$password = null, |
|
52
|
|
|
$connectionTimeout = null, |
|
53
|
|
|
$responseTimeout = null |
|
54
|
|
|
) { |
|
55
|
|
|
$this->host = $host; |
|
56
|
|
|
$this->port = $port; |
|
57
|
|
|
$this->password = $password; |
|
58
|
|
|
$this->connectionTimeout = $connectionTimeout; |
|
59
|
|
|
$this->responseTimeout = $responseTimeout; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Get the server host |
|
64
|
|
|
* |
|
65
|
|
|
* @return string |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getHost() |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->host; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Get the server port |
|
74
|
|
|
* |
|
75
|
|
|
* @return int |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getPort() |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->port; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Get the server address |
|
84
|
|
|
* @return string |
|
85
|
|
|
*/ |
|
86
|
|
|
public function getAddress() |
|
87
|
|
|
{ |
|
88
|
|
|
return sprintf(self::ADDRESS_FORMAT, $this->host, $this->port); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Get the password needed to connect to the server |
|
93
|
|
|
* |
|
94
|
|
|
* Passwords in Disque are optional, servers should be secured in other ways |
|
95
|
|
|
* |
|
96
|
|
|
* @return null|string |
|
97
|
|
|
*/ |
|
98
|
|
|
public function getPassword() |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->password; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Check if the credentials have a password set |
|
105
|
|
|
* |
|
106
|
|
|
* @return bool |
|
107
|
|
|
*/ |
|
108
|
|
|
public function havePassword() |
|
109
|
|
|
{ |
|
110
|
|
|
return !empty($this->password); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Get the maximum time in seconds to wait for a server connection |
|
115
|
|
|
* |
|
116
|
|
|
* @return int|null |
|
117
|
|
|
*/ |
|
118
|
|
|
public function getConnectionTimeout() |
|
119
|
|
|
{ |
|
120
|
|
|
return $this->connectionTimeout; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Get the maximum time in seconds to wait for any server response |
|
125
|
|
|
* |
|
126
|
|
|
* @return int|null |
|
127
|
|
|
*/ |
|
128
|
|
|
public function getResponseTimeout() |
|
129
|
|
|
{ |
|
130
|
|
|
return $this->responseTimeout; |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|