-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Deprecate Connection::getWrappedConnection(), mark Connection::connect() internal #4966
Deprecate Connection::getWrappedConnection(), mark Connection::connect() internal #4966
Conversation
7ad4dfc
to
0591041
Compare
In the past, I've worked on several codebases that did access the native connection occasionally.
Both applications were Symfony applications that configured DBAL through DoctrineBundle. Implementing a custom driver just to gain access to the native connection wouldn't be straightforward in these setups. I understand that the motivation behind the deprecation is to push the middleware architecture in which the native connection in the bottom of a stack with multiple layers. However, I believe that accessing the native connection can be a valid thing to do and we should neither forbid it completely nor make it unnecessarily difficult. Since |
@derrabus in my opinion, it's reasonably difficult since the idea of retrieving an underlying connection undermines the purpose of the DBAL as such. What exactly is difficult about implementing a middleware? It's mostly a boilerplate code. In my opinion, the absence of an API that breaks the library's own abstraction while it is possible to break it if needed is the most optimal solution. Think of it as of breaking the glass in case of emergency. As you can see, all the APIs that rely on breaking the abstraction become a liability at a certain point in time. I'm referring to the insanity of the |
0591041
to
a8d1126
Compare
To the point of being able to access the native connection, note, this PR deprecates only the wrapper-level A great example of this method being unreliable is the failure of this test in #4967: dbal/tests/Functional/Driver/IBMDB2/ConnectionTest.php Lines 39 to 43 in 10df50f
It expects that the method will return an |
I don't think so. By providing access to the native connection, we merely acknowledge that the DBAL cannot provide abstraction for features that are very specific to a certain DB engine. If 99% of an application accesses the database through the DBAL, but for one operation, the native connection is used, the DBAL is still a good choice for that application, I'd say.
Agreed, I understand that you don't see that use-case and that you would like to avoid maintaining leaky abstractions. But I believe that the need for accessing the native connection accasionally is there. |
I have worked out a proposal to address the concern of accessing the native connection: #5037. With that change implemented, I could live with deprecating and dropping |
a8d1126
to
7daa10f
Compare
7daa10f
to
dcee3b5
Compare
So, how to make reconnect in deamon with deprecated public access to Connection::connect()? |
The wrapper will connect automatically upon the next interaction with the database. |
HI @morozov How to get rid of the deprecation in the following code
In our |
Why do you use the driver connection in your code? |
It's use here: https://github.com/sonata-project/exporter/blob/3.x/src/Source/DoctrineDBALConnectionSourceIterator.php#L73 From a string query, |
Why can’t you use the wrapper connection itself? |
Indeed, I can. |
Currently,
Connection::getWrappedConnection()
is only used by the connection class itself and the tests. This method will return the object that is immediately wrapped into the wrapper connection. If there's a middleware between the wrapper and the actual driver, it is not guaranteed that there is a way to get to the actual driver.If it is necessary to get the underlying driver connection, e.g. for integration with another database layer, it's possible to implement a custom driver:
See a complete example of a driver middleware for more details.
In DBAL 4.0, the
Connection::connect()
method will return the underlying driver connection and will be madeprotected
.