From 2faccc227b65ab9dea0f80cd008cbf22ca4c5142 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 16 Aug 2026 14:56:45 +0900 Subject: feat(plugin): proxy Composer\Util\Filesystem into the plugin worker The class was shadowed by a guard, so a plugin doing `new Filesystem()` got an explicit error. It is classified rust-proxy and plugin-constructible and the Rust port is complete, so listing it as a stub target and answering its public surface from the entity is all it takes. The constructor rejects a caller-supplied ProcessExecutor: that class has no proxy stub, so the argument could only be a second instance the Rust side never sees. findShortestPath re-checks its arguments at the boundary because the port panics where PHP throws, and a panic would take the process down instead of reaching the plugin's catch block. phpstan/extension-installer matches upstream Composer byte for byte again. --- .../php/stubs/Composer/Util/Filesystem.php | 243 +++++++++++++++++++++ 1 file changed, 243 insertions(+) create mode 100644 crates/shirabe-php-rpc/php/stubs/Composer/Util/Filesystem.php (limited to 'crates/shirabe-php-rpc/php/stubs/Composer') diff --git a/crates/shirabe-php-rpc/php/stubs/Composer/Util/Filesystem.php b/crates/shirabe-php-rpc/php/stubs/Composer/Util/Filesystem.php new file mode 100644 index 00000000..e1532889 --- /dev/null +++ b/crates/shirabe-php-rpc/php/stubs/Composer/Util/Filesystem.php @@ -0,0 +1,243 @@ +__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 __construct(?ProcessExecutor $executor = null) + { + [$this->__rhandle, $this->__epoch] = \ShirabeRpcRuntime::callRust(0, '__shirabeConstruct', [static::class, [$executor]]); + \ShirabeRustObjectRegistry::adopt($this->__rhandle, $this); + } + + public static function trimTrailingSlash(string $path) + { + if (!Preg::isMatch('{^[/\\\\]+$}', $path)) { + $path = rtrim($path, '/\\'); + } + + return $path; + } + + public static function isLocalPath(string $path) + { + // on windows, \\foo indicates network paths so we exclude those from local paths, however it is unsafe + // on linux as file:////foo (which would be a network path \\foo on windows) will resolve to /foo which could be a local path + if (Platform::isWindows()) { + return Preg::isMatch('{^(file://(?!//)|/(?!/)|/?[a-z]:[\\\\/]|\.\.[\\\\/]|[a-z0-9_.-]+[\\\\/])}i', $path); + } + + return Preg::isMatch('{^(file://|/|/?[a-z]:[\\\\/]|\.\.[\\\\/]|[a-z0-9_.-]+[\\\\/])}i', $path); + } + + public static function getPlatformPath(string $path) + { + if (Platform::isWindows()) { + $path = Preg::replace('{^(?:file:///([a-z]):?/)}i', 'file://$1:/', $path); + } + + return Preg::replace('{^file://}i', '', $path); + } + + public static function isReadable(string $path) + { + if (is_readable($path)) { + return true; + } + + if (is_file($path)) { + return false !== Silencer::call('file_get_contents', $path, false, null, 0, 1); + } + + if (is_dir($path)) { + return false !== Silencer::call('opendir', $path); + } + + // assume false otherwise + return false; + } + + public function remove(string $file) + { + return \ShirabeRpcRuntime::callRust($this->__rhandle, 'remove', [$file]); + } + + public function isDirEmpty(string $dir) + { + return \ShirabeRpcRuntime::callRust($this->__rhandle, 'isDirEmpty', [$dir]); + } + + public function emptyDirectory(string $dir, bool $ensureDirectoryExists = true) + { + return \ShirabeRpcRuntime::callRust($this->__rhandle, 'emptyDirectory', [$dir, $ensureDirectoryExists]); + } + + public function removeDirectory(string $directory) + { + return \ShirabeRpcRuntime::callRust($this->__rhandle, 'removeDirectory', [$directory]); + } + + public function removeDirectoryAsync(string $directory) + { + return \ShirabeRpcRuntime::callRust($this->__rhandle, 'removeDirectoryAsync', [$directory]); + } + + public function removeDirectoryPhp(string $directory) + { + return \ShirabeRpcRuntime::callRust($this->__rhandle, 'removeDirectoryPhp', [$directory]); + } + + public function ensureDirectoryExists(string $directory) + { + return \ShirabeRpcRuntime::callRust($this->__rhandle, 'ensureDirectoryExists', [$directory]); + } + + public function unlink(string $path) + { + return \ShirabeRpcRuntime::callRust($this->__rhandle, 'unlink', [$path]); + } + + public function rmdir(string $path) + { + return \ShirabeRpcRuntime::callRust($this->__rhandle, 'rmdir', [$path]); + } + + public function copyThenRemove(string $source, string $target) + { + return \ShirabeRpcRuntime::callRust($this->__rhandle, 'copyThenRemove', [$source, $target]); + } + + public function copy(string $source, string $target) + { + return \ShirabeRpcRuntime::callRust($this->__rhandle, 'copy', [$source, $target]); + } + + public function rename(string $source, string $target) + { + return \ShirabeRpcRuntime::callRust($this->__rhandle, 'rename', [$source, $target]); + } + + public function findShortestPath(string $from, string $to, bool $directories = false, bool $preferRelative = false) + { + return \ShirabeRpcRuntime::callRust($this->__rhandle, 'findShortestPath', [$from, $to, $directories, $preferRelative]); + } + + public function findShortestPathCode(string $from, string $to, bool $directories = false, bool $staticCode = false, bool $preferRelative = false) + { + return \ShirabeRpcRuntime::callRust($this->__rhandle, 'findShortestPathCode', [$from, $to, $directories, $staticCode, $preferRelative]); + } + + public function isAbsolutePath(string $path) + { + return \ShirabeRpcRuntime::callRust($this->__rhandle, 'isAbsolutePath', [$path]); + } + + public function size(string $path) + { + return \ShirabeRpcRuntime::callRust($this->__rhandle, 'size', [$path]); + } + + public function normalizePath(string $path) + { + return \ShirabeRpcRuntime::callRust($this->__rhandle, 'normalizePath', [$path]); + } + + public function relativeSymlink(string $target, string $link) + { + return \ShirabeRpcRuntime::callRust($this->__rhandle, 'relativeSymlink', [$target, $link]); + } + + public function isSymlinkedDirectory(string $directory) + { + return \ShirabeRpcRuntime::callRust($this->__rhandle, 'isSymlinkedDirectory', [$directory]); + } + + public function junction(string $target, string $junction) + { + return \ShirabeRpcRuntime::callRust($this->__rhandle, 'junction', [$target, $junction]); + } + + public function isJunction(string $junction) + { + return \ShirabeRpcRuntime::callRust($this->__rhandle, 'isJunction', [$junction]); + } + + public function removeJunction(string $junction) + { + return \ShirabeRpcRuntime::callRust($this->__rhandle, 'removeJunction', [$junction]); + } + + public function filePutContentsIfModified(string $path, string $content) + { + return \ShirabeRpcRuntime::callRust($this->__rhandle, 'filePutContentsIfModified', [$path, $content]); + } + + public function safeCopy(string $source, string $target): void + { + \ShirabeRpcRuntime::callRust($this->__rhandle, 'safeCopy', [$source, $target]); + } +} -- cgit v1.3.1-4-g156e