diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-25 03:20:08 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-25 03:33:09 +0900 |
| commit | c65cab710bb3d79db20862c9361d4dbbac8ac5d7 (patch) | |
| tree | b4d192237bbb8dbaa80166f1ffa24703e57243f4 /crates/shirabe/src/command | |
| parent | f73e9ab05f8d94937d2437919199d9d9681c8cde (diff) | |
| download | php-shirabe-c65cab710bb3d79db20862c9361d4dbbac8ac5d7.tar.gz php-shirabe-c65cab710bb3d79db20862c9361d4dbbac8ac5d7.tar.zst php-shirabe-c65cab710bb3d79db20862c9361d4dbbac8ac5d7.zip | |
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) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/command')
| -rw-r--r-- | crates/shirabe/src/command/init_command.rs | 52 |
1 files changed, 39 insertions, 13 deletions
diff --git a/crates/shirabe/src/command/init_command.rs b/crates/shirabe/src/command/init_command.rs index 9683b89..557ebca 100644 --- a/crates/shirabe/src/command/init_command.rs +++ b/crates/shirabe/src/command/init_command.rs @@ -10,11 +10,11 @@ use shirabe_external_packages::symfony::console::input::ArrayInput; use shirabe_external_packages::symfony::console::input::InputInterface; use shirabe_external_packages::symfony::console::output::OutputInterface; use shirabe_php_shim::{ - FILE_IGNORE_NEW_LINES, InvalidArgumentException, PHP_EOL, PhpMixed, array_filter, array_flip, - array_flip_strings, array_intersect_key, array_keys, array_map, basename, empty, explode, file, - file_exists, file_get_contents, file_put_contents, function_exists, get_current_user, implode, - is_dir, is_string, preg_quote, realpath, server_get, sprintf, str_replace, strpos, strtolower, - trim, ucwords, + FILE_IGNORE_NEW_LINES, InvalidArgumentException, PHP_EOL, PHP_SERVER, PhpMixed, array_filter, + array_flip, array_flip_strings, array_intersect_key, array_keys, array_map, basename, empty, + explode, file, file_exists, file_get_contents, file_put_contents, function_exists, + get_current_user, implode, is_dir, is_string, preg_quote, realpath, sprintf, str_replace, + strpos, strtolower, trim, ucwords, }; use shirabe_spdx_licenses::SpdxLicenses; use std::cell::RefCell; @@ -723,7 +723,11 @@ impl Command for InitCommand { .as_string() .map(|s| s.to_string()); if license.is_none() { - let default_license = server_get("COMPOSER_DEFAULT_LICENSE"); + let default_license = PHP_SERVER + .lock() + .unwrap() + .get("COMPOSER_DEFAULT_LICENSE") + .map(|value| value.to_string_lossy().into_owned()); if !empty( &default_license .clone() @@ -1163,7 +1167,21 @@ impl InitCommand { let name = self.sanitize_package_name_component(&name); let mut vendor = name.clone(); - let composer_default_vendor = server_get("COMPOSER_DEFAULT_VENDOR"); + let composer_default_vendor = PHP_SERVER + .lock() + .unwrap() + .get("COMPOSER_DEFAULT_VENDOR") + .map(|value| value.to_string_lossy().into_owned()); + let server_username = PHP_SERVER + .lock() + .unwrap() + .get("USERNAME") + .map(|value| value.to_string_lossy().into_owned()); + let server_user = PHP_SERVER + .lock() + .unwrap() + .get("USER") + .map(|value| value.to_string_lossy().into_owned()); if !empty( &composer_default_vendor .clone() @@ -1174,19 +1192,19 @@ impl InitCommand { } else if git.contains_key("github.user") { vendor = git.get("github.user").cloned().unwrap_or_default(); } else if !empty( - &server_get("USERNAME") + &server_username .clone() .map(PhpMixed::String) .unwrap_or(PhpMixed::Null), ) { - vendor = server_get("USERNAME").unwrap_or_default(); + vendor = server_username.unwrap_or_default(); } else if !empty( - &server_get("USER") + &server_user .clone() .map(PhpMixed::String) .unwrap_or(PhpMixed::Null), ) { - vendor = server_get("USER").unwrap_or_default(); + vendor = server_user.unwrap_or_default(); } else if !get_current_user().is_empty() { vendor = get_current_user(); } @@ -1200,7 +1218,11 @@ impl InitCommand { let git = self.get_git_config(); let mut author_name: Option<String> = None; - let composer_default_author = server_get("COMPOSER_DEFAULT_AUTHOR"); + let composer_default_author = PHP_SERVER + .lock() + .unwrap() + .get("COMPOSER_DEFAULT_AUTHOR") + .map(|value| value.to_string_lossy().into_owned()); if !empty( &composer_default_author .clone() @@ -1213,7 +1235,11 @@ impl InitCommand { } let mut author_email: Option<String> = None; - let composer_default_email = server_get("COMPOSER_DEFAULT_EMAIL"); + let composer_default_email = PHP_SERVER + .lock() + .unwrap() + .get("COMPOSER_DEFAULT_EMAIL") + .map(|value| value.to_string_lossy().into_owned()); if !empty( &composer_default_email .clone() |
