@@ -150,18 +150,37 @@ public function disconnect()
150
150
}
151
151
152
152
/**
153
- * Create a DSN string from a configuration .
153
+ * Determine if the given configuration array has a UNIX socket value .
154
154
*
155
- * @param array $config
155
+ * @param array $config
156
+ * @return bool
157
+ */
158
+ protected function hasDsnString (array $ config )
159
+ {
160
+ return isset ($ config ['dsn ' ]) && ! empty ($ config ['dsn ' ]);
161
+ }
162
+
163
+ /**
164
+ * Get the DSN string for a socket configuration.
165
+ *
166
+ * @param array $config
156
167
* @return string
157
168
*/
158
- protected function getDsn (array $ config )
169
+ protected function getDsnString (array $ config )
159
170
{
160
- // Check if the user passed a complete dsn to the configuration.
161
- if (! empty ( $ config [ ' dsn ' ])) {
162
- return $ config [ ' dsn ' ] ;
163
- }
171
+ $ dsn = rawurlencode ( $ config [ ' dsn ' ]);
172
+
173
+ return " mongodb:// { $ dsn}" ;
174
+ }
164
175
176
+ /**
177
+ * Get the DSN string for a host / port configuration.
178
+ *
179
+ * @param array $config
180
+ * @return string
181
+ */
182
+ protected function getHostDsn (array $ config )
183
+ {
165
184
// Treat host option as array of hosts
166
185
$ hosts = is_array ($ config ['host ' ]) ? $ config ['host ' ] : [$ config ['host ' ]];
167
186
@@ -178,6 +197,19 @@ protected function getDsn(array $config)
178
197
return 'mongodb:// ' . implode (', ' , $ hosts ) . ($ auth_database ? '/ ' . $ auth_database : '' );
179
198
}
180
199
200
+ /**
201
+ * Create a DSN string from a configuration.
202
+ *
203
+ * @param array $config
204
+ * @return string
205
+ */
206
+ protected function getDsn (array $ config )
207
+ {
208
+ return $ this ->hasDsnString ($ config )
209
+ ? $ this ->getDsnString ($ config )
210
+ : $ this ->getHostDsn ($ config );
211
+ }
212
+
181
213
/**
182
214
* @inheritdoc
183
215
*/
0 commit comments