diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-05-10 23:58:26 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-05-10 23:58:26 +0900 |
| commit | 8871b923fa3df1935c263db155cb8bc3d59705cd (patch) | |
| tree | 4c080d383c30a0d92229f9b411f1d94976a6e707 /crates/mozart/src/composer.rs | |
| parent | 59bab6efee41a196b0d9d392167c536abbe068ba (diff) | |
| download | php-mozart-8871b923fa3df1935c263db155cb8bc3d59705cd.tar.gz php-mozart-8871b923fa3df1935c263db155cb8bc3d59705cd.tar.zst php-mozart-8871b923fa3df1935c263db155cb8bc3d59705cd.zip | |
refactor(downloader): turn DownloadManager into downloader registry
Reshape DownloadManager from a hard-coded VCS match into a registry of
DownloaderInterface instances keyed by source type, mirroring
Composer's DownloadManager — with prefer-source/dist preferences, an
IO handle, and a files cache. ArchiveManager now resolves dist
sources through a shared DownloadManager instead of calling
download_dist directly, and Composer::require / try_load take an IO
so it flows through the factory wiring.
Diffstat (limited to 'crates/mozart/src/composer.rs')
| -rw-r--r-- | crates/mozart/src/composer.rs | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/crates/mozart/src/composer.rs b/crates/mozart/src/composer.rs index 9fd8b77..c73902e 100644 --- a/crates/mozart/src/composer.rs +++ b/crates/mozart/src/composer.rs @@ -11,13 +11,14 @@ //! `Composer\Command\BaseCommand::tryComposer()` for the upstream contract //! that [`Composer::require`] and [`Composer::try_load`] are modelled on. -use std::path::{Path, PathBuf}; - use crate::factory::create_composer; use mozart_core::composer::{AutoloadGenerator, InstallationManager, Locker, RepositoryManager}; use mozart_core::config::Config; +use mozart_core::console::IoInterface; use mozart_core::downloader::DownloadManager; use mozart_core::package::RootPackageData; +use mozart_core::package::archiver::ArchiveManager; +use std::path::{Path, PathBuf}; /// Project-level Composer state. Mirrors `Composer\PartialComposer` / /// `Composer\Composer` in PHP, exposing the subset of getters command @@ -30,9 +31,10 @@ pub struct Composer { package: RootPackageData, repository_manager: RepositoryManager, installation_manager: InstallationManager, - download_manager: DownloadManager, + download_manager: std::sync::Arc<tokio::sync::Mutex<DownloadManager>>, autoload_generator: AutoloadGenerator, locker: Locker, + archive_manager: std::sync::Arc<tokio::sync::Mutex<ArchiveManager>>, } impl Composer { @@ -48,9 +50,10 @@ impl Composer { package: RootPackageData, repository_manager: RepositoryManager, installation_manager: InstallationManager, - download_manager: DownloadManager, + download_manager: std::sync::Arc<tokio::sync::Mutex<DownloadManager>>, autoload_generator: AutoloadGenerator, locker: Locker, + archive_manager: std::sync::Arc<tokio::sync::Mutex<ArchiveManager>>, ) -> Self { Self { project_dir, @@ -61,13 +64,17 @@ impl Composer { download_manager, autoload_generator, locker, + archive_manager, } } /// Load Composer state for `project_dir`, requiring a composer.json. /// Mirrors `BaseCommand::requireComposer()`, which delegates to /// `Factory::createComposer` after asserting the file exists. - pub fn require(project_dir: impl Into<PathBuf>) -> anyhow::Result<Self> { + pub fn require( + io: std::sync::Arc<std::sync::Mutex<Box<dyn IoInterface>>>, + project_dir: impl Into<PathBuf>, + ) -> anyhow::Result<Self> { let project_dir = project_dir.into(); let composer_json = project_dir.join("composer.json"); if !composer_json.exists() { @@ -76,31 +83,37 @@ impl Composer { project_dir.display() ); } - create_composer(project_dir, &composer_json) + create_composer(io, project_dir, &composer_json) } /// Load Composer state for `project_dir`, returning `None` if no /// composer.json exists. Other I/O or parse errors still propagate. /// Mirrors `BaseCommand::tryComposer()`. - pub fn try_load(project_dir: impl Into<PathBuf>) -> anyhow::Result<Option<Self>> { + pub fn try_load( + io: std::sync::Arc<std::sync::Mutex<Box<dyn IoInterface>>>, + project_dir: impl Into<PathBuf>, + ) -> anyhow::Result<Option<Self>> { let project_dir = project_dir.into(); let composer_json = project_dir.join("composer.json"); if !composer_json.exists() { return Ok(None); } - create_composer(project_dir, &composer_json).map(Some) + create_composer(io, project_dir, &composer_json).map(Some) } /// Load Composer state keyed on a specific `composer.json` file, deriving /// the project directory from `file.parent()`. Mirrors /// `ValidateCommand::createComposerInstance($file)` — Composer keys /// instances on a file rather than a directory for non-default paths. - pub fn try_load_from_file(file: &Path) -> anyhow::Result<Option<Self>> { + pub fn try_load_from_file( + io: std::sync::Arc<std::sync::Mutex<Box<dyn IoInterface>>>, + file: &Path, + ) -> anyhow::Result<Option<Self>> { let project_dir = file .parent() .map(Path::to_path_buf) .unwrap_or_else(|| PathBuf::from(".")); - Self::try_load(project_dir) + Self::try_load(io, project_dir) } pub fn project_dir(&self) -> &Path { @@ -130,7 +143,7 @@ impl Composer { &self.installation_manager } - pub fn download_manager(&self) -> &DownloadManager { + pub fn download_manager(&self) -> &std::sync::Arc<tokio::sync::Mutex<DownloadManager>> { &self.download_manager } @@ -149,4 +162,8 @@ impl Composer { pub fn locker(&self) -> &Locker { &self.locker } + + pub fn archive_manager(&self) -> &std::sync::Arc<tokio::sync::Mutex<ArchiveManager>> { + &self.archive_manager + } } |
