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

Service Doctrine\DBAL\Driver\Connection is an instance of Doctrine\DBAL\Connection which does not implement Doctrine\DBAL\Driver\Connection #1637

Closed
chrif opened this issue Mar 21, 2023 · 3 comments
Milestone

Comments

@chrif
Copy link

chrif commented Mar 21, 2023

"doctrine/dbal": "^3.6",
"doctrine/doctrine-bundle": "^2.8",

In dbal.xml:
<service id="Doctrine\DBAL\Driver\Connection" alias="database_connection" public="false" />

This service enables autowiring on the Doctrine\DBAL\Driver\Connection interface but database_connection is an instance of Doctrine\DBAL\Connection which does not implement Doctrine\DBAL\Driver\Connection anymore in DBAL 3.x

So why keeping this definition? Is it only for backward compatibility? But if it makes autowiring fails it's not really backward compatible.

@ostrolucky
Copy link
Member

Right below that there is a same alias for Doctrine\DBAL\Connection which should explain why nobody complained till now. Or do you have some scenario where you get autowiring error regarding this?

@chrif
Copy link
Author

chrif commented Mar 23, 2023

I'm upgrading an app from dbal 2 to 3. It had a custom service like this:

  doctrine.connection:
    class: Doctrine\DBAL\Driver\Connection
    factory: ['@doctrine.orm.entity_manager', getConnection]
    public: true

and developers were in the habit of injecting the Doctrine\DBAL\Driver\Connection interface with autowiring.

I replaced all usages of Doctrine\DBAL\Driver\Connection to Doctrine\DBAL\Connection and replaced the service with this definition:

  doctrine.connection:
    alias: 'doctrine.dbal.default_connection'
    public: true

Now developers need to lose the habit of autowiring Doctrine\DBAL\Driver\Connection which I thought would fail with a "no such service error". I was surprised to see instead an "interface not implemented" error, which is confusing.

I created a compiler pass to remove it.

@ostrolucky
Copy link
Member

Since we don't support DBAL 2 anymore, indeed we should remove this alias.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants