Move the logic of driver exception conversion into a separate interface #4136
+1,025
−880
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.
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: