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