aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/package/dumper
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-04 21:09:02 +0900
committernsfisis <nsfisis@gmail.com>2026-06-04 21:09:02 +0900
commit06e8e14520a4a38fed500581d2b75a42418b22c4 (patch)
tree573af18bf6e0933488aea9c1bac47bf4e857546d /crates/shirabe/src/package/dumper
parenta9f19862350c6fd3592d93515d869ffe07ecb399 (diff)
downloadphp-shirabe-06e8e14520a4a38fed500581d2b75a42418b22c4.tar.gz
php-shirabe-06e8e14520a4a38fed500581d2b75a42418b22c4.tar.zst
php-shirabe-06e8e14520a4a38fed500581d2b75a42418b22c4.zip
feat(package): implement PackageInterface accessor layer for Package/CompletePackage/RootPackage
Fill the trait-impl todo!() across the package accessor layer so loaded packages are actually usable (the ArrayLoader::load path depends on it): - Package: implement BasePackage/PackageInterface from struct fields and existing inherent methods; Display via get_unique_name. - CompletePackage: delegate PackageInterface to inner Package. - RootPackage: delegate CompletePackageInterface/PackageInterface to inner CompletePackage; RootPackageInterface link setters delegate to Package. Correct three unfaithful trait signatures found during implementation: - get_target_dir returns Option<String> (PHP computes a normalized value; a borrow cannot represent it, and AliasPackage could not implement &str across its aliasOf handle). - RootPackageInterface link setters take IndexMap<String, Link>, matching Package and the real ArrayLoader caller (PHP RootPackage inherits Package::setRequires; the Link[] docblock was imprecise). - get_full_pretty_version takes a DisplayMode enum instead of a raw i64; the match is now exhaustive, so it returns String without an error path. Move mirror conversion to the boundaries: PackageInterface mirror methods use Vec<Mirror> (the typed form, matching the inherent methods), with array<->Mirror conversion done by the producer (ComposerRepository) and consumer (ArrayDumper). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/package/dumper')
-rw-r--r--crates/shirabe/src/package/dumper/array_dumper.rs30
1 files changed, 14 insertions, 16 deletions
diff --git a/crates/shirabe/src/package/dumper/array_dumper.rs b/crates/shirabe/src/package/dumper/array_dumper.rs
index 3d3b27a..3523d58 100644
--- a/crates/shirabe/src/package/dumper/array_dumper.rs
+++ b/crates/shirabe/src/package/dumper/array_dumper.rs
@@ -3,9 +3,21 @@
use indexmap::IndexMap;
use shirabe_php_shim::PhpMixed;
+use crate::package::Mirror;
use crate::package::PackageInterfaceHandle;
use crate::package::SUPPORTED_LINK_TYPES;
+/// Serializes a Mirror back into the PHP array shape `{url, preferred}`.
+fn mirror_to_php(mirror: Mirror) -> PhpMixed {
+ let mut entry: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
+ entry.insert("url".to_string(), Box::new(PhpMixed::String(mirror.url)));
+ entry.insert(
+ "preferred".to_string(),
+ Box::new(PhpMixed::Bool(mirror.preferred)),
+ );
+ PhpMixed::Array(entry)
+}
+
#[derive(Debug)]
pub struct ArrayDumper;
@@ -62,14 +74,7 @@ impl ArrayDumper {
mirrors
.into_iter()
.enumerate()
- .map(|(i, m)| {
- (
- i.to_string(),
- Box::new(PhpMixed::Array(
- m.into_iter().map(|(k, v)| (k, Box::new(v))).collect(),
- )),
- )
- })
+ .map(|(i, m)| (i.to_string(), Box::new(mirror_to_php(m))))
.collect(),
)),
);
@@ -108,14 +113,7 @@ impl ArrayDumper {
mirrors
.into_iter()
.enumerate()
- .map(|(i, m)| {
- (
- i.to_string(),
- Box::new(PhpMixed::Array(
- m.into_iter().map(|(k, v)| (k, Box::new(v))).collect(),
- )),
- )
- })
+ .map(|(i, m)| (i.to_string(), Box::new(mirror_to_php(m))))
.collect(),
)),
);