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
e8056f53
Commit
e8056f53
authored
Nov 16, 2014
by
David Zuelke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
first stab at supporting database 'url' for connection
tests to come
parent
e35ce048
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
79 additions
and
0 deletions
+79
-0
DriverManager.php
lib/Doctrine/DBAL/DriverManager.php
+79
-0
No files found.
lib/Doctrine/DBAL/DriverManager.php
View file @
e8056f53
...
@@ -51,6 +51,22 @@ final class DriverManager
...
@@ -51,6 +51,22 @@ final class DriverManager
'sqlsrv'
=>
'Doctrine\DBAL\Driver\SQLSrv\Driver'
,
'sqlsrv'
=>
'Doctrine\DBAL\Driver\SQLSrv\Driver'
,
);
);
/**
* List of URL schemes from a database URL and their mappings to driver.
*/
private
static
$_driverSchemeAliases
=
array
(
'db2'
=>
'ibm_db2'
,
'mssql'
=>
'pdo_sqlsrv'
,
'pdo_mssql'
=>
'pdo_sqlsrv'
,
'mysql'
=>
'pdo_mysql'
,
'mysql2'
=>
'pdo_mysql'
,
// Amazon RDS, for some weird reason
'postgres'
=>
'pdo_pgsql'
,
'postgresql'
=>
'pdo_pgsql'
,
'pgsql'
=>
'pdo_pgsql'
,
'sqlite'
=>
'pdo_sqlite'
,
'sqlite3'
=>
'pdo_sqlite'
,
);
/**
/**
* Private constructor. This class cannot be instantiated.
* Private constructor. This class cannot be instantiated.
*/
*/
...
@@ -126,6 +142,8 @@ final class DriverManager
...
@@ -126,6 +142,8 @@ final class DriverManager
$eventManager
=
new
EventManager
();
$eventManager
=
new
EventManager
();
}
}
$params
=
self
::
_parseDatabaseUrl
(
$params
);
// check for existing pdo object
// check for existing pdo object
if
(
isset
(
$params
[
'pdo'
])
&&
!
$params
[
'pdo'
]
instanceof
\PDO
)
{
if
(
isset
(
$params
[
'pdo'
])
&&
!
$params
[
'pdo'
]
instanceof
\PDO
)
{
throw
DBALException
::
invalidPdoInstance
();
throw
DBALException
::
invalidPdoInstance
();
...
@@ -194,4 +212,65 @@ final class DriverManager
...
@@ -194,4 +212,65 @@ final class DriverManager
throw
DBALException
::
invalidDriverClass
(
$params
[
'driverClass'
]);
throw
DBALException
::
invalidDriverClass
(
$params
[
'driverClass'
]);
}
}
}
}
/**
* Extracts parts from a database URL, if present, and returns an
* updated list of parameters.
*
* @param array $params The list of parameters.
*
* @param array A modified list of parameters with info from a database
* URL extracted into indidivual parameter parts.
*
*/
private
static
function
_parseDatabaseUrl
(
array
$params
)
{
if
(
!
isset
(
$params
[
'url'
]))
{
return
;
}
// (pdo_)?sqlite3?:///... => (pdo_)?sqlite3?://localhost/... or else the URL will be invalid
$url
=
preg_replace
(
'#^((?:pdo_)?sqlite3?):///#'
,
'$1://localhost/'
,
$url
);
$url
=
parse_url
(
$params
[
'url'
]);
if
(
$url
===
false
)
{
throw
new
DBALException
(
'Malformed parameter "url".'
);
}
if
(
isset
(
$url
[
'scheme'
]))
{
if
(
isset
(
self
::
$_driverSchemeAliases
[
$url
[
'scheme'
]]))
{
$params
[
'driver'
]
=
self
::
$_driverSchemeAliases
[
$url
[
'scheme'
]];
// use alias
}
else
{
$params
[
'driver'
]
=
$url
[
'scheme'
];
// let's see what checkParams() says about it later
}
}
if
(
isset
(
$url
[
'host'
]))
{
$params
[
'host'
]
=
$url
[
'host'
];
}
if
(
isset
(
$url
[
'port'
]))
{
$params
[
'port'
]
=
$url
[
'port'
];
}
if
(
isset
(
$url
[
'user'
]))
{
$params
[
'user'
]
=
$url
[
'user'
];
}
if
(
isset
(
$url
[
'pass'
]))
{
$params
[
'password'
]
=
$url
[
'pass'
];
}
if
(
isset
(
$url
[
'path'
]))
{
if
(
!
isset
(
$url
[
'scheme'
])
||
(
strpos
(
$url
[
'scheme'
],
'sqlite'
)
!==
false
&&
$url
[
'path'
]
==
':memory:'
))
{
$params
[
'dbname'
]
=
$url
[
'path'
];
// if the URL was just "sqlite::memory:", which parses to scheme and path only
}
else
{
$params
[
'dbname'
]
=
substr
(
$url
[
'path'
],
1
);
// strip the leading slash from the URL
}
}
if
(
isset
(
$url
[
'query'
]))
{
$query
=
array
();
parse_str
(
$url
[
'query'
],
$query
);
// simply ingest query as extra params, e.g. charset or sslmode
$params
=
array_merge
(
$params
,
$query
);
// parse_str wipes existing array elements
}
}
}
}
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