diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-16 14:56:45 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-16 14:56:45 +0900 |
| commit | 2faccc227b65ab9dea0f80cd008cbf22ca4c5142 (patch) | |
| tree | 6f4e11bc37489550d68ad57d210668d0bea9cfb6 /crates/shirabe-php-rpc/php/stubs/Composer/Util/Filesystem.php | |
| parent | aa2124fe5d0c96078c034a6e4044b7e81acdf692 (diff) | |
| download | php-shirabe-2faccc227b65ab9dea0f80cd008cbf22ca4c5142.tar.gz php-shirabe-2faccc227b65ab9dea0f80cd008cbf22ca4c5142.tar.zst php-shirabe-2faccc227b65ab9dea0f80cd008cbf22ca4c5142.zip | |
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.
Diffstat (limited to 'crates/shirabe-php-rpc/php/stubs/Composer/Util/Filesystem.php')
| -rw-r--r-- | crates/shirabe-php-rpc/php/stubs/Composer/Util/Filesystem.php | 243 |
1 files changed, 243 insertions, 0 deletions
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 @@ +<?php + +// Generated by scripts/plugin-stub-generator; do not edit by hand. +// Proxy stub for Composer\Util\Filesystem: the public surface forwards to the Rust-side entity over RPC. + +namespace Composer\Util; + +use Composer\Pcre\Preg; + +class Filesystem 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 __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]); + } +} |
