Repository navigation
Conversation
AbstractPlatform now asks decoratorFor() for the decorator registered for a subject and renders the subject itself when there is none. That removes the union of bare Sql interfaces from the return type: a bare subject no longer occupies a decorator position, so requireDecoratorImplementing() and its per-call narrowing are gone. setTypeDecorator() enforces the invariant at registration instead, rejecting a decorator that does not implement the type it is registered for. A decorator that cannot render its subject can no longer be registered, so the render path has nothing left to check. Sql\Platform\Platform drops the platform-name keyed registry: resolvePlatformName(), cachedPlatformName, resolvePlatform(), getDefaultPlatform() and the third setTypeDecorator() argument are gone, and the decorator map has one flat shape in one class. Platform keeps its constructor argument so drivers that pass their adapter platform keep working, and it now ships with no decorators, which is what standard SQL needs. TestPlatform confirms the absent default: the stand-in assets and both driver platforms resolve and fall back exactly as before. Guard now enforces the two layer rules the split depends on. Refs #256 Signed-off-by: Joey Smith <jsmith@webinertia.net> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Member
Author
|
Superseded by #258, which removes the decorator machinery rather than reshaping it. Closing so this shape is not reviewed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Types of changes
Checklist
Description
First step of #256. It removes the pre-split platform resolution layer and gives the Sql platform one honest decorator contract. The RFC is split because its remaining steps either rename an
@apibase class that two driver packages extend, or moveSql92out of the public surface across three packages.One lookup, one map shape
AbstractPlatformno longer returns a decorator or a bare subject from one union-typed method.decoratorFor()returns the decorator registered for a subject, bound to it, ornull:That deletes
getTypeDecorator(), itsPlatformDecoratorInterface|PreparableSqlInterface|SqlInterfacereturn type, andrequireDecoratorImplementing()with its per-call narrowing. A bare subject can no longer occupy a decorator position, because no method returns one there.The decorator map has a single flat shape,
array<class-string, PlatformDecoratorInterface>, in one class. The nestedarray<string, array<string, PlatformDecoratorInterface>>union that forced@varcasts ingetTypeDecorator()anddecoratorsFor()is gone.Registration enforces the invariant
setTypeDecorator()rejects a decorator that does not implement the type it is registered for, withSql\Exception\RuntimeException::DECORATOR_WRONG_TYPE. A decorator that cannot render its subject now fails where it is registered rather than when it is used, which is what makes the render path's fallback unreachable for correct registration and safe for a subclass that injects directly into$decorators.No platform-name registry
Removed from
Sql\Platform\Platform:resolvePlatformName(),$cachedPlatformName,resolvePlatform(),getDefaultPlatform(), and the third$adapterOrPlatformargument onsetTypeDecorator(). The dialect is fixed by the platform object, and no code insrc/ever populated the name-keyed map, sogetDecorators()on a standard-SQL platform was an undefined key followed by aTypeError. It now returns[]because there is nothing to look up.Platformkeeps an ignored?PlatformInterfaceconstructor argument sonew Platform($this)inSql92and in the pg driver keeps working, and it ships with no decorators: standard SQL needs none.Guard rules
mago guardhad no perimeter configuration, so it skipped every check. Two rules now encode the layering, and I confirmed both fire by adding a temporary violating import to each layer:PhpDb\Adaptermay not depend onPhpDb\Sql\Platform\AbstractPlatform.PhpDb\Sqlmay not depend onPhpDb\Adapter\Platform\AbstractPlatform.Motivation and Context
Refs #256.
getTypeDecorator()was introduced in 2014 (dda49f70) by folding two duplicated loops into one method. The loops each checked the capability needed for the call (instanceof PreparableSqlInterface,instanceof SqlInterface) and fell back to the subject at the call site. The folded version dropped that check and moved the fallback into the return type, which is where the union of bare interfaces came from. This restores the call-site fallback and the capability check, in the place the split now requires: registration.What stays the same
PhpDb\Mysql\Sql\PlatformandPhpDb\Sqlite\Sql\Platformagainst the new contract, including the "no decorator for this type" fallback.instanceof.PlatformDecoratorInterface,setSubject(), and the public render methods.getSqlPlatformDecorator()onPlatformInterface, so a driver still supplies its platform.Breaking changes
getTypeDecorator()is replaced bydecoratorFor(). Nothing in the fleet calls it.Platform::setTypeDecorator()no longer takes the platform argument. No production caller used it; only tests did.Sql\Exception\RuntimeException::forDecoratorNotImplementing()andDECORATOR_NOT_IMPLEMENTINGare replaced byforDecoratorWrongType()andDECORATOR_WRONG_TYPE, because the condition moved from delegation to registration. Both were added in Clear Mago findings in the Sql platform layer #252 and are unreleased in 0.6.x.Platform::getSqlString()with no platform argument no longer substitutes the adapter platform, since the object no longer holds one.Sqlalways passes a platform, so the render path throughSqlis unchanged.Not in this PR
Sql92runtime default inAbstractSql::getSqlString()and movingSql92out ofsrc. Needs 90 call sites in this package plus 17 inphpdb-validatorandphpdb-paginator-adapter.Sql\Platform\AbstractPlatform.phpdb-mysqlandphpdb-sqliteextend it, so it needs a coordinated release.SequenceFeature's vendormatch. Needs a TableGateway feature shipped inphpdb-pgsqlfirst.PhpDb\Sql\Platform\PlatformfromPhpDb\Adapter(guard).Sql92::getSqlPlatformDecorator()still returns it, so that rule lands with theSql92step.How has this been tested?
Mago 1.59.0 on PHP 8.5.12:
format --check,lint,analyzeandguardall exit 0.lint --fail-on-out-of-sync-baselineandanalyze --fail-on-out-of-sync-baselineexit 0. The analyzer baseline loses 9 outdated entries, all inSql\Platform\PlatformorPlatformDecoratorInterface.use PhpDb\Sql\Platform\AbstractPlatforminsrc/Adapterand a temporaryuse PhpDb\Adapter\Platform\AbstractPlatforminsrc/Sqleach producedisallowed-useanddisallowed-class-constant.PHPUnit: 2864 tests, 4992 assertions, OK.
PlatformTestandAbstractPlatformTestare rewritten for the new contract, including the fallback paths for a decorator that can only render or only prepare. Every changedsrcline is covered (Clover, statement lines).Cross-package smoke test:
PhpDb\Mysql\Sql\Platformregisters and resolvesSelect,CreateTableandAlterTable,PhpDb\Sqlite\Sql\PlatformregistersSelect, and both fall back forInsertand the DDL types they do not decorate.Docs: new
docs/book/sql/platform.mdcovers the two platform concepts, one platform per adapter, the decorator contract and registration rule, and the driver package checklist. Added to themkdocs.ymlnav.