1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpAmqpLib\Connection; |
4
|
|
|
|
5
|
|
|
class AMQPSSLConnection extends AMQPStreamConnection |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* @param string $host |
9
|
|
|
* @param int $port |
10
|
|
|
* @param string $user |
11
|
|
|
* @param string $password |
12
|
|
|
* @param string $vhost |
13
|
|
|
* @param array $ssl_options |
14
|
|
|
* @param array $options |
15
|
|
|
* @param AMQPConnectionConfig|null $config |
16
|
|
|
* @throws \Exception |
17
|
|
|
*/ |
18
|
3 |
|
public function __construct( |
19
|
|
|
$host, |
20
|
|
|
$port, |
21
|
|
|
$user, |
22
|
|
|
$password, |
23
|
|
|
$vhost = '/', |
24
|
|
|
$ssl_options = array(), |
25
|
|
|
$options = array(), |
26
|
|
|
?AMQPConnectionConfig $config = null |
27
|
|
|
) { |
28
|
|
|
if (empty($ssl_options)) { |
29
|
3 |
|
trigger_error('Using non-TLS instances of AMQPSSLConnection is deprecated and will be removed in version 4 of php-amqplib', E_USER_DEPRECATED); |
30
|
3 |
|
$ssl_context = null; |
31
|
|
|
} else { |
32
|
|
|
$ssl_context = $this->createSslContext($ssl_options); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
parent::__construct( |
|
|
|
|
36
|
3 |
|
$host, |
37
|
3 |
|
$port, |
38
|
3 |
|
$user, |
39
|
3 |
|
$password, |
40
|
3 |
|
$vhost, |
41
|
3 |
|
isset($options['insist']) ? $options['insist'] : false, |
42
|
|
|
isset($options['login_method']) ? $options['login_method'] : 'AMQPLAIN', |
43
|
3 |
|
isset($options['login_response']) ? $options['login_response'] : null, |
44
|
3 |
|
isset($options['locale']) ? $options['locale'] : 'en_US', |
45
|
3 |
|
isset($options['connection_timeout']) ? $options['connection_timeout'] : 3, |
46
|
|
|
isset($options['read_write_timeout']) ? $options['read_write_timeout'] : 130, |
47
|
|
|
$ssl_context, |
48
|
|
|
isset($options['keepalive']) ? $options['keepalive'] : false, |
49
|
|
|
isset($options['heartbeat']) ? $options['heartbeat'] : 0, |
50
|
|
|
isset($options['channel_rpc_timeout']) ? $options['channel_rpc_timeout'] : 0.0, |
51
|
|
|
$config |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @deprecated Use AmqpConnectionFactory |
57
|
|
|
* @throws \Exception |
58
|
|
|
*/ |
59
|
|
|
public static function try_create_connection($host, $port, $user, $password, $vhost, $options) |
60
|
|
|
{ |
61
|
|
|
$ssl_options = isset($options['ssl_options']) ? $options['ssl_options'] : []; |
62
|
|
|
return new static($host, $port, $user, $password, $vhost, $ssl_options, $options); |
63
|
|
|
} |
64
|
3 |
|
|
65
|
|
|
/** |
66
|
3 |
|
* @param array $options |
67
|
3 |
|
* @return resource |
68
|
3 |
|
*/ |
69
|
|
|
private function createSslContext($options) |
70
|
|
|
{ |
71
|
3 |
|
$ssl_context = stream_context_create(); |
72
|
|
|
foreach ($options as $k => $v) { |
73
|
|
|
// Note: 'ssl' applies to 'tls' as well |
74
|
|
|
// https://www.php.net/manual/en/context.ssl.php |
75
|
|
|
stream_context_set_option($ssl_context, 'ssl', $k, $v); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $ssl_context; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|