From 695365a0ad68e4534425c64b7a6a4b6598b68ef7 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 4 Aug 2026 04:07:41 +0900 Subject: feat(plugin): dispatch plugin event subscribers through the RPC worker Wires the addPlugin subscriber branch end to end: EventSubscriberInterface and Capable become fallible and dyn-compatible (their sole implementor is the PHP plugin proxy, which answers getSubscribedEvents over RPC), listeners register as Callable::PhpMethod and are invoked with a per-call event handle, and the R table now drops entries when a child-side stub destructs. The R table keeps its IndexMap with monotonically increasing handles, so released handles are never reused and no generation counter is needed. Upstream has no subscriber-plugin test, so the path is covered by a Shirabe-owned fixture exercising all three getSubscribedEvents shapes. Co-Authored-By: Claude Fable 5 --- .../src/event_dispatcher/event_subscriber_interface.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'crates/shirabe/src/event_dispatcher/event_subscriber_interface.rs') diff --git a/crates/shirabe/src/event_dispatcher/event_subscriber_interface.rs b/crates/shirabe/src/event_dispatcher/event_subscriber_interface.rs index 41d723dc..0a5d88d5 100644 --- a/crates/shirabe/src/event_dispatcher/event_subscriber_interface.rs +++ b/crates/shirabe/src/event_dispatcher/event_subscriber_interface.rs @@ -1,15 +1,26 @@ //! ref: composer/src/Composer/EventDispatcher/EventSubscriberInterface.php use indexmap::IndexMap; +use shirabe_php_rpc::PhpObjHandle; /// Represents one event's subscriber info: method name only, method+priority, or multiple handlers. +#[derive(Debug)] pub enum SubscribedEventEntry { Method(String), MethodWithPriority(String, Option), Methods(Vec<(String, Option)>), } +// The sole implementor is the PHP plugin proxy (plugins are the only subscribers in Composer +// itself), so the trait deviates from the PHP shape in two deliberate ways: the PHP-side static +// `getSubscribedEvents()` takes `&self` here (the receiver carries which PHP class to call, and +// an associated function would not be dyn-compatible), and it is fallible because the answer +// crosses the RPC boundary. pub trait EventSubscriberInterface { /// Returns an array of event names this subscriber wants to listen to. - fn get_subscribed_events() -> IndexMap; + fn get_subscribed_events(&self) -> anyhow::Result>; + + /// The subscriber as it crosses the wire: PHP's `[$subscriber, $method]` array callables + /// capture the subscriber object itself, represented here by its P-table handle. + fn subscriber_handle(&self) -> PhpObjHandle; } -- cgit v1.3.1