Skip to content

fix: plugin interface wrappers keep the target's other interfaces - #727

Merged
markshust merged 2 commits into
developfrom
feature/plugin-wrapper-interfaces
Nov 28, 2026
Merged

markshust merged 2 commits into
developfrom
feature/plugin-wrapper-interfaces

Conversation

@markshust

Copy link
Copy Markdown
Collaborator

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/debugbar ships a plugin on ConnectionInterface. With it registered:

== WITHOUT the plugin
  resolved ConnectionInterface: SqliteConnection
  instanceof TransactionInterface: true
  resolved TransactionInterface: SqliteConnection

== WITH debugbar's DatabaseConnectionPlugin
  resolved ConnectionInterface: Marko_Interceptor_..._ConnectionInterface_b4d6bb79
  instanceof TransactionInterface: false
  resolving TransactionInterface THREW UnsupportedTransactionFeatureException:
    Connection 'Marko_Interceptor_...' does not support transactions

The drivers' TransactionInterface binding threw, and seven instanceof TransactionInterface checks (Repository, SqlQueryBuilder, DatabaseQueue, PgSqlIntrospector, TestDatabase, admin-auth's PermissionRepository and PivotSync) silently took their no-transaction branch.

Change

  • The interface wrapper now also implements the other interfaces of the concrete class behind it. Their methods are passed 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 that interface. That covers an interface that has plugins of its own, is a PHP built-in interface (or extends one), declares a property, a static method, a method returning by reference or 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 inside eval() is a fatal error that nothing can catch.
  • When nothing extra is added, the generated class has the same name and the same code as before. That is the case for the queue, logger and view wrappers.
  • PluginInterceptor passes 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 instanceof site would spread plugin knowledge across eight packages, leave PendingAfterCommitInterface, TransactionalDdlInterface and ResettableInterface hidden, and leave every third-party site broken. Binding TransactionInterface to the unwrapped connection would fix resolution only; the seven checks on the injected ConnectionInterface would still skip transactions.

Behaviour notes for review

  • Behaviour change (breaking): a service behind an interface plugin now satisfies instanceof for 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.
  • Plugins registered on one of the other interfaces do not fire for calls made through this wrapper; such an interface is left off the wrapper entirely, as before.
  • The existing proxy-unwrapping in RequestStateResetter and MigrationTransaction (feat: run each migration in a transaction on postgresql #724) is kept: it still covers interfaces the wrapper leaves out and hand-written proxies.
  • Known limits, unchanged by this PR: a method returning $this hands back the unwrapped target, and delegated methods pass the interface's default values explicitly.
  • A plugged interface that itself declares a property is an existing limitation and is not addressed here.

Tests

  • Generator: the wrapper implements the other interfaces, delegates their methods, keeps by-reference and variadic parameters and never returns, names wrappers by the interfaces they carry, and leaves out each unreproducible shape. Reds for wrong declarations were the PHP fatal errors themselves.
  • Interceptor, through the real container: a proxy is an instance of the target's other interfaces, a call through one reaches the target, two concrete classes behind one plugged interface get their own interface sets, a closure binding like the drivers' TransactionInterface one 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 SQLite TransactionInterface binding and an in-memory connection. TransactionInterface resolves 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.
  • No existing test had to change what it asserts.
  • Run locally: composer ci green and composer test:integration green (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), the core page and the architecture notes.

Closes #726

🤖 Generated with Claude Code

https://claude.ai/code/session_017KaHtXZjUng1AMo4pPj48V

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
@markshust markshust added bug Something isn't working breaking Introduces a breaking change labels Nov 28, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Nov 28, 2026
@markshust
markshust merged commit 5f89e2f into develop Nov 28, 2026
5 checks passed
@markshust
markshust deleted the feature/plugin-wrapper-interfaces branch November 28, 2026 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Introduces a breaking change bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

core: a plugin on an interface hides the target's other interfaces (debugbar breaks TransactionInterface)

1 participant