aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/command
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-07 20:51:59 +0900
committernsfisis <nsfisis@gmail.com>2026-08-07 20:51:59 +0900
commitae365645730b95d5b01b0df7382b91668d5fa24e (patch)
tree962e3abb51132097ff11a79d453e058945ae699c /crates/shirabe/src/command
parentf749a47804cd296a3059cd3f8079c62dbaa5fdc0 (diff)
downloadphp-shirabe-ae365645730b95d5b01b0df7382b91668d5fa24e.tar.gz
php-shirabe-ae365645730b95d5b01b0df7382b91668d5fa24e.tar.zst
php-shirabe-ae365645730b95d5b01b0df7382b91668d5fa24e.zip
refactor(platform-repository): fetch the PHP runtime in one RPC call
The RuntimeInterface seam asked the worker one question at a time: a round trip per loaded extension, per ReflectionExtension::info() output and per constant, so a single `show --platform` cost 70 to 100 of them. A `platform` dispatch entry now answers all of it as one PHP array, which shirabe-php-rpc decodes into a OnceLock-cached PlatformInfo, the way the diagnose command already works. Composer\Platform\Runtime therefore has no Rust counterpart any more. Its work belongs to the running interpreter, and invoke()/construct() could only be ported as a whitelist that panicked on anything unlisted; it is ported as PHP into the worker instead, and PlatformRepository reads the answers off PlatformInfo. Accessors panic on a name the payload does not carry, so the worker and its consumers cannot drift apart unnoticed. The tests describe the runtime as payload data where they used to mock the seam, with the datasets unchanged. The one loss is the call-count assertion of test_inet_pton_regression: the payload reports the result of `@inet_pton('::')` rather than answering a call. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/command')
-rw-r--r--crates/shirabe/src/command/base_dependency_command.rs4
-rw-r--r--crates/shirabe/src/command/check_platform_reqs_command.rs2
-rw-r--r--crates/shirabe/src/command/completion_trait.rs6
-rw-r--r--crates/shirabe/src/command/create_project_command.rs2
-rw-r--r--crates/shirabe/src/command/diagnose_command.rs2
-rw-r--r--crates/shirabe/src/command/init_command.rs2
-rw-r--r--crates/shirabe/src/command/package_discovery_trait.rs2
-rw-r--r--crates/shirabe/src/command/require_command.rs8
-rw-r--r--crates/shirabe/src/command/search_command.rs2
-rw-r--r--crates/shirabe/src/command/show_command.rs8
-rw-r--r--crates/shirabe/src/command/suggests_command.rs4
11 files changed, 28 insertions, 14 deletions
diff --git a/crates/shirabe/src/command/base_dependency_command.rs b/crates/shirabe/src/command/base_dependency_command.rs
index c4399f34..46cc654f 100644
--- a/crates/shirabe/src/command/base_dependency_command.rs
+++ b/crates/shirabe/src/command/base_dependency_command.rs
@@ -78,7 +78,7 @@ pub trait BaseDependencyCommand: BaseCommand {
.map(|(k, v)| (k, PhpMixed::String(v)))
.collect();
repos.push(crate::repository::RepositoryInterfaceHandle::new(
- PlatformRepository::new(vec![], platform_overrides)?,
+ PlatformRepository::new(vec![], platform_overrides, None, None)?,
));
} else {
let repository_manager = composer.get_repository_manager().clone();
@@ -109,7 +109,7 @@ pub trait BaseDependencyCommand: BaseCommand {
.into_iter()
.collect();
repos.push(crate::repository::RepositoryInterfaceHandle::new(
- PlatformRepository::new(vec![], platform_overrides)?,
+ PlatformRepository::new(vec![], platform_overrides, None, None)?,
));
}
diff --git a/crates/shirabe/src/command/check_platform_reqs_command.rs b/crates/shirabe/src/command/check_platform_reqs_command.rs
index 903e0c4c..4e105e69 100644
--- a/crates/shirabe/src/command/check_platform_reqs_command.rs
+++ b/crates/shirabe/src/command/check_platform_reqs_command.rs
@@ -290,7 +290,7 @@ impl Command for CheckPlatformReqsCommand {
requires_sorted.sort_by(|a, b| a.0.cmp(&b.0));
installed_repo.add_repository(crate::repository::RepositoryInterfaceHandle::new(
- PlatformRepository::new(vec![], indexmap::IndexMap::new())?,
+ PlatformRepository::new(vec![], indexmap::IndexMap::new(), None, None)?,
));
let installed_repo_with_platform = installed_repo;
diff --git a/crates/shirabe/src/command/completion_trait.rs b/crates/shirabe/src/command/completion_trait.rs
index bdd42dff..67ab23be 100644
--- a/crates/shirabe/src/command/completion_trait.rs
+++ b/crates/shirabe/src/command/completion_trait.rs
@@ -80,14 +80,14 @@ pub trait CompletionTrait: BaseCommand {
.into_iter()
.map(|(k, v)| (k, PhpMixed::String(v)))
.collect();
- PlatformRepository::new(vec![], overrides)?
+ PlatformRepository::new(vec![], overrides, None, None)?
} else {
let platform_cfg = composer.get_config().borrow().get("platform");
let overrides: IndexMap<String, PhpMixed> = platform_cfg
.as_array()
.map(|m| m.iter().map(|(k, v)| (k.clone(), v.clone())).collect())
.unwrap_or_default();
- PlatformRepository::new(vec![], overrides)?
+ PlatformRepository::new(vec![], overrides, None, None)?
};
if input.get_completion_value().is_empty() {
// to reduce noise, when no text is yet entered we list only two entries for ext- and lib- prefixes
@@ -286,7 +286,7 @@ pub trait CompletionTrait: BaseCommand {
.as_array()
.map(|m| m.iter().map(|(k, v)| (k.clone(), v.clone())).collect())
.unwrap_or_default();
- let mut repos = PlatformRepository::new(vec![], overrides)?;
+ let mut repos = PlatformRepository::new(vec![], overrides, None, None)?;
let pattern =
base_package::package_name_to_regexp(&format!("{}*", input.get_completion_value()));
diff --git a/crates/shirabe/src/command/create_project_command.rs b/crates/shirabe/src/command/create_project_command.rs
index dcf0e0f8..aa1b79a8 100644
--- a/crates/shirabe/src/command/create_project_command.rs
+++ b/crates/shirabe/src/command/create_project_command.rs
@@ -684,6 +684,8 @@ impl CreateProjectCommand {
.collect(),
_ => indexmap::IndexMap::new(),
},
+ None,
+ None,
)?;
// find the latest version if there are multiple
diff --git a/crates/shirabe/src/command/diagnose_command.rs b/crates/shirabe/src/command/diagnose_command.rs
index 8483eb56..65240e51 100644
--- a/crates/shirabe/src/command/diagnose_command.rs
+++ b/crates/shirabe/src/command/diagnose_command.rs
@@ -1223,7 +1223,7 @@ impl Command for DiagnoseCommand {
let platform_overrides_unboxed: indexmap::IndexMap<String, PhpMixed> =
platform_overrides.into_iter().collect();
let mut platform_repo =
- PlatformRepository::new(vec![], platform_overrides_unboxed).unwrap();
+ PlatformRepository::new(vec![], platform_overrides_unboxed, None, None).unwrap();
let php_pkg = <PlatformRepository as crate::repository::RepositoryInterface>::find_package(
&mut platform_repo,
"php",
diff --git a/crates/shirabe/src/command/init_command.rs b/crates/shirabe/src/command/init_command.rs
index f2bf19d7..5168b2ba 100644
--- a/crates/shirabe/src/command/init_command.rs
+++ b/crates/shirabe/src/command/init_command.rs
@@ -830,7 +830,7 @@ impl Command for InitCommand {
let mut repos: Vec<crate::repository::RepositoryInterfaceHandle> =
vec![crate::repository::RepositoryInterfaceHandle::new(
- PlatformRepository::new(vec![], IndexMap::new())?,
+ PlatformRepository::new(vec![], IndexMap::new(), None, None)?,
)];
let mut create_default_packagist_repo = true;
for repo in &repositories {
diff --git a/crates/shirabe/src/command/package_discovery_trait.rs b/crates/shirabe/src/command/package_discovery_trait.rs
index 5c921e95..db7db488 100644
--- a/crates/shirabe/src/command/package_discovery_trait.rs
+++ b/crates/shirabe/src/command/package_discovery_trait.rs
@@ -42,7 +42,7 @@ pub trait PackageDiscoveryTrait: BaseCommand {
// PHP: array_merge([new PlatformRepository], RepositoryFactory::defaultReposWithDefaultManager($this->getIO()))
let mut repos: Vec<crate::repository::RepositoryInterfaceHandle> =
vec![crate::repository::RepositoryInterfaceHandle::new(
- PlatformRepository::new(vec![], IndexMap::new())
+ PlatformRepository::new(vec![], IndexMap::new(), None, None)
.expect("PlatformRepository::new should not fail"),
)];
let io_owned: std::rc::Rc<std::cell::RefCell<dyn IOInterface>> = self.get_io();
diff --git a/crates/shirabe/src/command/require_command.rs b/crates/shirabe/src/command/require_command.rs
index f4410c19..85e53a37 100644
--- a/crates/shirabe/src/command/require_command.rs
+++ b/crates/shirabe/src/command/require_command.rs
@@ -916,8 +916,12 @@ impl Command for RequireCommand {
.map(|m| m.iter().map(|(k, v)| (k.clone(), v.clone())).collect())
.unwrap_or_default();
// initialize self.repos as it is used by the PackageDiscoveryTrait
- let platform_repo =
- PlatformRepositoryHandle::new(PlatformRepository::new(vec![], platform_overrides_map)?);
+ let platform_repo = PlatformRepositoryHandle::new(PlatformRepository::new(
+ vec![],
+ platform_overrides_map,
+ None,
+ None,
+ )?);
let mut combined: Vec<crate::repository::RepositoryInterfaceHandle> =
vec![platform_repo.clone().into()];
for repo in repos {
diff --git a/crates/shirabe/src/command/search_command.rs b/crates/shirabe/src/command/search_command.rs
index 0b675109..4bf75c8b 100644
--- a/crates/shirabe/src/command/search_command.rs
+++ b/crates/shirabe/src/command/search_command.rs
@@ -111,7 +111,7 @@ impl Command for SearchCommand {
input: std::rc::Rc<std::cell::RefCell<dyn InputInterface>>,
output: std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>,
) -> anyhow::Result<i64> {
- let platform_repo = PlatformRepository::new4(vec![], IndexMap::new(), None, None)?;
+ let platform_repo = PlatformRepository::new(vec![], IndexMap::new(), None, None)?;
let io = self.get_io();
let format = input
diff --git a/crates/shirabe/src/command/show_command.rs b/crates/shirabe/src/command/show_command.rs
index 44733531..ff20f325 100644
--- a/crates/shirabe/src/command/show_command.rs
+++ b/crates/shirabe/src/command/show_command.rs
@@ -1784,8 +1784,12 @@ impl Command for ShowCommand {
platform_overrides = p.into_iter().collect();
}
}
- let platform_repo =
- PlatformRepositoryHandle::new(PlatformRepository::new(vec![], platform_overrides)?);
+ let platform_repo = PlatformRepositoryHandle::new(PlatformRepository::new(
+ vec![],
+ platform_overrides,
+ None,
+ None,
+ )?);
let mut locked_repo: Option<RepositoryInterfaceHandle> = None;
// The single-package $package binding from PHP gets surfaced here.
diff --git a/crates/shirabe/src/command/suggests_command.rs b/crates/shirabe/src/command/suggests_command.rs
index 5c73da9b..96989dc0 100644
--- a/crates/shirabe/src/command/suggests_command.rs
+++ b/crates/shirabe/src/command/suggests_command.rs
@@ -133,6 +133,8 @@ impl Command for SuggestsCommand {
installed_repos.push(RepositoryInterfaceHandle::new(PlatformRepository::new(
vec![],
platform_overrides,
+ None,
+ None,
)?));
let locked_repo = composer.get_locker().borrow_mut().get_locked_repository(
!input
@@ -151,6 +153,8 @@ impl Command for SuggestsCommand {
installed_repos.push(RepositoryInterfaceHandle::new(PlatformRepository::new(
vec![],
platform_overrides,
+ None,
+ None,
)?));
installed_repos.push(
composer