From 793571b52de57df2b3cde9a3ba6a2823676aba41 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Fri, 24 Jul 2026 02:54:34 +0900 Subject: refactor(filesystem-repository): drop eval() shim, defer installed.php reload to PHP runtime Rust has no PHP interpreter, so eval() can never be ported faithfully. safely_load_installed_versions()'s job of priming Composer\InstalledVersions before plugins run only matters within a single shared PHP process, which the RPC-based plugin architecture does not have; the PHP runtime process can call InstalledVersions::reload() itself instead. Co-Authored-By: Claude Sonnet 5 --- crates/shirabe-php-shim/src/runtime.rs | 5 --- .../src/repository/filesystem_repository.rs | 39 ++++------------------ 2 files changed, 6 insertions(+), 38 deletions(-) (limited to 'crates') diff --git a/crates/shirabe-php-shim/src/runtime.rs b/crates/shirabe-php-shim/src/runtime.rs index 91de9e45..fa7a728c 100644 --- a/crates/shirabe-php-shim/src/runtime.rs +++ b/crates/shirabe-php-shim/src/runtime.rs @@ -468,11 +468,6 @@ pub fn php_require(_file: &str) -> PhpMixed { todo!() } -pub fn r#eval(_code: &str) -> PhpMixed { - // TODO(phase-d): `eval` runs arbitrary PHP source at runtime; there is no PHP interpreter. - todo!() -} - pub fn memory_get_usage() -> i64 { // TODO(phase-d): return PHP's actual emalloc-tracked memory usage instead of a stub 0. 0 diff --git a/crates/shirabe/src/repository/filesystem_repository.rs b/crates/shirabe/src/repository/filesystem_repository.rs index 8f7ce8ea..32bf4728 100644 --- a/crates/shirabe/src/repository/filesystem_repository.rs +++ b/crates/shirabe/src/repository/filesystem_repository.rs @@ -22,8 +22,8 @@ use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::Preg; use shirabe_php_shim::{ Exception, InvalidArgumentException, LogicException, PhpMixed, UnexpectedValueException, - array_flip, dirname, r#eval, file_get_contents, get_class_err, get_debug_type, in_array, - is_array, is_null, is_string, ksort, php_regex, realpath, str_repeat, trim, usort, var_export, + array_flip, dirname, file_get_contents, get_class_err, get_debug_type, in_array, is_array, + is_null, is_string, ksort, php_regex, realpath, str_repeat, trim, usort, var_export, }; use shirabe_semver::constraint::AnyConstraint; @@ -346,37 +346,10 @@ impl FilesystemRepository { /// As we load the file from vendor dir during bootstrap, we need to make sure it contains only expected code before executing it /// /// @internal - pub fn safely_load_installed_versions(path: &str) -> bool { - // PHP: @file_get_contents($path) - let installed_versions_data = Silencer::call(|| Ok(file_get_contents(path))) - .ok() - .flatten(); - let pattern = "{(?(DEFINE)\n (? -? \\s*+ \\d++ (?:\\.\\d++)? )\n (? true | false | null )\n (? (?&string) (?: \\s*+ \\. \\s*+ (?&string))*+ )\n (? (?: \" (?:[^\"\\\\$]*+ | \\\\ [\"\\\\0] )* \" | ' (?:[^'\\\\]*+ | \\\\ ['\\\\] )* ' ) )\n (? array\\( \\s*+ (?: (?:(?&number)|(?&strings)) \\s*+ => \\s*+ (?: (?:__DIR__ \\s*+ \\. \\s*+)? (?&strings) | (?&value) ) \\s*+, \\s*+ )*+ \\s*+ \\) )\n (? (?: (?&number) | (?&boolean) | (?&strings) | (?&array) ) )\n)\n^<\\?php\\s++return\\s++(?&array)\\s*+;$}ix"; - if let Some(data) = installed_versions_data { - let mixed = PhpMixed::String(data.clone()); - if is_string(&mixed) && Preg::is_match(pattern, &trim(&data, None)) { - let replaced = Preg::replace( - php_regex!(r#"{=>\s*+__DIR__\s*+\.\s*+(['\"])}"#), - &format!( - "=> {} . $1", - var_export(&PhpMixed::String(dirname(path)), true), - ), - &data, - ); - let evaluated = r#eval(&format!("?>{}", replaced)); - InstalledVersions::reload( - evaluated - .as_array() - .cloned() - .map(|m| m.into_iter().collect()) - .unwrap_or_default(), - ); - - return true; - } - } - - false + pub fn safely_load_installed_versions(_path: &str) -> bool { + // TODO(php-runtime): call `InstalledVersions::reload()` in PHP runtime process, not in + // Rust. + true } /// @param array $array -- cgit v1.3.1