Repository navigation
Backlog
Labels
RFCRFC issue or PR
Description
Proposed Version
1.0 (major)
Basic Information
Finish the split of platform handling so that driver packages own dialect behaviour, core contains no vendor knowledge, and nothing is resolved at runtime.
There are two concepts, both legitimately named "platform", and the proposal is to qualify them consistently rather than rename one away:
| Concept | Namespace | Responsibility | Implementations |
|---|---|---|---|
| Adapter platform | PhpDb\Adapter\Platform |
identifier and value quoting | Sql92 (fixture), Mysql\AdapterPlatform, Pgsql\AdapterPlatform, Sqlite\AdapterPlatform |
| SQL platform | PhpDb\Sql\Platform |
renders Sql objects, decorating where a dialect differs |
Platform (no decoration), Mysql\Sql\Platform, Sqlite\Sql\Platform, Pgsql\Sql\Platform when it exists |
The six rules this RFC proposes to adopt and enforce:
- Core contains no vendor knowledge: no vendor names, no vendor SQL, no naming of a driver class.
- The unit of support is a driver package. A new driver ships without touching core.
- One platform object per adapter, bound at construction. No runtime resolution, no multi-flavor registry.
- No runtime default platform. A caller supplies a platform, or gets a named exception.
- Core owns the interfaces for features and decorators; driver packages own the implementations, including TableGateway features.
PlatformInterface::getName()is for labels, never for dispatch.
Background
The component exists to split driver code from the abstraction so each driver can evolve or be deprecated independently. Laminas Db ended up abandoned because supporting every driver required maintainers with breadth that did not exist in the contributor pool.
Several pieces of the pre-split design are still present and are the source of the current ambiguity:
- Name-keyed decorator registry.
PhpDb\Sql\Platform\Platformholds a map keyed by platform name and resolves it withresolvePlatformName(). It is now empty in every production instance, because the constructor registration was removed. The removed code and the vendor list are recorded in the@todo sat-migrationcomment. - Runtime default platform.
AbstractSql::getSqlString()falls back tonew Sql92()when no platform is passed.new Sql92has been in the lineage since 2012-02-23 (f7992bc7), moved intoAbstractSqlon 2014-05-27 (bed7032a), and only had its operator modernized on 2026-10-05 (a4376201).Sql92is a driverless conformance platform whosequoteValue()throws, so as a default it fails depending on statement content. - The adapter to Sql seam.
PlatformInterface::getSqlPlatformDecorator()was added 2025-05-06 (db1cd25e). It is the one place where the Adapter layer references Sql, and every consumer path (TableGateway,RowGateway,PrimaryReplicaFeature,phpdb-validator) constructsnew Sql($adapter), so the flavor has to travel with the adapter. - Vendor dispatch in core.
TableGateway\Feature\SequenceFeatureselects Oracle or PostgreSQL SQL with amatchon$platform->getName(), and the PostgreSQL branch callsLAST_INSERT_ROWID(), which is SQLite's function.
Considerations
- Backward compatibility.
$decoratorsisprotected,Platformis tagged@api(Mago compliance: settle the API decisions behind remaining src analyzer issues #255), and wideningPlatformInterfaceor narrowing return types breaks third-party platforms and subclasses. Before 1.0 is the cheapest time to do this. - Driver packages. mysql and sqlite keep their own carriers. pgsql gains one when core gains a construct that needs PostgreSQL rendering. DuckDB is a likely future package and fits the same shape as SQLite.
- Two drivers in one process. A cross-platform migration component would hold two adapters, each bound to its own platform, and two
Sqlinstances. That is host-application wiring, not a core feature, and it does not revive the registry. - Non-SQL drivers. Mongo is only an illustrative example.
Platform,Sql,TableGatewayandRowGatewayare the SQL half; shared contracts (Adapter,ConnectionInterface,ResultInterface,ResultSet) must stay free of SQL concepts so a document store could reuse them later. - Conformance role.
Sql92plusPhpDb\Sql\Platform\Platformform the driverless conformance pair. That role is legitimate and should be preserved, but as test-only surface.
Proposal(s)
- Remove the runtime default. Delete the
AbstractSql::getSqlString()fallback and require a platform, with a named exception when none is supplied. MoveSql92out of the public runtime surface (test asset or@internal), together with itsgetSqlPlatformDecorator(). - Bind one platform per adapter and delete the name layer. Remove
resolvePlatformName(),$cachedPlatformName, the nested$decorators[$platformName]shape, and the third$adapterOrPlatformargument fromsetTypeDecorator(). - Narrow the decorator contract. Replace
getTypeDecorator()with a lookup that returns?PlatformDecoratorInterface(decoratorFor($subject)), haveSqlresolvedecoratorFor(...) ?? $subject, and deleterequireDecoratorImplementing(). A bare subject never occupies a decorator slot. - Fix the naming collision. Rename
PhpDb\Sql\Platform\AbstractPlatform(proposedAbstractSqlPlatform). KeepPhpDb\Sql\Platform\Platformas the no-decoration implementation. - Move vendor SQL out of core. Delete the
SequenceFeaturevendormatchand the two unsupported-platform exceptions consumption; ship sequence support as a TableGateway feature in the package that owns the dialect. Feature implementations move to driver packages; core keeps the interfaces. - Publish the driver package contract. A package is complete when it provides: a
ConfigProvider; driver and connection; anAdapterPlatform; optional SQL decorators; optional driver features including TableGateway features; and requires no edit to core. - Enforce the split with guard rules.
phpdb/srccontains none of the stringsmysql,pgsql,postgres,sqlite,oracle,sqlsrv,ibmdb2.- No behavioural use of
PlatformInterface::getName()inSqlorTableGateway. Adaptermay referenceSql\Platform\PlatformDecoratorInterfaceonly.Sqlmay referenceAdapter\Platform\PlatformInterfacebut notAdapter\Platform\AbstractPlatform.- Core never names a driver class.
- Document the layering, including that cross-driver, side-by-side work is host-application wiring.
Acceptance Criteria
- No runtime default platform anywhere in
src. - No platform-name keyed storage or resolution.
- One flat decorator map per platform object;
AbstractPlatformhas a single decorator property shape. SequenceFeaturecontains no vendor SQL.mago guardconfigured with the rules above and passing.- Driver package contract documented in
docs/book. - Existing drivers (mysql, pgsql, sqlite) pass their suites unchanged apart from the sqlite fixes tracked in SelectDecorator diverges from laminas Sqlite and produces invalid SQL phpdb-sqlite#45.
Appendix/Additional Info
- Introducing commits:
f7992bc7(2012-02-23, firstnew Sql92),bed7032a(2014-05-27, fallback moved intoAbstractSql),dda49f70(2014-05-29,getTypeDecorator()extraction and the bare-subject return),db1cd25e(2025-05-06,getSqlPlatformDecorator()). - Relevant code:
src/Sql/AbstractSql.php:72-77,src/Sql/Platform/Platform.php:25-42,src/Sql/Platform/AbstractPlatform.php:44-60,src/Adapter/Platform/PlatformInterface.php:37,src/TableGateway/Feature/SequenceFeature.php:46-50,81-85. - Driver defects found while reviewing this: SelectDecorator diverges from laminas Sqlite and produces invalid SQL phpdb-sqlite#45.
- Open questions: whether
PhpDb\Sql\Platform\Platformsurvives long term as the no-decoration base; whetherSequenceFeatureshrinks tonextSequenceId()or is replaced bygetLastGeneratedValue($name); how a MariaDB variant ships alongside MySQL.
Metadata
Metadata
Assignees
Labels
RFCRFC issue or PR
Activity