aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/command
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-05 04:45:11 +0900
committernsfisis <nsfisis@gmail.com>2026-06-05 04:45:11 +0900
commitd0edb5b7ac3456f99c2f2576e8992cc12d60574a (patch)
treeb69546366676c06e1c8fabddb592c202436a92b2 /crates/shirabe/src/command
parent53800ab77565de1c16fb8a95e047eba1cb3a160c (diff)
downloadphp-shirabe-d0edb5b7ac3456f99c2f2576e8992cc12d60574a.tar.gz
php-shirabe-d0edb5b7ac3456f99c2f2576e8992cc12d60574a.tar.zst
php-shirabe-d0edb5b7ac3456f99c2f2576e8992cc12d60574a.zip
refactor(json): model JsonFile encode/write options as a typed struct
Replace the i64 bitmask + encode_with_indent split with a JsonEncodeOptions struct (Default = JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE, default indent). encode/write each get a default form plus an explicit encode_with_options/write_with_options variant, mirroring PHP's optional $options argument. write_with_options always encodes with self.indent, matching PHP write(). Also reconcile call sites with the PHP sources: most ported sites passed 0 where Composer omits the argument (= default flags), so JsonManipulator/ShowCommand and JsonConfigSource now use the default options; only ComposerRepository and Locker genuinely pass 0. 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/check_platform_reqs_command.rs7
-rw-r--r--crates/shirabe/src/command/config_command.rs20
-rw-r--r--crates/shirabe/src/command/fund_command.rs2
-rw-r--r--crates/shirabe/src/command/init_command.rs2
-rw-r--r--crates/shirabe/src/command/licenses_command.rs15
-rw-r--r--crates/shirabe/src/command/repository_command.rs2
-rw-r--r--crates/shirabe/src/command/search_command.rs2
-rw-r--r--crates/shirabe/src/command/show_command.rs38
8 files changed, 41 insertions, 47 deletions
diff --git a/crates/shirabe/src/command/check_platform_reqs_command.rs b/crates/shirabe/src/command/check_platform_reqs_command.rs
index bfef6a5..edacf0b 100644
--- a/crates/shirabe/src/command/check_platform_reqs_command.rs
+++ b/crates/shirabe/src/command/check_platform_reqs_command.rs
@@ -312,10 +312,9 @@ impl CheckPlatformReqsCommand {
})
.collect();
- io.write(&JsonFile::encode(
- &PhpMixed::List(rows.into_iter().map(Box::new).collect()),
- 448,
- ));
+ io.write(&JsonFile::encode(&PhpMixed::List(
+ rows.into_iter().map(Box::new).collect(),
+ )));
} else {
let rows: Vec<PhpMixed> = results
.iter()
diff --git a/crates/shirabe/src/command/config_command.rs b/crates/shirabe/src/command/config_command.rs
index 476be75..40a12e1 100644
--- a/crates/shirabe/src/command/config_command.rs
+++ b/crates/shirabe/src/command/config_command.rs
@@ -8,12 +8,11 @@ use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_external_packages::symfony::component::console::input::InputInterface;
use shirabe_external_packages::symfony::component::console::output::OutputInterface;
use shirabe_php_shim::{
- ArrayObject, InvalidArgumentException, JSON_UNESCAPED_SLASHES, JSON_UNESCAPED_UNICODE,
- JsonObject, PhpMixed, RuntimeException, array_filter, array_filter_use_key, array_is_list,
- array_map, array_merge, array_unique, call_user_func, count, escapeshellcmd, exec, explode,
- file_exists, file_get_contents, implode, in_array, is_array, is_bool, is_dir, is_numeric,
- is_object, is_string, json_encode, key, sort, sprintf, str_replace, str_starts_with, strpos,
- strtolower, system, touch, var_export,
+ ArrayObject, InvalidArgumentException, JsonObject, PhpMixed, RuntimeException, array_filter,
+ array_filter_use_key, array_is_list, array_map, array_merge, array_unique, call_user_func,
+ count, escapeshellcmd, exec, explode, file_exists, file_get_contents, implode, in_array,
+ is_array, is_bool, is_dir, is_numeric, is_object, is_string, json_encode, key, sort, sprintf,
+ str_replace, str_starts_with, strpos, strtolower, system, touch, var_export,
};
use crate::advisory::Auditor;
@@ -26,6 +25,7 @@ use crate::console::input::InputArgument;
use crate::factory::Factory;
use crate::io::IOInterface;
use crate::io::IOInterfaceImmutable;
+use crate::json::JsonEncodeOptions;
use crate::json::JsonFile;
use crate::package::base_package::{self, BasePackage};
use crate::util::Filesystem;
@@ -476,7 +476,13 @@ impl ConfigCommand {
}
let value_str = if is_array(&value) || is_object(&value) || is_bool(&value) {
- JsonFile::encode(&value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)
+ JsonFile::encode_with_options(
+ &value,
+ JsonEncodeOptions {
+ pretty_print: false,
+ ..Default::default()
+ },
+ )
} else {
value.as_string().unwrap_or("").to_string()
};
diff --git a/crates/shirabe/src/command/fund_command.rs b/crates/shirabe/src/command/fund_command.rs
index 9d5720e..a01a67c 100644
--- a/crates/shirabe/src/command/fund_command.rs
+++ b/crates/shirabe/src/command/fund_command.rs
@@ -162,7 +162,7 @@ impl FundCommand {
io.write("Thank you!");
} else if format == "json" {
let fundings_mixed: PhpMixed = fundings.clone().into();
- io.write(&JsonFile::encode(&fundings_mixed, 448));
+ io.write(&JsonFile::encode(&fundings_mixed));
} else {
io.write("No funding links were found in your package dependencies. This doesn't mean they don't need your support!");
}
diff --git a/crates/shirabe/src/command/init_command.rs b/crates/shirabe/src/command/init_command.rs
index e401534..a46b6ca 100644
--- a/crates/shirabe/src/command/init_command.rs
+++ b/crates/shirabe/src/command/init_command.rs
@@ -301,7 +301,7 @@ impl InitCommand {
.into_iter()
.map(|(k, v)| (k, Box::new(v)))
.collect();
- let json = JsonFile::encode(&PhpMixed::Array(options_for_encode.clone()), 448);
+ let json = JsonFile::encode(&PhpMixed::Array(options_for_encode.clone()));
if input.is_interactive() {
io.write_error3(&format!("\n{}\n", json), true, io_interface::NORMAL);
diff --git a/crates/shirabe/src/command/licenses_command.rs b/crates/shirabe/src/command/licenses_command.rs
index ddd7d3d..81f9b67 100644
--- a/crates/shirabe/src/command/licenses_command.rs
+++ b/crates/shirabe/src/command/licenses_command.rs
@@ -247,15 +247,12 @@ impl LicensesCommand {
.collect(),
),
);
- io.write(&JsonFile::encode(
- &PhpMixed::Array(
- output_map
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
- ),
- 448,
- ));
+ io.write(&JsonFile::encode(&PhpMixed::Array(
+ output_map
+ .into_iter()
+ .map(|(k, v)| (k, Box::new(v)))
+ .collect(),
+ )));
}
"summary" => {
let mut used_licenses: IndexMap<String, i64> = IndexMap::new();
diff --git a/crates/shirabe/src/command/repository_command.rs b/crates/shirabe/src/command/repository_command.rs
index bf000e4..d57a98d 100644
--- a/crates/shirabe/src/command/repository_command.rs
+++ b/crates/shirabe/src/command/repository_command.rs
@@ -380,7 +380,7 @@ impl RepositoryCommand {
.get("url")
.and_then(|v| v.as_string())
.map(|s| s.to_string())
- .unwrap_or_else(|| JsonFile::encode(repo, 448));
+ .unwrap_or_else(|| JsonFile::encode(repo));
io.write(&format!("[{}] <info>{}</info> {}", name, r#type, url));
}
}
diff --git a/crates/shirabe/src/command/search_command.rs b/crates/shirabe/src/command/search_command.rs
index 5d6a31b..2c5d27d 100644
--- a/crates/shirabe/src/command/search_command.rs
+++ b/crates/shirabe/src/command/search_command.rs
@@ -182,7 +182,7 @@ impl SearchCommand {
} else if format == "json" {
// TODO(phase-b): JsonFile::encode takes &PhpMixed; convert Vec<SearchResult> into PhpMixed
let _ = &results;
- io.write(&JsonFile::encode(&PhpMixed::Null, 448));
+ io.write(&JsonFile::encode(&PhpMixed::Null));
}
Ok(0)
diff --git a/crates/shirabe/src/command/show_command.rs b/crates/shirabe/src/command/show_command.rs
index f992798..bb7b909 100644
--- a/crates/shirabe/src/command/show_command.rs
+++ b/crates/shirabe/src/command/show_command.rs
@@ -575,12 +575,9 @@ impl ShowCommand {
.collect(),
))]),
);
- self.get_io().write(&JsonFile::encode(
- &PhpMixed::Array(
- wrapper.into_iter().map(|(k, v)| (k, Box::new(v))).collect(),
- ),
- 0,
- ));
+ self.get_io().write(&JsonFile::encode(&PhpMixed::Array(
+ wrapper.into_iter().map(|(k, v)| (k, Box::new(v))).collect(),
+ )));
} else {
self.display_package_tree(vec![array_tree]);
}
@@ -700,10 +697,9 @@ impl ShowCommand {
.collect(),
),
);
- self.get_io().write(&JsonFile::encode(
- &PhpMixed::Array(wrapper.into_iter().map(|(k, v)| (k, Box::new(v))).collect()),
- 0,
- ));
+ self.get_io().write(&JsonFile::encode(&PhpMixed::Array(
+ wrapper.into_iter().map(|(k, v)| (k, Box::new(v))).collect(),
+ )));
} else {
self.display_package_tree(array_tree);
}
@@ -1152,15 +1148,12 @@ impl ShowCommand {
);
}
let io = self.get_io();
- io.write(&JsonFile::encode(
- &PhpMixed::Array(
- json_map
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
- ),
- 0,
- ));
+ io.write(&JsonFile::encode(&PhpMixed::Array(
+ json_map
+ .into_iter()
+ .map(|(k, v)| (k, Box::new(v)))
+ .collect(),
+ )));
} else {
if input.get_option("latest").as_bool() == Some(true)
&& view_data.values().any(|v| !v.is_empty())
@@ -2025,10 +2018,9 @@ impl ShowCommand {
json = Self::append_links(json, package);
- self.get_io().write(&JsonFile::encode(
- &PhpMixed::Array(json.into_iter().map(|(k, v)| (k, Box::new(v))).collect()),
- 0,
- ));
+ self.get_io().write(&JsonFile::encode(&PhpMixed::Array(
+ json.into_iter().map(|(k, v)| (k, Box::new(v))).collect(),
+ )));
Ok(())
}