Skip to content

Commit 459d7e8

Browse files
committed
applied pull request mongodb#1457
1 parent 9df75b7 commit 459d7e8

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

src/Jenssegers/Mongodb/Connection.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Illuminate\Database\Connection as BaseConnection;
66
use Illuminate\Support\Arr;
7-
use Illuminate\Support\Str;
87
use MongoDB\Client;
98

109
class Connection extends BaseConnection
@@ -151,7 +150,7 @@ public function disconnect()
151150
}
152151

153152
/**
154-
* Determine if the given configuration array has a UNIX socket value.
153+
* Determine if the given configuration array has a dsn string.
155154
*
156155
* @param array $config
157156
* @return bool
@@ -162,22 +161,14 @@ protected function hasDsnString(array $config)
162161
}
163162

164163
/**
165-
* Get the DSN string for a socket configuration.
164+
* Get the DSN string form configuration.
166165
*
167166
* @param array $config
168167
* @return string
169168
*/
170169
protected function getDsnString(array $config)
171170
{
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'];
181172
}
182173

183174
/**

tests/DsnTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
}

tests/TestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ protected function getEnvironmentSetUp($app)
5151
$app['config']->set('database.default', 'mongodb');
5252
$app['config']->set('database.connections.mysql', $config['connections']['mysql']);
5353
$app['config']->set('database.connections.mongodb', $config['connections']['mongodb']);
54+
$app['config']->set('database.connections.dsn_mongodb', $config['connections']['dsn_mongodb']);
5455

5556
$app['config']->set('auth.model', 'User');
5657
$app['config']->set('auth.providers.users.model', 'User');

tests/config/database.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
'database' => 'unittest',
1212
],
1313

14+
'dsn_mongodb' => [
15+
'driver' => 'mongodb',
16+
'dsn' => 'mongodb://mongodb:27017',
17+
'database' => 'unittest',
18+
],
19+
1420
'mysql' => [
1521
'driver' => 'mysql',
1622
'host' => 'mysql',

0 commit comments

Comments
 (0)