aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/mozart-registry/src/repository/packagist_repo.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-02 18:04:29 +0900
committernsfisis <nsfisis@gmail.com>2026-05-02 18:04:29 +0900
commit33fe16285acbed1f5146c2d746eba2295bd57688 (patch)
tree0df8f83fd9e95e87406e350ce48816451b6d07af /crates/mozart-registry/src/repository/packagist_repo.rs
parent82501a36a0fa6725d656742da42c860e75a89b89 (diff)
parentc446337e75ba9fd674dd63d56ec25d7bd5b5fa31 (diff)
downloadphp-mozart-33fe16285acbed1f5146c2d746eba2295bd57688.tar.gz
php-mozart-33fe16285acbed1f5146c2d746eba2295bd57688.tar.zst
php-mozart-33fe16285acbed1f5146c2d746eba2295bd57688.zip
Merge branch 'test/di'
Diffstat (limited to 'crates/mozart-registry/src/repository/packagist_repo.rs')
-rw-r--r--crates/mozart-registry/src/repository/packagist_repo.rs57
1 files changed, 57 insertions, 0 deletions
diff --git a/crates/mozart-registry/src/repository/packagist_repo.rs b/crates/mozart-registry/src/repository/packagist_repo.rs
new file mode 100644
index 0000000..6f9b687
--- /dev/null
+++ b/crates/mozart-registry/src/repository/packagist_repo.rs
@@ -0,0 +1,57 @@
+//! [`Repository`] backed by the live Packagist HTTP API.
+//!
+//! Wraps the existing [`crate::packagist::fetch_package_versions`] so the
+//! resolver sees the same data either through this trait or via the legacy
+//! direct call. Construction takes ownership of the [`Cache`] handle so
+//! callers no longer thread it through `ResolveRequest` / `LockFileGenerationRequest`.
+
+use super::{LoadResult, NamedPackagistVersion, PackageQuery, Repository};
+use crate::cache::Cache;
+use crate::packagist;
+
+pub struct PackagistRepository {
+ id: String,
+ cache: Cache,
+}
+
+impl PackagistRepository {
+ pub fn new(cache: Cache) -> Self {
+ Self {
+ id: "packagist.org".to_string(),
+ cache,
+ }
+ }
+}
+
+#[async_trait::async_trait]
+impl Repository for PackagistRepository {
+ fn id(&self) -> &str {
+ &self.id
+ }
+
+ async fn load_packages(&self, queries: &[PackageQuery<'_>]) -> anyhow::Result<LoadResult> {
+ let mut result = LoadResult::default();
+ for query in queries {
+ // Errors propagate to the caller. Composer's
+ // `ComposerRepository::loadAsyncPackages` distinguishes 404
+ // (empty result, no error) from transport failures (exception);
+ // Mozart's underlying `fetch_package_versions` doesn't yet make
+ // that distinction, so for now both surface as `Err` and the
+ // caller decides whether the loop wants to continue (transitive
+ // exploration) or abort (seed-time fetch failure).
+ let versions = packagist::fetch_package_versions(query.name, &self.cache).await?;
+ // A successful fetch counts as "this repo authoritatively knows
+ // the name", even if the version list is empty — mirrors
+ // Composer's `ArrayRepository::loadPackages` which adds the
+ // name to `namesFound` regardless of constraint match.
+ result.names_found.push(query.name.to_string());
+ for version in versions {
+ result.packages.push(NamedPackagistVersion {
+ name: query.name.to_string(),
+ version,
+ });
+ }
+ }
+ Ok(result)
+ }
+}