@@ -17,19 +17,19 @@ class AmqpConnectionFactory implements PsrConnectionFactory
17
17
private $ connection ;
18
18
19
19
/**
20
- * The config could be an array, string DSN or null. In case of null it will attempt to connect to localhost with default credentials
20
+ * The config could be an array, string DSN or null. In case of null it will attempt to connect to localhost with default credentials.
21
21
*
22
22
* [
23
- * 'host' => amqp.host The host to connect too. Note: Max 1024 characters.
24
- * 'port' => amqp.port Port on the host.
25
- * 'vhost' => amqp.vhost The virtual host on the host. Note: Max 128 characters.
26
- * 'user' => amqp.user The user name to use. Note: Max 128 characters.
27
- * 'pass' => amqp.password Password. Note: Max 128 characters.
28
- * 'read_timeout' => Timeout in for income activity. Note: 0 or greater seconds. May be fractional.
29
- * 'write_timeout' => Timeout in for outcome activity. Note: 0 or greater seconds. May be fractional.
30
- * 'connect_timeout' => Connection timeout. Note: 0 or greater seconds. May be fractional.
31
- * 'persisted' => bool, Whether it use single persisted connection or open a new one for every context
32
- * 'lazy' => the connection will be performed as later as possible, if the option set to true
23
+ * 'host' => ' amqp.host The host to connect too. Note: Max 1024 characters.',
24
+ * 'port' => ' amqp.port Port on the host.',
25
+ * 'vhost' => ' amqp.vhost The virtual host on the host. Note: Max 128 characters.',
26
+ * 'user' => ' amqp.user The user name to use. Note: Max 128 characters.',
27
+ * 'pass' => ' amqp.password Password. Note: Max 128 characters.',
28
+ * 'read_timeout' => ' Timeout in for income activity. Note: 0 or greater seconds. May be fractional.',
29
+ * 'write_timeout' => ' Timeout in for outcome activity. Note: 0 or greater seconds. May be fractional.',
30
+ * 'connect_timeout' => ' Connection timeout. Note: 0 or greater seconds. May be fractional.',
31
+ * 'persisted' => ' bool, Whether it use single persisted connection or open a new one for every context',
32
+ * 'lazy' => ' the connection will be performed as later as possible, if the option set to true',
33
33
* ]
34
34
*
35
35
* or
@@ -40,13 +40,13 @@ class AmqpConnectionFactory implements PsrConnectionFactory
40
40
*/
41
41
public function __construct ($ config = 'amqp:// ' )
42
42
{
43
- if (empty ($ config )) {
43
+ if (empty ($ config ) || ' amqp:// ' === $ config ) {
44
44
$ config = [];
45
- } else if (is_string ($ config )) {
45
+ } elseif (is_string ($ config )) {
46
46
$ config = $ this ->parseDsn ($ config );
47
- } else if (is_array ($ config )) {
47
+ } elseif (is_array ($ config )) {
48
48
} else {
49
- throw new \LogicException ('The config must be eaither an array of options, a DSN string or null ' );
49
+ throw new \LogicException ('The config must be either an array of options, a DSN string or null ' );
50
50
}
51
51
52
52
$ this ->config = array_replace ($ this ->defaultConfig (), $ config );
@@ -82,7 +82,6 @@ private function establishConnection()
82
82
83
83
$ this ->config ['persisted ' ] ? $ this ->connection ->pconnect () : $ this ->connection ->connect ();
84
84
}
85
-
86
85
if (false == $ this ->connection ->isConnected ()) {
87
86
$ this ->config ['persisted ' ] ? $ this ->connection ->preconnect () : $ this ->connection ->reconnect ();
88
87
}
@@ -97,10 +96,6 @@ private function establishConnection()
97
96
*/
98
97
private function parseDsn ($ dsn )
99
98
{
100
- if ('amqp:// ' == $ dsn ) {
101
- return [];
102
- }
103
-
104
99
$ dsnConfig = parse_url ($ dsn );
105
100
if (false === $ dsnConfig ) {
106
101
throw new \LogicException (sprintf ('Failed to parse DSN "%s" ' , $ dsn ));
@@ -130,9 +125,8 @@ private function parseDsn($dsn)
130
125
131
126
unset($ dsnConfig ['scheme ' ], $ dsnConfig ['query ' ], $ dsnConfig ['fragment ' ], $ dsnConfig ['path ' ]);
132
127
133
-
134
128
$ config = array_replace ($ this ->defaultConfig (), $ dsnConfig );
135
- $ config = array_map (function ($ value ) {
129
+ $ config = array_map (function ($ value ) {
136
130
return urldecode ($ value );
137
131
}, $ config );
138
132
0 commit comments