File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -111,20 +111,26 @@ protected function getDsn(array $config)
111111 // Treat host option as array of hosts
112112 $ hosts = is_array ($ config ['host ' ]) ? $ config ['host ' ] : array ($ config ['host ' ]);
113113
114+ // Add ports to hosts
114115 foreach ($ hosts as &$ host )
115116 {
116- if (isset ($ config ['username ' ]) and isset ($ config ['password ' ]))
117- {
118- $ host = "{$ username }: {$ password }@ {$ host }" ;
119- }
120-
121117 if (isset ($ config ['port ' ]))
122118 {
123119 $ host = "{$ host }: {$ port }" ;
124120 }
125121 }
126122
127- return "mongodb:// " . implode (', ' , $ hosts ) . "/ {$ database }" ;
123+ // Credentials
124+ if (isset ($ config ['username ' ]) and isset ($ config ['password ' ]))
125+ {
126+ $ credentials = "{$ username }: {$ password }@ " ;
127+ }
128+ else
129+ {
130+ $ credentials = '' ;
131+ }
132+
133+ return "mongodb:// {$ credentials }" . implode (', ' , $ hosts ) . "/ {$ database }" ;
128134 }
129135
130136 /**
You can’t perform that action at this time.
0 commit comments