From 78c23c7105914b74ae91c71496265d3b03d7e285 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 9 Aug 2026 19:10:27 +0900 Subject: feat(plugin): let a Rust-implemented plugin cross into the worker PluginManager::getPluginCapability hands the plugin itself to the capability constructor. Only a PHP-implemented plugin had an entity the child could receive, so a Rust-implemented one bailed out; it now crosses as a handle to an R-table entity behind Shirabe\RustPluginStub, or its Capable flavour, since `$plugin instanceof Capable` is what decides whether Composer asks a plugin for capabilities at all. This is what the two capability tests of PluginInstallerTest were waiting on: the mocked Capable plugin is Rust-side, and one of them asserts the identity of the plugin read back out of $capability->args. --- .../php/runtime/Shirabe/RustCapablePluginStub.php | 17 +++++ .../php/runtime/Shirabe/RustPluginStub.php | 89 ++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 crates/shirabe-php-rpc/php/runtime/Shirabe/RustCapablePluginStub.php create mode 100644 crates/shirabe-php-rpc/php/runtime/Shirabe/RustPluginStub.php (limited to 'crates/shirabe-php-rpc/php/runtime') diff --git a/crates/shirabe-php-rpc/php/runtime/Shirabe/RustCapablePluginStub.php b/crates/shirabe-php-rpc/php/runtime/Shirabe/RustCapablePluginStub.php new file mode 100644 index 00000000..7a7c7eef --- /dev/null +++ b/crates/shirabe-php-rpc/php/runtime/Shirabe/RustCapablePluginStub.php @@ -0,0 +1,17 @@ +__rhandle, 'getCapabilities', []); + } +} diff --git a/crates/shirabe-php-rpc/php/runtime/Shirabe/RustPluginStub.php b/crates/shirabe-php-rpc/php/runtime/Shirabe/RustPluginStub.php new file mode 100644 index 00000000..a60c889a --- /dev/null +++ b/crates/shirabe-php-rpc/php/runtime/Shirabe/RustPluginStub.php @@ -0,0 +1,89 @@ +__rhandle = $rhandle; + $this->__epoch = $epoch; + } + + public function __destruct() + { + \ShirabeRustObjectRegistry::release($this->__rhandle); + } + + public function __shirabeRustHandleDescriptor(): array + { + return [ + '__rhandle' => $this->__rhandle, + '__class' => static::class, + '__epoch' => $this->__epoch, + ]; + } + + public function __clone() + { + // PHP has already shallow-copied this stub, so both copies would point at one + // entity and release it twice. The Rust side clones the entity instead, applying + // whatever __clone semantics the real class defines, and this copy rebinds to the + // fresh handle. Entities without clone semantics answer with an explicit error. + [$this->__rhandle, $this->__epoch] = \ShirabeRpcRuntime::callRust($this->__rhandle, '__shirabeClone', []); + \ShirabeRustObjectRegistry::adopt($this->__rhandle, $this); + } + + public function __get($name) + { + return \ShirabeRpcRuntime::callRust($this->__rhandle, '__get', [$name]); + } + + public function __set($name, $value): void + { + \ShirabeRpcRuntime::callRust($this->__rhandle, '__set', [$name, $value]); + } + + public function __isset($name): bool + { + return \ShirabeRpcRuntime::callRust($this->__rhandle, '__isset', [$name]); + } + + public function __unset($name): void + { + \ShirabeRpcRuntime::callRust($this->__rhandle, '__unset', [$name]); + } + + public function activate(Composer $composer, IOInterface $io) + { + \ShirabeRpcRuntime::callRust($this->__rhandle, 'activate', [$composer, $io]); + } + + public function deactivate(Composer $composer, IOInterface $io) + { + \ShirabeRpcRuntime::callRust($this->__rhandle, 'deactivate', [$composer, $io]); + } + + public function uninstall(Composer $composer, IOInterface $io) + { + \ShirabeRpcRuntime::callRust($this->__rhandle, 'uninstall', [$composer, $io]); + } +} -- cgit v1.3.1-4-g156e