Skip to content

[RFC]: Finish the platform split before 1.0 #256

Backlog

Description

@tyrsson

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:

  1. Core contains no vendor knowledge: no vendor names, no vendor SQL, no naming of a driver class.
  2. The unit of support is a driver package. A new driver ships without touching core.
  3. One platform object per adapter, bound at construction. No runtime resolution, no multi-flavor registry.
  4. No runtime default platform. A caller supplies a platform, or gets a named exception.
  5. Core owns the interfaces for features and decorators; driver packages own the implementations, including TableGateway features.
  6. 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\Platform holds a map keyed by platform name and resolves it with resolvePlatformName(). 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-migration comment.
  • Runtime default platform. AbstractSql::getSqlString() falls back to new Sql92() when no platform is passed. new Sql92 has been in the lineage since 2012-02-23 (f7992bc7), moved into AbstractSql on 2014-05-27 (bed7032a), and only had its operator modernized on 2026-10-05 (a4376201). Sql92 is a driverless conformance platform whose quoteValue() 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) constructs new Sql($adapter), so the flavor has to travel with the adapter.
  • Vendor dispatch in core. TableGateway\Feature\SequenceFeature selects Oracle or PostgreSQL SQL with a match on $platform->getName(), and the PostgreSQL branch calls LAST_INSERT_ROWID(), which is SQLite's function.

Considerations

  • Backward compatibility. $decorators is protected, Platform is tagged @api (Mago compliance: settle the API decisions behind remaining src analyzer issues #255), and widening PlatformInterface or 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 Sql instances. 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, TableGateway and RowGateway are 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. Sql92 plus PhpDb\Sql\Platform\Platform form the driverless conformance pair. That role is legitimate and should be preserved, but as test-only surface.

Proposal(s)

  1. Remove the runtime default. Delete the AbstractSql::getSqlString() fallback and require a platform, with a named exception when none is supplied. Move Sql92 out of the public runtime surface (test asset or @internal), together with its getSqlPlatformDecorator().
  2. Bind one platform per adapter and delete the name layer. Remove resolvePlatformName(), $cachedPlatformName, the nested $decorators[$platformName] shape, and the third $adapterOrPlatform argument from setTypeDecorator().
  3. Narrow the decorator contract. Replace getTypeDecorator() with a lookup that returns ?PlatformDecoratorInterface (decoratorFor($subject)), have Sql resolve decoratorFor(...) ?? $subject, and delete requireDecoratorImplementing(). A bare subject never occupies a decorator slot.
  4. Fix the naming collision. Rename PhpDb\Sql\Platform\AbstractPlatform (proposed AbstractSqlPlatform). Keep PhpDb\Sql\Platform\Platform as the no-decoration implementation.
  5. Move vendor SQL out of core. Delete the SequenceFeature vendor match and 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.
  6. Publish the driver package contract. A package is complete when it provides: a ConfigProvider; driver and connection; an AdapterPlatform; optional SQL decorators; optional driver features including TableGateway features; and requires no edit to core.
  7. Enforce the split with guard rules.
    • phpdb/src contains none of the strings mysql, pgsql, postgres, sqlite, oracle, sqlsrv, ibmdb2.
    • No behavioural use of PlatformInterface::getName() in Sql or TableGateway.
    • Adapter may reference Sql\Platform\PlatformDecoratorInterface only.
    • Sql may reference Adapter\Platform\PlatformInterface but not Adapter\Platform\AbstractPlatform.
    • Core never names a driver class.
  8. 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; AbstractPlatform has a single decorator property shape.
  • SequenceFeature contains no vendor SQL.
  • mago guard configured 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, first new Sql92), bed7032a (2014-05-27, fallback moved into AbstractSql), 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\Platform survives long term as the no-decoration base; whether SequenceFeature shrinks to nextSequenceId() or is replaced by getLastGeneratedValue($name); how a MariaDB variant ships alongside MySQL.

Activity

  1. added
    RFC
    on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFC

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions