Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Tomáš Trávníček
doctrine-dbal
Commits
09aadef8
Commit
09aadef8
authored
Jun 29, 2018
by
Christophe Coevoet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix support for URL to account for master-slave and pooling-shard connections
parent
402bbcf0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
93 additions
and
0 deletions
+93
-0
DriverManager.php
lib/Doctrine/DBAL/DriverManager.php
+22
-0
DriverManagerTest.php
tests/Doctrine/Tests/DBAL/DriverManagerTest.php
+71
-0
No files found.
lib/Doctrine/DBAL/DriverManager.php
View file @
09aadef8
...
...
@@ -155,6 +155,28 @@ final class DriverManager
$params
=
self
::
parseDatabaseUrl
(
$params
);
// URL support for MasterSlaveConnection
if
(
isset
(
$params
[
'master'
]))
{
$params
[
'master'
]
=
self
::
parseDatabaseUrl
(
$params
[
'master'
]);
}
if
(
isset
(
$params
[
'slaves'
]))
{
foreach
(
$params
[
'slaves'
]
as
$key
=>
$slaveParams
)
{
$params
[
'slaves'
][
$key
]
=
self
::
parseDatabaseUrl
(
$slaveParams
);
}
}
// URL support for PoolingShardConnection
if
(
isset
(
$params
[
'global'
]))
{
$params
[
'global'
]
=
self
::
parseDatabaseUrl
(
$params
[
'global'
]);
}
if
(
isset
(
$params
[
'shards'
]))
{
foreach
(
$params
[
'shards'
]
as
$key
=>
$shardParams
)
{
$params
[
'shards'
][
$key
]
=
self
::
parseDatabaseUrl
(
$shardParams
);
}
}
// check for existing pdo object
if
(
isset
(
$params
[
'pdo'
])
&&
!
$params
[
'pdo'
]
instanceof
\PDO
)
{
throw
DBALException
::
invalidPdoInstance
();
...
...
tests/Doctrine/Tests/DBAL/DriverManagerTest.php
View file @
09aadef8
...
...
@@ -2,12 +2,15 @@
namespace
Doctrine\Tests\DBAL
;
use
Doctrine\DBAL\Connections\MasterSlaveConnection
;
use
Doctrine\DBAL\DBALException
;
use
Doctrine\DBAL\Driver\DrizzlePDOMySql\Driver
as
DrizzlePDOMySqlDriver
;
use
Doctrine\DBAL\Driver\PDOMySql\Driver
as
PDOMySQLDriver
;
use
Doctrine\DBAL\Driver\PDOSqlite\Driver
as
PDOSqliteDriver
;
use
Doctrine\DBAL\Driver\SQLSrv\Driver
as
SQLSrvDriver
;
use
Doctrine\DBAL\DriverManager
;
use
Doctrine\DBAL\Sharding\PoolingShardConnection
;
use
Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser
;
use
Doctrine\Tests\DBAL\Mocks\MockPlatform
;
use
Doctrine\Tests\DbalTestCase
;
use
Doctrine\Tests\Mocks\ConnectionMock
;
...
...
@@ -133,6 +136,74 @@ class DriverManagerTest extends DbalTestCase
self
::
assertInstanceOf
(
PDOMySQLDriver
::
class
,
$conn
->
getDriver
());
}
public
function
testDatabaseUrlMasterSlave
()
{
$options
=
[
'driver'
=>
'pdo_mysql'
,
'master'
=>
[
'url'
=>
'mysql://foo:bar@localhost:11211/baz'
],
'slaves'
=>
[
'slave1'
=>
[
'url'
=>
'mysql://foo:bar@localhost:11211/baz_slave'
],
],
'wrapperClass'
=>
MasterSlaveConnection
::
class
,
];
$conn
=
DriverManager
::
getConnection
(
$options
);
$params
=
$conn
->
getParams
();
self
::
assertInstanceOf
(
PDOMySQLDriver
::
class
,
$conn
->
getDriver
());
$expected
=
[
'user'
=>
'foo'
,
'password'
=>
'bar'
,
'host'
=>
'localhost'
,
'port'
=>
11211
,
];
foreach
(
$expected
as
$key
=>
$value
)
{
self
::
assertEquals
(
$value
,
$params
[
'master'
][
$key
]);
self
::
assertEquals
(
$value
,
$params
[
'slaves'
][
'slave1'
][
$key
]);
}
self
::
assertEquals
(
'baz'
,
$params
[
'master'
][
'dbname'
]);
self
::
assertEquals
(
'baz_slave'
,
$params
[
'slaves'
][
'slave1'
][
'dbname'
]);
}
public
function
testDatabaseUrlShard
()
{
$options
=
[
'driver'
=>
'pdo_mysql'
,
'shardChoser'
=>
MultiTenantShardChoser
::
class
,
'global'
=>
[
'url'
=>
'mysql://foo:bar@localhost:11211/baz'
],
'shards'
=>
[
[
'id'
=>
1
,
'url'
=>
'mysql://foo:bar@localhost:11211/baz_slave'
,
],
],
'wrapperClass'
=>
PoolingShardConnection
::
class
,
];
$conn
=
DriverManager
::
getConnection
(
$options
);
$params
=
$conn
->
getParams
();
self
::
assertInstanceOf
(
PDOMySQLDriver
::
class
,
$conn
->
getDriver
());
$expected
=
[
'user'
=>
'foo'
,
'password'
=>
'bar'
,
'host'
=>
'localhost'
,
'port'
=>
11211
,
];
foreach
(
$expected
as
$key
=>
$value
)
{
self
::
assertEquals
(
$value
,
$params
[
'global'
][
$key
]);
self
::
assertEquals
(
$value
,
$params
[
'shards'
][
0
][
$key
]);
}
self
::
assertEquals
(
'baz'
,
$params
[
'global'
][
'dbname'
]);
self
::
assertEquals
(
'baz_slave'
,
$params
[
'shards'
][
0
][
'dbname'
]);
}
/**
* @dataProvider databaseUrls
*/
...
...
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