-
-
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
Move the logic of driver exception conversion into a separate interface #4136
Conversation
95885ac
to
c48afea
Compare
c48afea
to
23c88b4
Compare
Does your sentence maybe miss a word or two? |
Yeah, it "indicates an issue in the DBAL". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the idea of using composition more 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I meant to approve of course!
Currently, there is a need to have abstract driver classes because specific driver implementations need to share certain code. This could be avoided by moving the common bits of logic under separate interfaces and compose drivers instead. A similar approach is already used to separate the logic of the DB platforms and drivers and then combine them together under a DBAL connection.
New API namespace
The
Driver\API
namespace is created. It will contain the logic specific to the driver APIs which the database servers and clients use to communicate. Multiple DBAL drivers and PHP extensions (e.g.mysqli
andpdo_mysql
) may use the same API. The API may include such functions as handling of the error codes, building DSN, etc.Changes in conversion of driver exceptions
ExceptionConverter
interface.Driver::convertException()
method has been replaced withgetExceptionConverter()
. This is a step towards converting theDriver
interface from an implementation of the driver logic to an abstract factory of the driver components that could be composed together.Changes in wrapping of driver exceptions
DBALException
to the wrapper Connection†handleException*()
methods in the wrapper connection have been reworked toconvertException*()
which return the exception instead of throwing it. The previous approach had certain downsides:Behavior changes
DataAccessTest::testFetchAllWithMissingTypes
has been removed. Besides not working withmysqli
,pdo_sqlite
andibm_db2
, the fact that it used to pass on PDO indicates an issue in the DBAL. The previous implementation used tocatch (Throwable $e)
. As per the comments in PHP bug #79769, this error is not meant to be caught. By wrapping the error in aDBALException
would make it less obvious that this was a logical error that had to be fixed, not caught.† — The original idea was to have the wrapper-level exception converter implemented as a separate class and used by the connection but the connection itself also has the logic of handling exceptions. Implementing this in two separate classes would require a circular reference between the connection and the exception handler which might cause memory issues.
TODO: