aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/command
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-07 18:47:59 +0900
committernsfisis <nsfisis@gmail.com>2026-06-07 19:29:26 +0900
commite8d6a57d157ab778108bcb044a3dfa5952d4a5ae (patch)
treeeaa30eeee79b2c04ca95be843ae6a9dda69af246 /crates/shirabe/src/command
parentb8a50e25aafb51a6d73f9695362854cc5ed58117 (diff)
downloadphp-shirabe-e8d6a57d157ab778108bcb044a3dfa5952d4a5ae.tar.gz
php-shirabe-e8d6a57d157ab778108bcb044a3dfa5952d4a5ae.tar.zst
php-shirabe-e8d6a57d157ab778108bcb044a3dfa5952d4a5ae.zip
feat(phase-c): resolve dynamic-dispatch phase-b TODOs
Replace the PHP `call_user_func([$obj, $method], ...)` / `$obj->{'get'.$x}()` dynamic dispatches (category E) with static Rust dispatch. - json_config_source: inject the clean-update as a typed `FnOnce(&mut JsonManipulator) -> Result<bool>` closure instead of a method-name string, dropping the call_user_func_array round-trip through PhpMixed args. The auth-config method override moves into the add/remove_config_setting closures. - config_command: dispatch addConfigSetting/addProperty on the concrete JsonConfigSource via match. - locker: select getRequires/getDevRequires and getReplaces/getProvides via match on the existing handle getters (previously stubbed to empty Vec). - create_project_command: reuse the existing get_links_for_type helper. 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/config_command.rs32
-rw-r--r--crates/shirabe/src/command/create_project_command.rs10
2 files changed, 20 insertions, 22 deletions
diff --git a/crates/shirabe/src/command/config_command.rs b/crates/shirabe/src/command/config_command.rs
index 945dfcb..2099bcc 100644
--- a/crates/shirabe/src/command/config_command.rs
+++ b/crates/shirabe/src/command/config_command.rs
@@ -9,9 +9,9 @@ use shirabe_external_packages::symfony::component::console::input::InputInterfac
use shirabe_external_packages::symfony::component::console::output::OutputInterface;
use shirabe_php_shim::{
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,
+ array_filter_use_key, array_is_list, array_map, array_merge, array_unique, 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,
};
@@ -1206,12 +1206,12 @@ impl ConfigCommand {
}
}
- // TODO(phase-b): port PHP `call_user_func([$this->configSource, $method], $key, $normalizedValue)`
- let _ = (method, key, normalized_value);
- let _: PhpMixed = call_user_func(
- method,
- &[/* PhpMixed::String(key.to_string()), normalized_value */],
- );
+ let config_source = self.config_source.as_mut().unwrap();
+ match method {
+ "addConfigSetting" => config_source.add_config_setting(key, normalized_value)?,
+ "addProperty" => config_source.add_property(key, normalized_value)?,
+ _ => unreachable!(),
+ }
Ok(())
}
@@ -1246,12 +1246,14 @@ impl ConfigCommand {
.into());
}
- // TODO(phase-b): port PHP `call_user_func([$this->configSource, $method], $key, $normalizer($valuesMixed))`
- let _ = (method, key, normalizer(&values_mixed));
- let _: PhpMixed = call_user_func(
- method,
- &[/* PhpMixed::String(key.to_string()), normalizer(&values_mixed) */],
- );
+ let config_source = self.config_source.as_mut().unwrap();
+ match method {
+ "addConfigSetting" => {
+ config_source.add_config_setting(key, normalizer(&values_mixed))?
+ }
+ "addProperty" => config_source.add_property(key, normalizer(&values_mixed))?,
+ _ => unreachable!(),
+ }
Ok(())
}
diff --git a/crates/shirabe/src/command/create_project_command.rs b/crates/shirabe/src/command/create_project_command.rs
index bbde603..c2e9b99 100644
--- a/crates/shirabe/src/command/create_project_command.rs
+++ b/crates/shirabe/src/command/create_project_command.rs
@@ -557,18 +557,14 @@ impl CreateProjectCommand {
)?)),
false,
);
- for (r#type, meta) in SUPPORTED_LINK_TYPES.iter() {
- // PHP: $package->{'get'.$meta['method']}() — dynamic getter dispatch
- // TODO(phase-b): dynamic getter dispatch by name
- let _method = format!("get{}", meta.method);
- let links: Vec<crate::package::Link> = vec![];
- for link in links {
+ for (r#type, _meta) in SUPPORTED_LINK_TYPES.iter() {
+ for link in package.get_links_for_type(r#type).values() {
if link.get_pretty_constraint() == "self.version" {
config_source.add_link(
r#type,
link.get_target(),
&package.get_pretty_version(),
- );
+ )?;
}
}
}