Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
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
PSDI Army
yii2
Commits
ec2df146
Commit
ec2df146
authored
Nov 27, 2013
by
Paul Klimov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mongo Connection updated allowing to fetch default database name from options.
parent
6eeeb6d1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
4 deletions
+10
-4
Connection.php
extensions/mongo/Connection.php
+3
-1
ConnectionTest.php
tests/unit/extensions/mongo/ConnectionTest.php
+6
-0
MongoTestCase.php
tests/unit/extensions/mongo/MongoTestCase.php
+1
-3
No files found.
extensions/mongo/Connection.php
View file @
ec2df146
...
@@ -85,7 +85,9 @@ class Connection extends Component
...
@@ -85,7 +85,9 @@ class Connection extends Component
protected
function
fetchDefaultDatabaseName
()
protected
function
fetchDefaultDatabaseName
()
{
{
if
(
$this
->
defaultDatabaseName
===
null
)
{
if
(
$this
->
defaultDatabaseName
===
null
)
{
if
(
preg_match
(
'/^mongodb:\\/\\/.+\\/(.+)$/s'
,
$this
->
dsn
,
$matches
))
{
if
(
isset
(
$this
->
options
[
'db'
]))
{
$this
->
defaultDatabaseName
=
$this
->
options
[
'db'
];
}
elseif
(
preg_match
(
'/^mongodb:\\/\\/.+\\/(.+)$/s'
,
$this
->
dsn
,
$matches
))
{
$this
->
defaultDatabaseName
=
$matches
[
1
];
$this
->
defaultDatabaseName
=
$matches
[
1
];
}
else
{
}
else
{
throw
new
InvalidConfigException
(
"Unable to determine default database name from dsn."
);
throw
new
InvalidConfigException
(
"Unable to determine default database name from dsn."
);
...
...
tests/unit/extensions/mongo/ConnectionTest.php
View file @
ec2df146
...
@@ -71,6 +71,12 @@ class ConnectionTest extends MongoTestCase
...
@@ -71,6 +71,12 @@ class ConnectionTest extends MongoTestCase
$this
->
assertTrue
(
$database
instanceof
Database
,
'Unable to get default database!'
);
$this
->
assertTrue
(
$database
instanceof
Database
,
'Unable to get default database!'
);
$connection
=
new
Connection
();
$connection
=
new
Connection
();
$connection
->
dsn
=
$this
->
mongoConfig
[
'dsn'
];
$connection
->
options
=
[
'db'
=>
$this
->
mongoConfig
[
'defaultDatabaseName'
]];
$database
=
$connection
->
getDatabase
();
$this
->
assertTrue
(
$database
instanceof
Database
,
'Unable to determine default database from options!'
);
$connection
=
new
Connection
();
$connection
->
dsn
=
$this
->
mongoConfig
[
'dsn'
]
.
'/'
.
$this
->
mongoConfig
[
'defaultDatabaseName'
];
$connection
->
dsn
=
$this
->
mongoConfig
[
'dsn'
]
.
'/'
.
$this
->
mongoConfig
[
'defaultDatabaseName'
];
$database
=
$connection
->
getDatabase
();
$database
=
$connection
->
getDatabase
();
$this
->
assertTrue
(
$database
instanceof
Database
,
'Unable to determine default database from dsn!'
);
$this
->
assertTrue
(
$database
instanceof
Database
,
'Unable to determine default database from dsn!'
);
...
...
tests/unit/extensions/mongo/MongoTestCase.php
View file @
ec2df146
...
@@ -77,9 +77,7 @@ class MongoTestCase extends TestCase
...
@@ -77,9 +77,7 @@ class MongoTestCase extends TestCase
}
}
$db
=
new
Connection
;
$db
=
new
Connection
;
$db
->
dsn
=
$this
->
mongoConfig
[
'dsn'
];
$db
->
dsn
=
$this
->
mongoConfig
[
'dsn'
];
if
(
isset
(
$this
->
mongoConfig
[
'defaultDatabaseName'
]))
{
$db
->
defaultDatabaseName
=
$this
->
mongoConfig
[
'defaultDatabaseName'
];
$db
->
defaultDatabaseName
=
$this
->
mongoConfig
[
'defaultDatabaseName'
];
}
if
(
isset
(
$this
->
mongoConfig
[
'options'
]))
{
if
(
isset
(
$this
->
mongoConfig
[
'options'
]))
{
$db
->
options
=
$this
->
mongoConfig
[
'options'
];
$db
->
options
=
$this
->
mongoConfig
[
'options'
];
}
}
...
...
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