Do not implement driver-level interfaces by wrapper-level classes#4159
Merged
morozov merged 1 commit intodoctrine:3.0.xfrom Jul 10, 2020
Merged
Conversation
692f299 to
6bcc08b
Compare
greg0ire
previously approved these changes
Jul 10, 2020
greg0ire
reviewed
Jul 10, 2020
Member
There was a problem hiding this comment.
Hold on, I think https://github.com/doctrine/dbal/blob/3.0.x/docs/en/reference/architecture.rst has to be changed, for instance this sentence:
Even more, a Doctrine\DBAL\Connection is a Doctrine\DBAL\Driver\Connection and a Doctrine\DBAL\Statement is a Doctrine\DBAL\Driver\Statement.
6bcc08b to
6d2b649
Compare
Member
Author
Yeah, this is no longer true, so I'll just remove it. There are some other bits outdated as of |
greg0ire
approved these changes
Jul 10, 2020
This was referenced Jul 11, 2020
This was referenced Sep 23, 2020
javiereguiluz
added a commit
to symfony/symfony-docs
that referenced
this pull request
Nov 8, 2021
This PR was merged into the 5.3 branch. Discussion ---------- Update type declaration for Doctrine DBAL Connection In doctrine/dbal 3.0.0 Doctrine\DBAL\Driver\Connection has become an internal interface and the wrapper-level Doctrine\DBAL\Connection should be used. Related: https://github.com/doctrine/dbal/releases/tag/3.0.0 doctrine/dbal#4159 Commits ------- 3e4c7d7 Update type declaration for Doctrine DBAL Connection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There are certain downsides of having the wrapper-level classes have to implement the driver-level interfaces:
Alongside the
executeQuery()andexecuteUpdate()methods, the wrapper connection has to implementquery()andexec()just because the interface declares them. Although, API-wise the latter two are just the subset of the former.Prior to PHP 7.4, the return type contravariance is not supported (https://3v4l.org/dNsho) which means that the wrapper-level classes cannot declare their return type specifically enough and have to declare the type just as prescribed by the lower-level interface.
The fact that the wrappers implement the driver interfaces makes it harder to evolve the wrapper layer independently of the driver one. E.g. we cannot add a new (even optional) argument to any of the wrapper methods that are declared in the driver interface without a BC break.
Unlike the driver-level classes that are allowed to throw driver exceptions and only them, the wrapper-level classes are not allowed to throw driver-level exceptions but are allowed to throw wrapper-level exceptions. This leads to the following issues:
Strictly speaking, at this point the wrapper layer violates the interface that it's forced to implement.
As for the upsides, I haven't seen a case where a consumer should be able to use a wrapper connection as a driver one. The fact that not a single test had to be changed confirms that.
TODO:
2.11.x(Deprecated usage of wrapper components as implementations of driver-level interfaces #4165).