Repository navigation
fix: plugin interface wrappers keep the target's other interfaces - #727
Merged
Merged
Conversation
A plugin on an interface made the container return a wrapper that implemented only that interface, so the real object's other interfaces vanished from instanceof. With marko/debugbar installed, its plugin on ConnectionInterface meant the connection was no longer a TransactionInterface: resolving TransactionInterface threw, and repositories and the database queue silently ran without a transaction. - The generated wrapper also implements the other interfaces of the concrete class behind it and passes their methods straight to the real object. Methods of the plugged interface go through the plugin chain exactly as before. - An interface the wrapper cannot reproduce exactly is left out, which is the previous behaviour for it: one with plugins of its own, a PHP built-in interface, one that declares a property, a static method, a by-reference or static return, a reserved method name or an object default, or one whose methods or constants clash with another's. This is decided by reflection before any code is generated. - When nothing extra is added, the generated class is identical to before. - RequestStateResetter::reset() leaves a service alone when the excepted object is the proxy or anything behind it. Closes #726 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017KaHtXZjUng1AMo4pPj48V
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.
Problem
When a plugin targets an interface, the container returns a generated wrapper around the real object. That wrapper implemented only the plugged interface, so every other interface of the real object vanished from
instanceof.marko/debugbarships a plugin onConnectionInterface. With it registered:The drivers'
TransactionInterfacebinding threw, and seveninstanceof TransactionInterfacechecks (Repository,SqlQueryBuilder,DatabaseQueue,PgSqlIntrospector,TestDatabase, admin-auth'sPermissionRepositoryandPivotSync) silently took their no-transaction branch.Change
static, a method name the interceptor reserves, or an object parameter default, and one whose methods or constants clash with another interface's. The decision is made by reflection before any code is generated, because a wrong class declaration insideeval()is a fatal error that nothing can catch.PluginInterceptorpasses the concrete class to the generator at both wrapper call sites.RequestStateResetter::reset(...$except)leaves a service alone when the excepted object is the proxy or anything behind it. Without this, a wrapper that is now itself resettable would have been reset even though its target was excepted.Why in core, not at the call sites
Unwrapping the proxy at each
instanceofsite would spread plugin knowledge across eight packages, leavePendingAfterCommitInterface,TransactionalDdlInterfaceandResettableInterfacehidden, and leave every third-party site broken. BindingTransactionInterfaceto the unwrapped connection would fix resolution only; the seven checks on the injectedConnectionInterfacewould still skip transactions.Behaviour notes for review
breaking): a service behind an interface plugin now satisfiesinstanceoffor its other interfaces. In shipped code, the only flips are on a debugbar-wrapped driver connection, and each is the intended fix. An app's own class behind its own interface plugin changes the same way; this needs a release-note line.RequestStateResetterandMigrationTransaction(feat: run each migration in a transaction on postgresql #724) is kept: it still covers interfaces the wrapper leaves out and hand-written proxies.$thishands back the unwrapped target, and delegated methods pass the interface's default values explicitly.Tests
neverreturns, names wrappers by the interfaces they carry, and leaves out each unreproducible shape. Reds for wrong declarations were the PHP fatal errors themselves.TransactionInterfaceone resolves, and a#[Subject]satisfies the other interfaces.packages/debugbar/tests/DatabaseConnectionPluginTransactionTest.php: the reproduction above as tests, with debugbar's real plugin, the shipped SQLiteTransactionInterfacebinding and an in-memory connection.TransactionInterfaceresolves and is the plugin proxy, a transaction commits and a failing one rolls back, and debugbar still records the queries. All three fail with the fix reversed.composer cigreen andcomposer test:integrationgreen (429 passed, 25 skipped). The real-service suite gives no direct evidence for this fix, because the fixture app does not load debugbar; the SQLite test is the real-driver proof.Docs: the plugins concept page ("What gets generated", a new "Other interfaces of the target" subsection, the constraints list, and the
getPluginTarget()note), thecorepage and the architecture notes.Closes #726
🤖 Generated with Claude Code
https://claude.ai/code/session_017KaHtXZjUng1AMo4pPj48V