Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standalone DSN parser #5843

Merged
merged 1 commit into from
Dec 31, 2022
Merged

Standalone DSN parser #5843

merged 1 commit into from
Dec 31, 2022

Conversation

derrabus
Copy link
Member

@derrabus derrabus commented Dec 30, 2022

Q A
Type feature
Fixed issues #5814, symfony/recipes#1139 (comment)

Summary

See the linked issue for details and motivation.

This PR extracts the parsing of the url config param into a dedicated class. This allows to configure how we map URL schemes to DBAL drivers before we parse a database URL. The idea is that DriverManager becomes unaware of database URLs entirely, giving the app full control over:

  • which drivers should be used for which database engine,
  • which connection parameters a URL is allowed to provide, and
  • how connection parameters are merged with other configuration sources.

This also obsoletes the deprecation introduced by #5697: Once DriverManager does not parse database URLs anymore, the mapping from schemes to drivers becomes a userland concern or a concern of the integration layer (e.g. DoctrineBundle).

@derrabus derrabus mentioned this pull request Dec 30, 2022
@derrabus derrabus marked this pull request as ready for review December 30, 2022 13:25
@derrabus derrabus added this to the 3.6.0 milestone Dec 30, 2022
@derrabus derrabus changed the title Extract DSN parsing into a dedicated class Standalone DSN parser Dec 30, 2022
src/Exception/MalformedDsnException.php Outdated Show resolved Hide resolved
src/Tools/DsnParser.php Outdated Show resolved Hide resolved
@derrabus derrabus merged commit 3d17514 into doctrine:3.6.x Dec 31, 2022
@derrabus derrabus deleted the feature/dsn-parser branch December 31, 2022 00:06
@faizanakram99
Copy link

@derrabus

How to pass driver options now ?

Earlier it used to be

$connection = DriverManager::getConnection([
    'url' => $this->databaseUrl,
    'driverOptions' => $driverOptions,
    'defaultTableOptions' => [
        'charset' => 'utf8mb4',
        'collate' => 'utf8mb4_0900_ai_ci',
    ],
]);

Now it is

$dsnParser  = new DsnParser(['mysql' => 'pdo_mysql']);
$connection = DriverManager::getConnection(
    $dsnParser->parse('mysql://my-user:t0ps3cr3t@my-host/my-database'),
   // how to pass driverOptions, defaultTableOptions etc ?
);

@derrabus
Copy link
Member Author

Merge them into the array that the parser returns before passing it to the driver manager.

@faizanakram99
Copy link

Merge them into the array that the parser returns before passing it to the driver manager.

Oh my bad, parser returns array 😂 ... didn't notice it

@fleonardelli-xt

This comment was marked as off-topic.

@faizanakram99

This comment was marked as off-topic.

@fleonardelli-xt

This comment was marked as off-topic.

@derrabus

This comment was marked as off-topic.

@doctrine doctrine locked and limited conversation to collaborators Feb 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants