From 06e8e14520a4a38fed500581d2b75a42418b22c4 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 4 Jun 2026 21:09:02 +0900 Subject: 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 (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, 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 (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 --- crates/shirabe/src/package/package_interface.rs | 33 ++++++++++++++----------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'crates/shirabe/src/package/package_interface.rs') diff --git a/crates/shirabe/src/package/package_interface.rs b/crates/shirabe/src/package/package_interface.rs index 0ab2a09..285a30b 100644 --- a/crates/shirabe/src/package/package_interface.rs +++ b/crates/shirabe/src/package/package_interface.rs @@ -5,8 +5,21 @@ use indexmap::IndexMap; use shirabe_php_shim::PhpMixed; use crate::package::Link; +use crate::package::Mirror; use crate::repository::RepositoryInterfaceHandle; +/// Selects how `get_full_pretty_version` renders the reference. +/// +/// ref: PackageInterface::DISPLAY_SOURCE_REF_IF_DEV +/// ref: PackageInterface::DISPLAY_SOURCE_REF +/// ref: PackageInterface::DISPLAY_DIST_REF +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum DisplayMode { + SourceRefIfDev, + SourceRef, + DistRef, +} + /// Defines the essential information a package has that is used during solving/installation /// /// PackageInterface & derivatives are considered internal, you may use them in type hints but extending/implementing them is not recommended and not supported. Things may change without notice. @@ -54,7 +67,7 @@ pub trait PackageInterface: std::fmt::Display + std::fmt::Debug { /// Returns the package targetDir property /// /// @return ?string The package targetDir - fn get_target_dir(&self) -> Option<&str>; + fn get_target_dir(&self) -> Option; /// Returns the package extra data /// @@ -96,10 +109,10 @@ pub trait PackageInterface: std::fmt::Display + std::fmt::Debug { /// Returns the source mirrors of this package /// /// @return ?list - fn get_source_mirrors(&self) -> Option>>; + fn get_source_mirrors(&self) -> Option>; /// @param null|list $mirrors - fn set_source_mirrors(&mut self, mirrors: Option>>); + fn set_source_mirrors(&mut self, mirrors: Option>); /// Returns the type of the distribution archive of this version, e.g. zip, tarball /// @@ -127,10 +140,10 @@ pub trait PackageInterface: std::fmt::Display + std::fmt::Debug { /// Returns the dist mirrors of this package /// /// @return ?list - fn get_dist_mirrors(&self) -> Option>>; + fn get_dist_mirrors(&self) -> Option>; /// @param null|list $mirrors - fn set_dist_mirrors(&mut self, mirrors: Option>>); + fn set_dist_mirrors(&mut self, mirrors: Option>); /// Returns the version of this package /// @@ -149,9 +162,7 @@ pub trait PackageInterface: std::fmt::Display + std::fmt::Debug { /// @param bool $truncate If the source reference is a sha1 hash, truncate it /// @param int $displayMode One of the DISPLAY_ constants on this interface determining display of references /// @return string version - /// - /// @phpstan-param self::DISPLAY_SOURCE_REF_IF_DEV|self::DISPLAY_SOURCE_REF|self::DISPLAY_DIST_REF $displayMode - fn get_full_pretty_version(&self, truncate: bool, display_mode: i64) -> String; + fn get_full_pretty_version(&self, truncate: bool, display_mode: DisplayMode) -> String; /// Returns the release date of the package fn get_release_date(&self) -> Option>; @@ -308,9 +319,3 @@ pub trait PackageInterface: std::fmt::Display + std::fmt::Debug { None } } - -impl dyn PackageInterface { - pub const DISPLAY_SOURCE_REF_IF_DEV: i64 = 0; - pub const DISPLAY_SOURCE_REF: i64 = 1; - pub const DISPLAY_DIST_REF: i64 = 2; -} -- cgit v1.3.1