diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-09 19:10:27 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-09 19:10:27 +0900 |
| commit | 78c23c7105914b74ae91c71496265d3b03d7e285 (patch) | |
| tree | 0f7e4b384bdbc211bb1bba2c274fd416880098d7 /crates/shirabe-php-rpc/php | |
| parent | 6d257691a39fb8c4191f4564ec6406d080dbf6b5 (diff) | |
| download | php-shirabe-78c23c7105914b74ae91c71496265d3b03d7e285.tar.gz php-shirabe-78c23c7105914b74ae91c71496265d3b03d7e285.tar.zst php-shirabe-78c23c7105914b74ae91c71496265d3b03d7e285.zip | |
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.
Diffstat (limited to 'crates/shirabe-php-rpc/php')
| -rw-r--r-- | crates/shirabe-php-rpc/php/runtime/Shirabe/RustCapablePluginStub.php | 17 | ||||
| -rw-r--r-- | crates/shirabe-php-rpc/php/runtime/Shirabe/RustPluginStub.php | 89 |
2 files changed, 106 insertions, 0 deletions
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 @@ +<?php + +// The Capable flavour of RustPluginStub: `$plugin instanceof Capable` decides whether Composer +// asks a plugin for capabilities, so the stub class is picked to match what the Rust-side +// plugin implements. + +namespace Shirabe; + +use Composer\Plugin\Capable; + +class RustCapablePluginStub extends RustPluginStub implements Capable +{ + public function getCapabilities() + { + return \ShirabeRpcRuntime::callRust($this->__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 @@ +<?php + +// Proxy stub for a plugin whose implementation lives on the Rust side. It has no counterpart +// class in Composer: a plugin is normally PHP code running in this process, and only a +// Rust-implemented one needs a stand-in here (a capability constructor receives the plugin +// itself as $ctorArgs['plugin']). + +namespace Shirabe; + +use Composer\Composer; +use Composer\IO\IOInterface; +use Composer\Plugin\PluginInterface; + +class RustPluginStub implements PluginInterface, \ShirabeRustStub +{ + /** @var int */ + protected $__rhandle; + /** @var int */ + protected $__epoch; + + /** + * Binds a stub the registry built for an existing entity. Proxy instantiation bypasses + * the constructor, which belongs to plugin code building a new entity instead. + */ + public function __shirabeBind(int $rhandle, int $epoch): void + { + $this->__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]); + } +} |
