Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-mongodb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
laravel-mongodb
Commits
da9f4a1a
Unverified
Commit
da9f4a1a
authored
Jan 08, 2018
by
Jens Segers
Committed by
GitHub
Jan 08, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1397 from DMNSteve/1396
fix: fixes dsn connection strings by url encoding
parents
f12f766d
b1ed1667
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
6 deletions
+45
-6
Connection.php
src/Jenssegers/Mongodb/Connection.php
+45
-6
No files found.
src/Jenssegers/Mongodb/Connection.php
View file @
da9f4a1a
...
...
@@ -4,6 +4,7 @@ namespace Jenssegers\Mongodb;
use
Illuminate\Database\Connection
as
BaseConnection
;
use
Illuminate\Support\Arr
;
use
Illuminate\Support\Str
;
use
MongoDB\Client
;
class
Connection
extends
BaseConnection
...
...
@@ -150,18 +151,43 @@ class Connection extends BaseConnection
}
/**
*
Create a DSN string from a configuration
.
*
Determine if the given configuration array has a UNIX socket value
.
*
* @param array $config
* @param array $config
* @return bool
*/
protected
function
hasDsnString
(
array
$config
)
{
return
isset
(
$config
[
'dsn'
])
&&
!
empty
(
$config
[
'dsn'
]);
}
/**
* Get the DSN string for a socket configuration.
*
* @param array $config
* @return string
*/
protected
function
getDsn
(
array
$config
)
protected
function
getDsn
String
(
array
$config
)
{
// Check if the user passed a complete dsn to the configuration.
if
(
!
empty
(
$config
[
'dsn'
]))
{
return
$config
[
'dsn'
];
$dsn_string
=
$config
[
'dsn'
];
if
(
Str
::
contains
(
$dsn_string
,
'mongodb://'
)
){
$dsn_string
=
Str
::
replaceFirst
(
'mongodb://'
,
''
,
$dsn_string
);
}
$dsn_string
=
rawurlencode
(
$dsn_string
);
return
"mongodb://
{
$dsn_string
}
"
;
}
/**
* Get the DSN string for a host / port configuration.
*
* @param array $config
* @return string
*/
protected
function
getHostDsn
(
array
$config
)
{
// Treat host option as array of hosts
$hosts
=
is_array
(
$config
[
'host'
])
?
$config
[
'host'
]
:
[
$config
[
'host'
]];
...
...
@@ -178,6 +204,19 @@ class Connection extends BaseConnection
return
'mongodb://'
.
implode
(
','
,
$hosts
)
.
(
$auth_database
?
'/'
.
$auth_database
:
''
);
}
/**
* Create a DSN string from a configuration.
*
* @param array $config
* @return string
*/
protected
function
getDsn
(
array
$config
)
{
return
$this
->
hasDsnString
(
$config
)
?
$this
->
getDsnString
(
$config
)
:
$this
->
getHostDsn
(
$config
);
}
/**
* @inheritdoc
*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment