Rework the portability layer to act as a middleware #4157
Merged
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.
Fixes #4156.
Importance
Apart from the fatal error reported in the linked issue, the current implementation blocks the decoupling of the driver and wrapper APIs. The wrapper-level
Connection::prepare()
declares its return type asDriverStatement
(which is not intended but required by the driver-levelConnection
interface) however it returns aStatement
(a more specific and feature-rich type):dbal/src/Connection.php
Lines 908 to 912 in 98c23fe
Even if it stops implementing the driver connection interface, it cannot declare its return type as
Statement
because thePortability\Connection
class currently extends it and returns a driver-level statement:dbal/src/Portability/Statement.php
Lines 9 to 12 in 48625f1
The Driver Middleware concept
The concept of a driver middleware will allow extending the behavior of the DBAL connection by wrapping the underlying driver. Once the driver is wrapped, the wrapper can also wrap the connection and the statement objects effectively extending any of the behaviors. The middleware objects are registered via configuration (see example in the test).
Apart from the portability layer, it can be used to reimplement the caching layer which is currently implemented as part of the wrapper connection class.
Portability layer reworked
The portability layer has been reworked to act as middleware and implement only the driver-level APIs.