aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/plugin-stub-generator/src
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-06 01:50:34 +0900
committernsfisis <nsfisis@gmail.com>2026-08-06 01:50:34 +0900
commit4de018826e9dce90fd5cb78d468641478327ec99 (patch)
tree0843f7e3e8c50886c8470ace17fcb6fed937be4f /scripts/plugin-stub-generator/src
parentda602f1cb1d555c7826fa3d026df66b82061cda4 (diff)
downloadphp-shirabe-4de018826e9dce90fd5cb78d468641478327ec99.tar.gz
php-shirabe-4de018826e9dce90fd5cb78d468641478327ec99.tar.zst
php-shirabe-4de018826e9dce90fd5cb78d468641478327ec99.zip
feat(plugin): run plugin-provided installers through the RPC worker
A plugin can now hand an InstallerInterface implementation to InstallationManager::addInstaller across the wire, and a legacy composer-installer package is loaded as one; both are backed by a PhpInstallerProxy forwarding the whole installer contract to the entity in the PHP worker. An installer returning a real promise is an explicit error until promises can cross the boundary. InstallationManager takes installers as shared handles instead of boxes, so the object identity removeInstaller and PluginManager's registeredPlugins compare against survives registration, and holds them in a RefCell: Installer::run keeps a shared borrow of the manager for the whole run, and a plugin activated inside it registers its installer from there. The type cache keys on the installer itself, like upstream, so re-entrant registration cannot leave a stale index behind. InstallerInterface::supports is fallible for the same reason getCapabilities and getCommands are: it answers over RPC. Cloning a proxy stub clones the Rust-side entity and rebinds the copy to the fresh handle. Previously only the classes declaring __clone got a throwing body, and the rest let two stubs share (and twice release) one handle. Package entities answer with AnyPackage::dup, which already carries BasePackage::__clone and the RootAliasPackage override; the others are an explicit error. The package proxy covers the whole PackageInterface surface; only the link maps and the release date still lack a wire image for their value objects. PluginManager gains a test-only seam for the reported Plugin API version, and the three PluginInstallerTest cases that need it are ported. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'scripts/plugin-stub-generator/src')
-rw-r--r--scripts/plugin-stub-generator/src/Generator.php31
1 files changed, 13 insertions, 18 deletions
diff --git a/scripts/plugin-stub-generator/src/Generator.php b/scripts/plugin-stub-generator/src/Generator.php
index 1e41eed8..ce8f612b 100644
--- a/scripts/plugin-stub-generator/src/Generator.php
+++ b/scripts/plugin-stub-generator/src/Generator.php
@@ -50,6 +50,16 @@ final class Generator
'__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);
+ }
PHP;
private const PROPERTY_FORWARDERS = <<<'PHP'
@@ -65,15 +75,6 @@ final class Generator
}
PHP;
- private const CLONE_THROW = <<<'PHP'
- public function __clone()
- {
- // Cloning a proxy is an open design question; fail instead of silently sharing
- // the Rust-side entity between two stub instances.
- throw new \RuntimeException('Shirabe does not support cloning ' . static::class . ' inside the plugin process yet');
- }
- PHP;
-
private Project $project;
private NamePrinter $printer;
@@ -234,7 +235,6 @@ final class Generator
$publicStatics = [];
$nonPublicStatics = [];
$ownInstanceMethods = [];
- $cloneThrows = false;
foreach ($class->getMethods() as $method) {
$name = $method->name->toString();
if ($name === '__construct') {
@@ -245,14 +245,12 @@ final class Generator
$this->errors[] = "$fqcn::$name: magic methods cannot be proxied";
}
// __toString is an ordinary zero-argument call under a magic name and is
- // forwarded below; __clone semantics are an open design question and the
- // emitted body throws instead of silently sharing the Rust handle.
+ // forwarded below. A real __clone declaration needs no counterpart here: the
+ // boilerplate's forwarder delegates cloning to the entity, whose Rust-side
+ // clone carries the declared semantics.
if ($method->isPublic() && $name === '__toString') {
$ownInstanceMethods[$name] = $method;
}
- if ($method->isPublic() && $name === '__clone') {
- $cloneThrows = true;
- }
continue;
}
if ($method->isStatic()) {
@@ -343,9 +341,6 @@ final class Generator
if ($hasPublicInstanceProperties) {
$members[] = self::PROPERTY_FORWARDERS;
}
- if ($cloneThrows) {
- $members[] = self::CLONE_THROW;
- }
$members = array_merge($members, $staticMethods, $methodTexts);
$body = implode("\n\n", $members);