aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-php-rpc
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-06 02:40:00 +0900
committernsfisis <nsfisis@gmail.com>2026-08-06 02:40:00 +0900
commit90764c477f24e4d67d3e0cae943c33fd2b8ae220 (patch)
tree8274fb1e266d6a14653c2a440cc6831ffda1c6bf /crates/shirabe-php-rpc
parent0e89281dd7f057d3829508b8e6c5d85c3f111c45 (diff)
downloadphp-shirabe-90764c477f24e4d67d3e0cae943c33fd2b8ae220.tar.gz
php-shirabe-90764c477f24e4d67d3e0cae943c33fd2b8ae220.tar.zst
php-shirabe-90764c477f24e4d67d3e0cae943c33fd2b8ae220.zip
feat(plugin): widen the RPC surface to LibraryInstaller-based plugins
An installer that extends LibraryInstaller reaches for the Composer object graph in ways the proxy did not answer: the download manager and the config, the writable repository methods, a React promise as its own return value, and `new Package(...)` from its supports() path. * `Composer::getConfig`/`getDownloadManager` are dispatched, and both classes become generated proxy stubs. Their reads and mutators answer from the Rust entity; the surfaces needing stubs of their own (ConfigSourceInterface, DownloaderInterface) stay explicit errors. * The download manager's futures are driven to completion and handed back as already-settled React promises, since PHP declares a non-nullable PromiseInterface there. A promise a plugin returns is drained the same way: settled yields its value, rejected re-raises, pending is an explicit error. * Proxy stubs now carry the real class's constructor and ask the Rust side to allocate the entity; reviving a stub for an existing entity binds the handle without running it. Classes Rust cannot build name themselves in the error. * The package proxy covers `Package`'s own setters, `CompletePackage`'s metadata, `RootPackage`'s root-only state, and `BasePackage::$id`. Link values and release dates still have no wire image, so the methods carrying them remain explicit errors.
Diffstat (limited to 'crates/shirabe-php-rpc')
-rw-r--r--crates/shirabe-php-rpc/php/runtime/Composer/EventDispatcher/Event.php30
-rw-r--r--crates/shirabe-php-rpc/php/stubs/Composer/Config.php212
-rw-r--r--crates/shirabe-php-rpc/php/stubs/Composer/Downloader/DownloadManager.php128
-rw-r--r--crates/shirabe-php-rpc/php/stubs/Composer/EventDispatcher/EventDispatcher.php23
-rw-r--r--crates/shirabe-php-rpc/php/stubs/Composer/IO/BaseIO.php20
-rw-r--r--crates/shirabe-php-rpc/php/stubs/Composer/IO/BufferIO.php9
-rw-r--r--crates/shirabe-php-rpc/php/stubs/Composer/IO/ConsoleIO.php9
-rw-r--r--crates/shirabe-php-rpc/php/stubs/Composer/Installer/InstallationManager.php22
-rw-r--r--crates/shirabe-php-rpc/php/stubs/Composer/Package/BasePackage.php20
-rw-r--r--crates/shirabe-php-rpc/php/stubs/Composer/Package/Package.php6
-rw-r--r--crates/shirabe-php-rpc/php/stubs/Composer/PartialComposer.php20
-rw-r--r--crates/shirabe-php-rpc/php/stubs/Composer/Repository/ArrayRepository.php20
-rw-r--r--crates/shirabe-php-rpc/php/stubs/Composer/Repository/FilesystemRepository.php9
-rw-r--r--crates/shirabe-php-rpc/php/stubs/Composer/Repository/RepositoryManager.php25
-rw-r--r--crates/shirabe-php-rpc/php/stubs/Composer/Script/Event.php6
-rw-r--r--crates/shirabe-php-rpc/php/worker.php55
-rw-r--r--crates/shirabe-php-rpc/src/lib.rs8
17 files changed, 539 insertions, 83 deletions
diff --git a/crates/shirabe-php-rpc/php/runtime/Composer/EventDispatcher/Event.php b/crates/shirabe-php-rpc/php/runtime/Composer/EventDispatcher/Event.php
index 0d35ac55..e2c63439 100644
--- a/crates/shirabe-php-rpc/php/runtime/Composer/EventDispatcher/Event.php
+++ b/crates/shirabe-php-rpc/php/runtime/Composer/EventDispatcher/Event.php
@@ -4,9 +4,10 @@
// lives in both worlds at once: an instance revived from a Rust handle proxies every call over
// RPC (like a generated stub), while an instance constructed natively — real Composer code in
// this process does `new PreCommandRunEvent(...)`, whose parent constructor lands here — is a
-// faithful in-process port of the real base class. The two modes are told apart by the
-// constructor arguments; `__shirabeRustHandleDescriptor()` returns null in native mode so the
-// wire codec registers the object in the P table instead of treating it as a Rust handle.
+// faithful in-process port of the real base class. Proxy revival binds the handle without
+// running the constructor, so the constructor below is the native mode alone;
+// `__shirabeRustHandleDescriptor()` returns null there so the wire codec registers the object in
+// the P table instead of treating it as a Rust handle.
namespace Composer\EventDispatcher;
@@ -29,29 +30,20 @@ class Event implements \ShirabeRustStub
/** @var bool Whether the event should not be passed to more listeners (native mode) */
private $propagationStopped = false;
- /**
- * Proxy revival passes (int $rhandle, int $epoch); the real class's constructor is
- * (string $name, array $args = [], array $flags = []).
- */
- public function __construct($name = null, $args = [], $flags = [])
+ public function __construct(string $name, array $args = [], array $flags = [])
{
- if (is_int($name) && func_num_args() === 2 && is_int($args)) {
- $this->__rhandle = $name;
- $this->__epoch = $args;
-
- return;
- }
- if (!is_string($name)) {
- throw new \RuntimeException(
- 'Shirabe does not support constructing ' . static::class . ' inside the plugin process without an event name'
- );
- }
$this->__rhandle = null;
$this->name = $name;
$this->args = $args;
$this->flags = $flags;
}
+ public function __shirabeBind(int $rhandle, int $epoch): void
+ {
+ $this->__rhandle = $rhandle;
+ $this->__epoch = $epoch;
+ }
+
public function __destruct()
{
if ($this->__rhandle !== null) {
diff --git a/crates/shirabe-php-rpc/php/stubs/Composer/Config.php b/crates/shirabe-php-rpc/php/stubs/Composer/Config.php
new file mode 100644
index 00000000..bccb8dcb
--- /dev/null
+++ b/crates/shirabe-php-rpc/php/stubs/Composer/Config.php
@@ -0,0 +1,212 @@
+<?php
+
+// Generated by scripts/plugin-stub-generator; do not edit by hand.
+// Proxy stub for Composer\Config: the public surface forwards to the Rust-side entity over RPC.
+
+namespace Composer;
+
+use Composer\Advisory\Auditor;
+use Composer\Config\ConfigSourceInterface;
+use Composer\IO\IOInterface;
+use Composer\Util\ProcessExecutor;
+
+class Config implements \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 __construct(bool $useEnvironment = true, ?string $baseDir = null)
+ {
+ [$this->__rhandle, $this->__epoch] = \ShirabeRpcRuntime::callRust(0, '__shirabeConstruct', [static::class, [$useEnvironment, $baseDir]]);
+ \ShirabeRustObjectRegistry::adopt($this->__rhandle, $this);
+ }
+
+ public const SOURCE_DEFAULT = 'default';
+ public const SOURCE_COMMAND = 'command';
+ public const SOURCE_UNKNOWN = 'unknown';
+ public const RELATIVE_PATHS = 1;
+
+ public static $defaultConfig = [
+ 'process-timeout' => 300,
+ 'use-include-path' => false,
+ 'allow-plugins' => [],
+ 'use-parent-dir' => 'prompt',
+ 'preferred-install' => 'dist',
+ 'audit' => ['ignore' => [], 'abandoned' => Auditor::ABANDONED_FAIL],
+ 'notify-on-install' => true,
+ 'github-protocols' => ['https', 'ssh', 'git'],
+ 'gitlab-protocol' => null,
+ 'vendor-dir' => 'vendor',
+ 'bin-dir' => '{$vendor-dir}/bin',
+ 'cache-dir' => '{$home}/cache',
+ 'data-dir' => '{$home}',
+ 'cache-files-dir' => '{$cache-dir}/files',
+ 'cache-repo-dir' => '{$cache-dir}/repo',
+ 'cache-vcs-dir' => '{$cache-dir}/vcs',
+ 'cache-ttl' => 15552000, // 6 months
+ 'cache-files-ttl' => null, // fallback to cache-ttl
+ 'cache-files-maxsize' => '300MiB',
+ 'cache-read-only' => false,
+ 'bin-compat' => 'auto',
+ 'discard-changes' => false,
+ 'autoloader-suffix' => null,
+ 'sort-packages' => false,
+ 'optimize-autoloader' => false,
+ 'classmap-authoritative' => false,
+ 'apcu-autoloader' => false,
+ 'prepend-autoloader' => true,
+ 'update-with-minimal-changes' => false,
+ 'github-domains' => ['github.com'],
+ 'bitbucket-expose-hostname' => true,
+ 'disable-tls' => false,
+ 'secure-http' => true,
+ 'secure-svn-domains' => [],
+ 'cafile' => null,
+ 'capath' => null,
+ 'github-expose-hostname' => true,
+ 'gitlab-domains' => ['gitlab.com'],
+ 'store-auths' => 'prompt',
+ 'platform' => [],
+ 'archive-format' => 'tar',
+ 'archive-dir' => '.',
+ 'htaccess-protect' => true,
+ 'use-github-api' => true,
+ 'lock' => true,
+ 'platform-check' => 'php-only',
+ 'bitbucket-oauth' => [],
+ 'github-oauth' => [],
+ 'gitlab-oauth' => [],
+ 'gitlab-token' => [],
+ 'http-basic' => [],
+ 'bearer' => [],
+ 'custom-headers' => [],
+ 'bump-after-update' => false,
+ 'allow-missing-requirements' => false,
+ 'client-certificate' => [],
+ 'forgejo-domains' => ['codeberg.org'],
+ 'forgejo-token' => [],
+ ];
+ public static $defaultRepositories = [
+ 'packagist.org' => [
+ 'type' => 'composer',
+ 'url' => 'https://repo.packagist.org',
+ ],
+ ];
+
+ public static function disableProcessTimeout(): void
+ {
+ // Override global timeout set earlier by environment or config
+ ProcessExecutor::setTimeout(0);
+ }
+
+ public function setBaseDir(?string $baseDir): void
+ {
+ \ShirabeRpcRuntime::callRust($this->__rhandle, 'setBaseDir', [$baseDir]);
+ }
+
+ public function setConfigSource(ConfigSourceInterface $source): void
+ {
+ \ShirabeRpcRuntime::callRust($this->__rhandle, 'setConfigSource', [$source]);
+ }
+
+ public function getConfigSource(): ConfigSourceInterface
+ {
+ return \ShirabeRpcRuntime::callRust($this->__rhandle, 'getConfigSource', []);
+ }
+
+ public function setAuthConfigSource(ConfigSourceInterface $source): void
+ {
+ \ShirabeRpcRuntime::callRust($this->__rhandle, 'setAuthConfigSource', [$source]);
+ }
+
+ public function getAuthConfigSource(): ConfigSourceInterface
+ {
+ return \ShirabeRpcRuntime::callRust($this->__rhandle, 'getAuthConfigSource', []);
+ }
+
+ public function setLocalAuthConfigSource(ConfigSourceInterface $source): void
+ {
+ \ShirabeRpcRuntime::callRust($this->__rhandle, 'setLocalAuthConfigSource', [$source]);
+ }
+
+ public function getLocalAuthConfigSource(): ?ConfigSourceInterface
+ {
+ return \ShirabeRpcRuntime::callRust($this->__rhandle, 'getLocalAuthConfigSource', []);
+ }
+
+ public function merge(array $config, string $source = self::SOURCE_UNKNOWN): void
+ {
+ \ShirabeRpcRuntime::callRust($this->__rhandle, 'merge', [$config, $source]);
+ }
+
+ public function getRepositories(): array
+ {
+ return \ShirabeRpcRuntime::callRust($this->__rhandle, 'getRepositories', []);
+ }
+
+ public function get(string $key, int $flags = 0)
+ {
+ return \ShirabeRpcRuntime::callRust($this->__rhandle, 'get', [$key, $flags]);
+ }
+
+ public function all(int $flags = 0): array
+ {
+ return \ShirabeRpcRuntime::callRust($this->__rhandle, 'all', [$flags]);
+ }
+
+ public function getSourceOfValue(string $key): string
+ {
+ return \ShirabeRpcRuntime::callRust($this->__rhandle, 'getSourceOfValue', [$key]);
+ }
+
+ public function raw(): array
+ {
+ return \ShirabeRpcRuntime::callRust($this->__rhandle, 'raw', []);
+ }
+
+ public function has(string $key): bool
+ {
+ return \ShirabeRpcRuntime::callRust($this->__rhandle, 'has', [$key]);
+ }
+
+ public function prohibitUrlByConfig(string $url, ?IOInterface $io = null, array $repoOptions = []): void
+ {
+ \ShirabeRpcRuntime::callRust($this->__rhandle, 'prohibitUrlByConfig', [$url, $io, $repoOptions]);
+ }
+}
diff --git a/crates/shirabe-php-rpc/php/stubs/Composer/Downloader/DownloadManager.php b/crates/shirabe-php-rpc/php/stubs/Composer/Downloader/DownloadManager.php
new file mode 100644
index 00000000..3828ac4a
--- /dev/null
+++ b/crates/shirabe-php-rpc/php/stubs/Composer/Downloader/DownloadManager.php
@@ -0,0 +1,128 @@
+<?php
+
+// Generated by scripts/plugin-stub-generator; do not edit by hand.
+// Proxy stub for Composer\Downloader\DownloadManager: the public surface forwards to the Rust-side entity over RPC.
+
+namespace Composer\Downloader;
+
+use Composer\Package\PackageInterface;
+use Composer\IO\IOInterface;
+use Composer\Util\Filesystem;
+use React\Promise\PromiseInterface;
+
+class DownloadManager implements \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 __construct(IOInterface $io, bool $preferSource = false, ?Filesystem $filesystem = null)
+ {
+ [$this->__rhandle, $this->__epoch] = \ShirabeRpcRuntime::callRust(0, '__shirabeConstruct', [static::class, [$io, $preferSource, $filesystem]]);
+ \ShirabeRustObjectRegistry::adopt($this->__rhandle, $this);
+ }
+
+ public function setPreferSource(bool $preferSource): self
+ {
+ \ShirabeRpcRuntime::callRust($this->__rhandle, 'setPreferSource', [$preferSource]);
+ return $this;
+ }
+
+ public function setPreferDist(bool $preferDist): self
+ {
+ \ShirabeRpcRuntime::callRust($this->__rhandle, 'setPreferDist', [$preferDist]);
+ return $this;
+ }
+
+ public function setPreferences(array $preferences): self
+ {
+ \ShirabeRpcRuntime::callRust($this->__rhandle, 'setPreferences', [$preferences]);
+ return $this;
+ }
+
+ public function setDownloader(string $type, DownloaderInterface $downloader): self
+ {
+ \ShirabeRpcRuntime::callRust($this->__rhandle, 'setDownloader', [$type, $downloader]);
+ return $this;
+ }
+
+ public function getDownloader(string $type): DownloaderInterface
+ {
+ return \ShirabeRpcRuntime::callRust($this->__rhandle, 'getDownloader', [$type]);
+ }
+
+ public function getDownloaderForPackage(PackageInterface $package): ?DownloaderInterface
+ {
+ return \ShirabeRpcRuntime::callRust($this->__rhandle, 'getDownloaderForPackage', [$package]);
+ }
+
+ public function getDownloaderType(DownloaderInterface $downloader): string
+ {
+ return \ShirabeRpcRuntime::callRust($this->__rhandle, 'getDownloaderType', [$downloader]);
+ }
+
+ public function download(PackageInterface $package, string $targetDir, ?PackageInterface $prevPackage = null): PromiseInterface
+ {
+ return \ShirabeRpcRuntime::callRust($this->__rhandle, 'download', [$package, $targetDir, $prevPackage]);
+ }
+
+ public function prepare(string $type, PackageInterface $package, string $targetDir, ?PackageInterface $prevPackage = null): PromiseInterface
+ {
+ return \ShirabeRpcRuntime::callRust($this->__rhandle, 'prepare', [$type, $package, $targetDir, $prevPackage]);
+ }
+
+ public function install(PackageInterface $package, string $targetDir): PromiseInterface
+ {
+ return \ShirabeRpcRuntime::callRust($this->__rhandle, 'install', [$package, $targetDir]);
+ }
+
+ public function update(PackageInterface $initial, PackageInterface $target, string $targetDir): PromiseInterface
+ {
+ return \ShirabeRpcRuntime::callRust($this->__rhandle, 'update', [$initial, $target, $targetDir]);
+ }
+
+ public function remove(PackageInterface $package, string $targetDir): PromiseInterface
+ {
+ return \ShirabeRpcRuntime::callRust($this->__rhandle, 'remove', [$package, $targetDir]);
+ }
+
+ public function cleanup(string $type, PackageInterface $package, string $targetDir, ?PackageInterface $prevPackage = null): PromiseInterface
+ {
+ return \ShirabeRpcRuntime::callRust($this->__rhandle, 'cleanup', [$type, $package, $targetDir, $prevPackage]);
+ }
+}
diff --git a/crates/shirabe-php-rpc/php/stubs/Composer/EventDispatcher/EventDispatcher.php b/crates/shirabe-php-rpc/php/stubs/Composer/EventDispatcher/EventDispatcher.php
index 30f8c0e8..e2369ed2 100644
--- a/crates/shirabe-php-rpc/php/stubs/Composer/EventDispatcher/EventDispatcher.php
+++ b/crates/shirabe-php-rpc/php/stubs/Composer/EventDispatcher/EventDispatcher.php
@@ -6,8 +6,11 @@
namespace Composer\EventDispatcher;
use Composer\DependencyResolver\Transaction;
+use Composer\IO\IOInterface;
+use Composer\PartialComposer;
use Composer\DependencyResolver\Operation\OperationInterface;
use Composer\Repository\RepositoryInterface;
+use Composer\Util\ProcessExecutor;
class EventDispatcher implements \ShirabeRustStub
{
@@ -16,16 +19,12 @@ class EventDispatcher implements \ShirabeRustStub
/** @var int */
protected $__epoch;
- public function __construct(int $rhandle = 0, int $epoch = 0)
+ /**
+ * 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
{
- if (func_num_args() < 2) {
- // Constructing the class from plugin code (a common idiom for e.g. `new BufferIO()`)
- // is an open question of the plugin design; only proxy instantiation passes a
- // Rust handle. Fail with a diagnosable message instead of an ArgumentCountError.
- throw new \RuntimeException(
- 'Shirabe does not support constructing ' . static::class . ' inside the plugin process yet'
- );
- }
$this->__rhandle = $rhandle;
$this->__epoch = $epoch;
}
@@ -54,6 +53,12 @@ class EventDispatcher implements \ShirabeRustStub
\ShirabeRustObjectRegistry::adopt($this->__rhandle, $this);
}
+ public function __construct(PartialComposer $composer, IOInterface $io, ?ProcessExecutor $process = null)
+ {
+ [$this->__rhandle, $this->__epoch] = \ShirabeRpcRuntime::callRust(0, '__shirabeConstruct', [static::class, [$composer, $io, $process]]);
+ \ShirabeRustObjectRegistry::adopt($this->__rhandle, $this);
+ }
+
public function setRunScripts(bool $runScripts = true): self
{
\ShirabeRpcRuntime::callRust($this->__rhandle, 'setRunScripts', [$runScripts]);
diff --git a/crates/shirabe-php-rpc/php/stubs/Composer/IO/BaseIO.php b/crates/shirabe-php-rpc/php/stubs/Composer/IO/BaseIO.php
index b3e0fb51..ecb4db2f 100644
--- a/crates/shirabe-php-rpc/php/stubs/Composer/IO/BaseIO.php
+++ b/crates/shirabe-php-rpc/php/stubs/Composer/IO/BaseIO.php
@@ -14,16 +14,12 @@ abstract class BaseIO implements IOInterface, \ShirabeRustStub
/** @var int */
protected $__epoch;
- public function __construct(int $rhandle = 0, int $epoch = 0)
+ /**
+ * 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
{
- if (func_num_args() < 2) {
- // Constructing the class from plugin code (a common idiom for e.g. `new BufferIO()`)
- // is an open question of the plugin design; only proxy instantiation passes a
- // Rust handle. Fail with a diagnosable message instead of an ArgumentCountError.
- throw new \RuntimeException(
- 'Shirabe does not support constructing ' . static::class . ' inside the plugin process yet'
- );
- }
$this->__rhandle = $rhandle;
$this->__epoch = $epoch;
}
@@ -52,6 +48,12 @@ abstract class BaseIO implements IOInterface, \ShirabeRustStub
\ShirabeRustObjectRegistry::adopt($this->__rhandle, $this);
}
+ public function __construct()
+ {
+ [$this->__rhandle, $this->__epoch] = \ShirabeRpcRuntime::callRust(0, '__shirabeConstruct', [static::class, []]);
+ \ShirabeRustObjectRegistry::adopt($this->__rhandle, $this);
+ }
+
public function isInteractive()
{
return \ShirabeRpcRuntime::callRust($this->__rhandle, 'isInteractive', []);
diff --git a/crates/shirabe-php-rpc/php/stubs/Composer/IO/BufferIO.php b/crates/shirabe-php-rpc/php/stubs/Composer/IO/BufferIO.php
index d5e59e90..b2e84d2b 100644
--- a/crates/shirabe-php-rpc/php/stubs/Composer/IO/BufferIO.php
+++ b/crates/shirabe-php-rpc/php/stubs/Composer/IO/BufferIO.php
@@ -5,8 +5,17 @@
namespace Composer\IO;
+use Symfony\Component\Console\Output\StreamOutput;
+use Symfony\Component\Console\Formatter\OutputFormatterInterface;
+
class BufferIO extends ConsoleIO
{
+ public function __construct(string $input = '', int $verbosity = StreamOutput::VERBOSITY_NORMAL, ?OutputFormatterInterface $formatter = null)
+ {
+ [$this->__rhandle, $this->__epoch] = \ShirabeRpcRuntime::callRust(0, '__shirabeConstruct', [static::class, [$input, $verbosity, $formatter]]);
+ \ShirabeRustObjectRegistry::adopt($this->__rhandle, $this);
+ }
+
public function getOutput(): string
{
return \ShirabeRpcRuntime::callRust($this->__rhandle, 'getOutput', []);
diff --git a/crates/shirabe-php-rpc/php/stubs/Composer/IO/ConsoleIO.php b/crates/shirabe-php-rpc/php/stubs/Composer/IO/ConsoleIO.php
index 0041363a..b68f50ff 100644
--- a/crates/shirabe-php-rpc/php/stubs/Composer/IO/ConsoleIO.php
+++ b/crates/shirabe-php-rpc/php/stubs/Composer/IO/ConsoleIO.php
@@ -6,10 +6,19 @@
namespace Composer\IO;
use Composer\Pcre\Preg;
+use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Helper\Table;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
class ConsoleIO extends BaseIO
{
+ public function __construct(InputInterface $input, OutputInterface $output, HelperSet $helperSet)
+ {
+ [$this->__rhandle, $this->__epoch] = \ShirabeRpcRuntime::callRust(0, '__shirabeConstruct', [static::class, [$input, $output, $helperSet]]);
+ \ShirabeRustObjectRegistry::adopt($this->__rhandle, $this);
+ }
+
public static function sanitize($messages, bool $allowNewlines = true)
{
// Match ANSI escape sequences:
diff --git a/crates/shirabe-php-rpc/php/stubs/Composer/Installer/InstallationManager.php b/crates/shirabe-php-rpc/php/stubs/Composer/Installer/InstallationManager.php
index d458d30b..7f41f6b9 100644
--- a/crates/shirabe-php-rpc/php/stubs/Composer/Installer/InstallationManager.php
+++ b/crates/shirabe-php-rpc/php/stubs/Composer/Installer/InstallationManager.php
@@ -13,6 +13,8 @@ use Composer\DependencyResolver\Operation\UpdateOperation;
use Composer\DependencyResolver\Operation\UninstallOperation;
use Composer\DependencyResolver\Operation\MarkAliasInstalledOperation;
use Composer\DependencyResolver\Operation\MarkAliasUninstalledOperation;
+use Composer\EventDispatcher\EventDispatcher;
+use Composer\Util\Loop;
use React\Promise\PromiseInterface;
class InstallationManager implements \ShirabeRustStub
@@ -22,16 +24,12 @@ class InstallationManager implements \ShirabeRustStub
/** @var int */
protected $__epoch;
- public function __construct(int $rhandle = 0, int $epoch = 0)
+ /**
+ * 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
{
- if (func_num_args() < 2) {
- // Constructing the class from plugin code (a common idiom for e.g. `new BufferIO()`)
- // is an open question of the plugin design; only proxy instantiation passes a
- // Rust handle. Fail with a diagnosable message instead of an ArgumentCountError.
- throw new \RuntimeException(
- 'Shirabe does not support constructing ' . static::class . ' inside the plugin process yet'
- );
- }
$this->__rhandle = $rhandle;
$this->__epoch = $epoch;
}
@@ -60,6 +58,12 @@ class InstallationManager implements \ShirabeRustStub
\ShirabeRustObjectRegistry::adopt($this->__rhandle, $this);
}
+ public function __construct(Loop $loop, IOInterface $io, ?EventDispatcher $eventDispatcher = null)
+ {
+ [$this->__rhandle, $this->__epoch] = \ShirabeRpcRuntime::callRust(0, '__shirabeConstruct', [static::class, [$loop, $io, $eventDispatcher]]);
+ \ShirabeRustObjectRegistry::adopt($this->__rhandle, $this);
+ }
+
public function reset(): void
{
\ShirabeRpcRuntime::callRust($this->__rhandle, 'reset', []);
diff --git a/crates/shirabe-php-rpc/php/stubs/Composer/Package/BasePackage.php b/crates/shirabe-php-rpc/php/stubs/Composer/Package/BasePackage.php
index de8037ca..9fca286a 100644
--- a/crates/shirabe-php-rpc/php/stubs/Composer/Package/BasePackage.php
+++ b/crates/shirabe-php-rpc/php/stubs/Composer/Package/BasePackage.php
@@ -14,16 +14,12 @@ abstract class BasePackage implements PackageInterface, \ShirabeRustStub
/** @var int */
protected $__epoch;
- public function __construct(int $rhandle = 0, int $epoch = 0)
+ /**
+ * 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
{
- if (func_num_args() < 2) {
- // Constructing the class from plugin code (a common idiom for e.g. `new BufferIO()`)
- // is an open question of the plugin design; only proxy instantiation passes a
- // Rust handle. Fail with a diagnosable message instead of an ArgumentCountError.
- throw new \RuntimeException(
- 'Shirabe does not support constructing ' . static::class . ' inside the plugin process yet'
- );
- }
$this->__rhandle = $rhandle;
$this->__epoch = $epoch;
}
@@ -52,6 +48,12 @@ abstract class BasePackage implements PackageInterface, \ShirabeRustStub
\ShirabeRustObjectRegistry::adopt($this->__rhandle, $this);
}
+ public function __construct(string $name)
+ {
+ [$this->__rhandle, $this->__epoch] = \ShirabeRpcRuntime::callRust(0, '__shirabeConstruct', [static::class, [$name]]);
+ \ShirabeRustObjectRegistry::adopt($this->__rhandle, $this);
+ }
+
public const STABILITY_STABLE = 0;
public const STABILITY_RC = 5;
public const STABILITY_BETA = 10;
diff --git a/crates/shirabe-php-rpc/php/stubs/Composer/Package/Package.php b/crates/shirabe-php-rpc/php/stubs/Composer/Package/Package.php
index 5b80060d..238dde3b 100644
--- a/crates/shirabe-php-rpc/php/stubs/Composer/Package/Package.php
+++ b/crates/shirabe-php-rpc/php/stubs/Composer/Package/Package.php
@@ -7,6 +7,12 @@ namespace Composer\Package;
class Package extends BasePackage
{
+ public function __construct(string $name, string $version, string $prettyVersion)
+ {
+ [$this->__rhandle, $this->__epoch] = \ShirabeRpcRuntime::callRust(0, '__shirabeConstruct', [static::class, [$name, $version, $prettyVersion]]);
+ \ShirabeRustObjectRegistry::adopt($this->__rhandle, $this);
+ }
+
public function setType(string $type): void
{
\ShirabeRpcRuntime::callRust($this->__rhandle, 'setType', [$type]);
diff --git a/crates/shirabe-php-rpc/php/stubs/Composer/PartialComposer.php b/crates/shirabe-php-rpc/php/stubs/Composer/PartialComposer.php
index c60edbb2..a48133cb 100644
--- a/crates/shirabe-php-rpc/php/stubs/Composer/PartialComposer.php
+++ b/crates/shirabe-php-rpc/php/stubs/Composer/PartialComposer.php
@@ -18,16 +18,12 @@ class PartialComposer implements \ShirabeRustStub
/** @var int */
protected $__epoch;
- public function __construct(int $rhandle = 0, int $epoch = 0)
+ /**
+ * 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
{
- if (func_num_args() < 2) {
- // Constructing the class from plugin code (a common idiom for e.g. `new BufferIO()`)
- // is an open question of the plugin design; only proxy instantiation passes a
- // Rust handle. Fail with a diagnosable message instead of an ArgumentCountError.
- throw new \RuntimeException(
- 'Shirabe does not support constructing ' . static::class . ' inside the plugin process yet'
- );
- }
$this->__rhandle = $rhandle;
$this->__epoch = $epoch;
}
@@ -56,6 +52,12 @@ class PartialComposer implements \ShirabeRustStub
\ShirabeRustObjectRegistry::adopt($this->__rhandle, $this);
}
+ public function __construct()
+ {
+ [$this->__rhandle, $this->__epoch] = \ShirabeRpcRuntime::callRust(0, '__shirabeConstruct', [static::class, []]);
+ \ShirabeRustObjectRegistry::adopt($this->__rhandle, $this);
+ }
+
public function setPackage(RootPackageInterface $package): void
{
\ShirabeRpcRuntime::callRust($this->__rhandle, 'setPackage', [$package]);
diff --git a/crates/shirabe-php-rpc/php/stubs/Composer/Repository/ArrayRepository.php b/crates/shirabe-php-rpc/php/stubs/Composer/Repository/ArrayRepository.php
index 51e6a462..a5358ff2 100644
--- a/crates/shirabe-php-rpc/php/stubs/Composer/Repository/ArrayRepository.php
+++ b/crates/shirabe-php-rpc/php/stubs/Composer/Repository/ArrayRepository.php
@@ -14,16 +14,12 @@ class ArrayRepository implements RepositoryInterface, \ShirabeRustStub
/** @var int */
protected $__epoch;
- public function __construct(int $rhandle = 0, int $epoch = 0)
+ /**
+ * 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
{
- if (func_num_args() < 2) {
- // Constructing the class from plugin code (a common idiom for e.g. `new BufferIO()`)
- // is an open question of the plugin design; only proxy instantiation passes a
- // Rust handle. Fail with a diagnosable message instead of an ArgumentCountError.
- throw new \RuntimeException(
- 'Shirabe does not support constructing ' . static::class . ' inside the plugin process yet'
- );
- }
$this->__rhandle = $rhandle;
$this->__epoch = $epoch;
}
@@ -52,6 +48,12 @@ class ArrayRepository implements RepositoryInterface, \ShirabeRustStub
\ShirabeRustObjectRegistry::adopt($this->__rhandle, $this);
}
+ public function __construct(array $packages = [])
+ {
+ [$this->__rhandle, $this->__epoch] = \ShirabeRpcRuntime::callRust(0, '__shirabeConstruct', [static::class, [$packages]]);
+ \ShirabeRustObjectRegistry::adopt($this->__rhandle, $this);
+ }
+
public function hasPackage(PackageInterface $package)
{
return \ShirabeRpcRuntime::callRust($this->__rhandle, 'hasPackage', [$package]);
diff --git a/crates/shirabe-php-rpc/php/stubs/Composer/Repository/FilesystemRepository.php b/crates/shirabe-php-rpc/php/stubs/Composer/Repository/FilesystemRepository.php
index 00e42ac6..99c225cf 100644
--- a/crates/shirabe-php-rpc/php/stubs/Composer/Repository/FilesystemRepository.php
+++ b/crates/shirabe-php-rpc/php/stubs/Composer/Repository/FilesystemRepository.php
@@ -5,10 +5,19 @@
namespace Composer\Repository;
+use Composer\Json\JsonFile;
+use Composer\Package\RootPackageInterface;
use Composer\Pcre\Preg;
+use Composer\Util\Filesystem;
class FilesystemRepository extends WritableArrayRepository
{
+ public function __construct(JsonFile $repositoryFile, bool $dumpVersions = false, ?RootPackageInterface $rootPackage = null, ?Filesystem $filesystem = null)
+ {
+ [$this->__rhandle, $this->__epoch] = \ShirabeRpcRuntime::callRust(0, '__shirabeConstruct', [static::class, [$repositoryFile, $dumpVersions, $rootPackage, $filesystem]]);
+ \ShirabeRustObjectRegistry::adopt($this->__rhandle, $this);
+ }
+
public static function safelyLoadInstalledVersions(string $path): bool
{
$installedVersionsData = @file_get_contents($path);
diff --git a/crates/shirabe-php-rpc/php/stubs/Composer/Repository/RepositoryManager.php b/crates/shirabe-php-rpc/php/stubs/Composer/Repository/RepositoryManager.php
index 5635c0dc..9f3567d3 100644
--- a/crates/shirabe-php-rpc/php/stubs/Composer/Repository/RepositoryManager.php
+++ b/crates/shirabe-php-rpc/php/stubs/Composer/Repository/RepositoryManager.php
@@ -5,7 +5,12 @@
namespace Composer\Repository;
+use Composer\IO\IOInterface;
+use Composer\Config;
+use Composer\EventDispatcher\EventDispatcher;
use Composer\Package\PackageInterface;
+use Composer\Util\HttpDownloader;
+use Composer\Util\ProcessExecutor;
class RepositoryManager implements \ShirabeRustStub
{
@@ -14,16 +19,12 @@ class RepositoryManager implements \ShirabeRustStub
/** @var int */
protected $__epoch;
- public function __construct(int $rhandle = 0, int $epoch = 0)
+ /**
+ * 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
{
- if (func_num_args() < 2) {
- // Constructing the class from plugin code (a common idiom for e.g. `new BufferIO()`)
- // is an open question of the plugin design; only proxy instantiation passes a
- // Rust handle. Fail with a diagnosable message instead of an ArgumentCountError.
- throw new \RuntimeException(
- 'Shirabe does not support constructing ' . static::class . ' inside the plugin process yet'
- );
- }
$this->__rhandle = $rhandle;
$this->__epoch = $epoch;
}
@@ -52,6 +53,12 @@ class RepositoryManager implements \ShirabeRustStub
\ShirabeRustObjectRegistry::adopt($this->__rhandle, $this);
}
+ public function __construct(IOInterface $io, Config $config, HttpDownloader $httpDownloader, ?EventDispatcher $eventDispatcher = null, ?ProcessExecutor $process = null)
+ {
+ [$this->__rhandle, $this->__epoch] = \ShirabeRpcRuntime::callRust(0, '__shirabeConstruct', [static::class, [$io, $config, $httpDownloader, $eventDispatcher, $process]]);
+ \ShirabeRustObjectRegistry::adopt($this->__rhandle, $this);
+ }
+
public function findPackage(string $name, $constraint): ?PackageInterface
{
return \ShirabeRpcRuntime::callRust($this->__rhandle, 'findPackage', [$name, $constraint]);
diff --git a/crates/shirabe-php-rpc/php/stubs/Composer/Script/Event.php b/crates/shirabe-php-rpc/php/stubs/Composer/Script/Event.php
index a93d0dfc..065e79e2 100644
--- a/crates/shirabe-php-rpc/php/stubs/Composer/Script/Event.php
+++ b/crates/shirabe-php-rpc/php/stubs/Composer/Script/Event.php
@@ -11,6 +11,12 @@ use Composer\EventDispatcher\Event as BaseEvent;
class Event extends BaseEvent
{
+ public function __construct(string $name, Composer $composer, IOInterface $io, bool $devMode = false, array $args = [], array $flags = [])
+ {
+ [$this->__rhandle, $this->__epoch] = \ShirabeRpcRuntime::callRust(0, '__shirabeConstruct', [static::class, [$name, $composer, $io, $devMode, $args, $flags]]);
+ \ShirabeRustObjectRegistry::adopt($this->__rhandle, $this);
+ }
+
public function getComposer(): Composer
{
return \ShirabeRpcRuntime::callRust($this->__rhandle, 'getComposer', []);
diff --git a/crates/shirabe-php-rpc/php/worker.php b/crates/shirabe-php-rpc/php/worker.php
index 12297c83..9a36abdd 100644
--- a/crates/shirabe-php-rpc/php/worker.php
+++ b/crates/shirabe-php-rpc/php/worker.php
@@ -25,6 +25,9 @@ interface ShirabeRustStub
* @return ?array{__rhandle: int, __class: string, __epoch: int}
*/
public function __shirabeRustHandleDescriptor(): ?array;
+
+ /** Binds this stub to an existing Rust entity, in place of running its constructor. */
+ public function __shirabeBind(int $rhandle, int $epoch): void;
}
/** Interns proxy stubs so the same Rust handle always yields the same stub instance. */
@@ -46,7 +49,10 @@ final class ShirabeRustObjectRegistry
"no proxy stub class is available for {$class}"
);
}
- $stub = new $class($rhandle, $epoch);
+ // The stub's constructor belongs to plugin code building a *new* entity; an entity that
+ // already exists is bound directly, so proxying never runs it.
+ $stub = (new ReflectionClass($class))->newInstanceWithoutConstructor();
+ $stub->__shirabeBind($rhandle, $epoch);
self::$internTable[$rhandle] = WeakReference::create($stub);
return $stub;
}
@@ -626,6 +632,53 @@ ShirabeRpcRuntime::$dispatch = [
}
return true;
},
+ // An already-fulfilled promise for a Rust-side call whose PHP signature declares
+ // PromiseInterface. The Rust future ran to completion before this is called, so there is
+ // nothing left to defer; see .ken/plugin-arch/design.md §10.1.6.
+ '__shirabe_resolved_promise' => static function ($args) {
+ if (!function_exists('React\\Promise\\resolve')) {
+ throw new RuntimeException(
+ 'react/promise is not loaded in the plugin process, so a PromiseInterface cannot be built'
+ );
+ }
+ return \React\Promise\resolve($args[0]);
+ },
+ // Drains a promise a plugin returned to the Rust side. React settles promises
+ // synchronously, so an already-settled one runs these handlers during then(); one that is
+ // still pending is an explicit error rather than a silently dropped continuation.
+ '__shirabe_settle_promise' => static function ($args) {
+ $promise = $args[0];
+ if (!$promise instanceof \React\Promise\PromiseInterface) {
+ throw new RuntimeException('__shirabe_settle_promise expects a promise handle');
+ }
+ $settled = false;
+ $value = null;
+ $rejected = false;
+ $reason = null;
+ $promise->then(
+ static function ($result) use (&$settled, &$value) {
+ $settled = true;
+ $value = $result;
+ },
+ static function ($error) use (&$settled, &$rejected, &$reason) {
+ $settled = true;
+ $rejected = true;
+ $reason = $error;
+ }
+ );
+ if (!$settled) {
+ throw new RuntimeException(
+ 'the promise returned to Shirabe is still pending; deferred resolution across the'
+ . ' RPC boundary is not implemented yet'
+ );
+ }
+ if ($rejected) {
+ throw $reason instanceof Throwable
+ ? $reason
+ : new RuntimeException('the promise returned to Shirabe was rejected with ' . gettype($reason));
+ }
+ return $value;
+ },
// For testing only: reads a public property of a P-table entity (PHPUnit asserts like
// `$plugins[0]->version` have no method to call).
'__shirabe_get_property' => static function ($args) {
diff --git a/crates/shirabe-php-rpc/src/lib.rs b/crates/shirabe-php-rpc/src/lib.rs
index ef11d542..4f9ba6b5 100644
--- a/crates/shirabe-php-rpc/src/lib.rs
+++ b/crates/shirabe-php-rpc/src/lib.rs
@@ -579,6 +579,14 @@ const STUB_FILES: &[(&str, &str)] = &[
include_str!("../php/stubs/Composer/Composer.php"),
),
(
+ "Composer/Config.php",
+ include_str!("../php/stubs/Composer/Config.php"),
+ ),
+ (
+ "Composer/Downloader/DownloadManager.php",
+ include_str!("../php/stubs/Composer/Downloader/DownloadManager.php"),
+ ),
+ (
"Composer/IO/BaseIO.php",
include_str!("../php/stubs/Composer/IO/BaseIO.php"),
),