File tree Expand file tree Collapse file tree 4 files changed +24
-12
lines changed Expand file tree Collapse file tree 4 files changed +24
-12
lines changed Original file line number Diff line number Diff line change 4
4
5
5
use Illuminate \Database \Connection as BaseConnection ;
6
6
use Illuminate \Support \Arr ;
7
- use Illuminate \Support \Str ;
8
7
use MongoDB \Client ;
9
8
10
9
class Connection extends BaseConnection
@@ -151,7 +150,7 @@ public function disconnect()
151
150
}
152
151
153
152
/**
154
- * Determine if the given configuration array has a UNIX socket value .
153
+ * Determine if the given configuration array has a dsn string .
155
154
*
156
155
* @param array $config
157
156
* @return bool
@@ -162,22 +161,14 @@ protected function hasDsnString(array $config)
162
161
}
163
162
164
163
/**
165
- * Get the DSN string for a socket configuration.
164
+ * Get the DSN string form configuration.
166
165
*
167
166
* @param array $config
168
167
* @return string
169
168
*/
170
169
protected function getDsnString (array $ config )
171
170
{
172
- $ dsn_string = $ config ['dsn ' ];
173
-
174
- if (Str::contains ($ dsn_string , 'mongodb:// ' )) {
175
- $ dsn_string = Str::replaceFirst ('mongodb:// ' , '' , $ dsn_string );
176
- }
177
-
178
- $ dsn_string = rawurlencode ($ dsn_string );
179
-
180
- return "mongodb:// {$ dsn_string }" ;
171
+ return $ config ['dsn ' ];
181
172
}
182
173
183
174
/**
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ class DsnTest extends TestCase
4
+ {
5
+ public function test_dsn_works ()
6
+ {
7
+ $ this ->assertInstanceOf (\Illuminate \Database \Eloquent \Collection::class, DsnAddress::all ());
8
+ }
9
+ }
10
+
11
+ class DsnAddress extends Address
12
+ {
13
+ protected $ connection = 'dsn_mongodb ' ;
14
+ }
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ protected function getEnvironmentSetUp($app)
51
51
$ app ['config ' ]->set ('database.default ' , 'mongodb ' );
52
52
$ app ['config ' ]->set ('database.connections.mysql ' , $ config ['connections ' ]['mysql ' ]);
53
53
$ app ['config ' ]->set ('database.connections.mongodb ' , $ config ['connections ' ]['mongodb ' ]);
54
+ $ app ['config ' ]->set ('database.connections.dsn_mongodb ' , $ config ['connections ' ]['dsn_mongodb ' ]);
54
55
55
56
$ app ['config ' ]->set ('auth.model ' , 'User ' );
56
57
$ app ['config ' ]->set ('auth.providers.users.model ' , 'User ' );
Original file line number Diff line number Diff line change 11
11
'database ' => 'unittest ' ,
12
12
],
13
13
14
+ 'dsn_mongodb ' => [
15
+ 'driver ' => 'mongodb ' ,
16
+ 'dsn ' => 'mongodb://mongodb:27017 ' ,
17
+ 'database ' => 'unittest ' ,
18
+ ],
19
+
14
20
'mysql ' => [
15
21
'driver ' => 'mysql ' ,
16
22
'host ' => 'mysql ' ,
You can’t perform that action at this time.
0 commit comments