diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-04 21:09:02 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-04 21:09:02 +0900 |
| commit | 06e8e14520a4a38fed500581d2b75a42418b22c4 (patch) | |
| tree | 573af18bf6e0933488aea9c1bac47bf4e857546d /crates/shirabe/src/package/package_interface.rs | |
| parent | a9f19862350c6fd3592d93515d869ffe07ecb399 (diff) | |
| download | php-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/package_interface.rs')
| -rw-r--r-- | crates/shirabe/src/package/package_interface.rs | 33 |
1 files changed, 19 insertions, 14 deletions
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<String>; /// 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<array{url: non-empty-string, preferred: bool}> - fn get_source_mirrors(&self) -> Option<Vec<IndexMap<String, PhpMixed>>>; + fn get_source_mirrors(&self) -> Option<Vec<Mirror>>; /// @param null|list<array{url: non-empty-string, preferred: bool}> $mirrors - fn set_source_mirrors(&mut self, mirrors: Option<Vec<IndexMap<String, PhpMixed>>>); + fn set_source_mirrors(&mut self, mirrors: Option<Vec<Mirror>>); /// 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<array{url: non-empty-string, preferred: bool}> - fn get_dist_mirrors(&self) -> Option<Vec<IndexMap<String, PhpMixed>>>; + fn get_dist_mirrors(&self) -> Option<Vec<Mirror>>; /// @param null|list<array{url: non-empty-string, preferred: bool}> $mirrors - fn set_dist_mirrors(&mut self, mirrors: Option<Vec<IndexMap<String, PhpMixed>>>); + fn set_dist_mirrors(&mut self, mirrors: Option<Vec<Mirror>>); /// 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<DateTime<Utc>>; @@ -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; -} |
