From c65cab710bb3d79db20862c9361d4dbbac8ac5d7 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 25 Jun 2026 03:20:08 +0900 Subject: feat(php-shim): model $_ENV/$_SERVER as OsString snapshots Rework the environment shim around getenv/putenv on the real environment and $_ENV/$_SERVER as startup snapshots, all over OsString. Migrate every caller off the old server()/server_argv() helpers and force the snapshots in main() before any putenv() runs. Document the porting rules in docs/dev/env-vars-porting.md. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe/src/console/application.rs | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'crates/shirabe/src/console') diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs index 251fc67..319e8dd 100644 --- a/crates/shirabe/src/console/application.rs +++ b/crates/shirabe/src/console/application.rs @@ -1402,7 +1402,10 @@ impl Application { input.borrow_mut().set_interactive(false); } - let mut shell_verbosity = shirabe_php_shim::getenv("SHELL_VERBOSITY").unwrap_or_default(); + let shell_verbosity = shirabe_php_shim::getenv("SHELL_VERBOSITY") + .unwrap_or_default() + .to_string_lossy() + .into_owned(); let shell_verbosity_int: i64 = shell_verbosity.parse().unwrap_or(0); let mut shell_verbosity: i64 = shell_verbosity_int; match shell_verbosity_int { @@ -1500,10 +1503,16 @@ impl Application { } if shirabe_php_shim::function_exists("putenv") { - shirabe_php_shim::putenv(&format!("SHELL_VERBOSITY={}", shell_verbosity)); + unsafe { shirabe_php_shim::putenv("SHELL_VERBOSITY", shell_verbosity.to_string()) }; } - shirabe_php_shim::env_set("SHELL_VERBOSITY", shell_verbosity.to_string()); - shirabe_php_shim::server_set("SHELL_VERBOSITY", shell_verbosity.to_string()); + shirabe_php_shim::PHP_ENV + .lock() + .unwrap() + .put("SHELL_VERBOSITY".into(), shell_verbosity.to_string().into()); + shirabe_php_shim::PHP_SERVER + .lock() + .unwrap() + .put("SHELL_VERBOSITY".into(), shell_verbosity.to_string().into()); let _ = &mut shell_verbosity; @@ -2285,7 +2294,12 @@ impl ApplicationHandle { { io.write_error(&format!( "Warning: This development build of Composer is over 60 days old. It is recommended to update it by running \"{} self-update\" to get the latest version.", - shirabe_php_shim::server_get("PHP_SELF").unwrap_or_default(), + shirabe_php_shim::PHP_SERVER + .lock() + .unwrap() + .get("PHP_SELF") + .unwrap_or_default() + .to_string_lossy(), )); } @@ -2598,8 +2612,8 @@ impl ApplicationHandle { let app = application.borrow(); (app.terminal.get_height(), app.terminal.get_width()) }; - shirabe_php_shim::putenv(&format!("LINES={}", height)); - shirabe_php_shim::putenv(&format!("COLUMNS={}", width)); + unsafe { shirabe_php_shim::putenv("LINES", height.to_string()) }; + unsafe { shirabe_php_shim::putenv("COLUMNS", width.to_string()) }; } let input: std::rc::Rc> = match input { -- cgit v1.3.1