diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-27 08:44:57 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-27 08:44:57 +0900 |
| commit | 901878ee3f2bee6605b02d321cc4c92bc32fd5b0 (patch) | |
| tree | 83d8c8c9a24cb95c0656866d328b87c2d4c5127f /crates/shirabe/src/repository | |
| parent | 5c2c72223cb6b4d77a332eeeeff7ee4e82e3f239 (diff) | |
| download | php-shirabe-901878ee3f2bee6605b02d321cc4c92bc32fd5b0.tar.gz php-shirabe-901878ee3f2bee6605b02d321cc4c92bc32fd5b0.tar.zst php-shirabe-901878ee3f2bee6605b02d321cc4c92bc32fd5b0.zip | |
refactor(composer): hold managers behind *Interface traits
Composer/PartialComposer exposed its RepositoryManager, InstallationManager,
EventDispatcher, Locker, DownloadManager, AutoloadGenerator and ArchiveManager
as concrete types, but Composer's public setters (setDownloadManager() etc.)
let plugins swap in subclasses. Introduce a *Interface trait per manager and
store each as Rc<RefCell<dyn ...Interface>> so a replacement is honored.
Only Composer's slots and the sinks fed from its accessors become trait
objects; managers injected concretely at construction keep their concrete
references, matching PHP semantics. Fluent setters on the affected classes now
return () and Locker::update_hash is de-generified to a boxed FnOnce so the
traits stay object-safe.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/repository')
| -rw-r--r-- | crates/shirabe/src/repository/repository_factory.rs | 9 | ||||
| -rw-r--r-- | crates/shirabe/src/repository/repository_manager.rs | 43 | ||||
| -rw-r--r-- | crates/shirabe/src/repository/repository_set.rs | 4 |
3 files changed, 50 insertions, 6 deletions
diff --git a/crates/shirabe/src/repository/repository_factory.rs b/crates/shirabe/src/repository/repository_factory.rs index db8185e..bc08589 100644 --- a/crates/shirabe/src/repository/repository_factory.rs +++ b/crates/shirabe/src/repository/repository_factory.rs @@ -15,6 +15,7 @@ use crate::json::JsonFile; use crate::repository::FilesystemRepository; use crate::repository::RepositoryInterfaceHandle; use crate::repository::RepositoryManager; +use crate::repository::RepositoryManagerInterface; use crate::util::HttpDownloader; use crate::util::ProcessExecutor; @@ -98,7 +99,7 @@ impl RepositoryFactory { config: &std::rc::Rc<std::cell::RefCell<Config>>, repository: &str, allow_filesystem: bool, - rm: Option<&mut RepositoryManager>, + rm: Option<&mut dyn RepositoryManagerInterface>, ) -> anyhow::Result<RepositoryInterfaceHandle> { let repo_config = Self::config_from_string(io.clone(), config, repository, allow_filesystem)?; @@ -109,7 +110,7 @@ impl RepositoryFactory { io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, config: &std::rc::Rc<std::cell::RefCell<Config>>, repo_config: IndexMap<String, PhpMixed>, - rm: Option<&mut RepositoryManager>, + rm: Option<&mut dyn RepositoryManagerInterface>, ) -> anyhow::Result<RepositoryInterfaceHandle> { let mut owned_rm; let rm = if let Some(rm) = rm { @@ -134,7 +135,7 @@ impl RepositoryFactory { pub fn default_repos( io: Option<std::rc::Rc<std::cell::RefCell<dyn IOInterface>>>, config: Option<std::rc::Rc<std::cell::RefCell<Config>>>, - rm: Option<&mut RepositoryManager>, + rm: Option<&mut dyn RepositoryManagerInterface>, ) -> anyhow::Result<IndexMap<String, RepositoryInterfaceHandle>> { let config = match config { Some(c) => c, @@ -235,7 +236,7 @@ impl RepositoryFactory { } fn create_repos( - rm: &mut RepositoryManager, + rm: &mut dyn RepositoryManagerInterface, repo_configs: Vec<PhpMixed>, ) -> anyhow::Result<IndexMap<String, RepositoryInterfaceHandle>> { let mut repo_map: IndexMap<String, RepositoryInterfaceHandle> = IndexMap::new(); diff --git a/crates/shirabe/src/repository/repository_manager.rs b/crates/shirabe/src/repository/repository_manager.rs index 247236c..41f4e7d 100644 --- a/crates/shirabe/src/repository/repository_manager.rs +++ b/crates/shirabe/src/repository/repository_manager.rs @@ -196,3 +196,46 @@ impl RepositoryManager { self.local_repository.clone().unwrap() } } + +// Composer's PartialComposer::setRepositoryManager() accepts any RepositoryManager subclass, so +// plugins may swap in a replacement. The interface captures the methods reached through Composer's +// accessor and through the `&mut RepositoryManager` parameters fed from it. +pub trait RepositoryManagerInterface: std::fmt::Debug { + fn get_local_repository(&self) -> RepositoryInterfaceHandle; + fn get_repositories(&self) -> &Vec<RepositoryInterfaceHandle>; + fn create_repository( + &self, + r#type: &str, + config: IndexMap<String, PhpMixed>, + name: Option<&str>, + ) -> anyhow::Result<RepositoryInterfaceHandle>; + fn add_repository(&mut self, repository: RepositoryInterfaceHandle); + fn set_local_repository(&mut self, repository: RepositoryInterfaceHandle); +} + +impl RepositoryManagerInterface for RepositoryManager { + fn get_local_repository(&self) -> RepositoryInterfaceHandle { + self.get_local_repository() + } + + fn get_repositories(&self) -> &Vec<RepositoryInterfaceHandle> { + self.get_repositories() + } + + fn create_repository( + &self, + r#type: &str, + config: IndexMap<String, PhpMixed>, + name: Option<&str>, + ) -> anyhow::Result<RepositoryInterfaceHandle> { + self.create_repository(r#type, config, name) + } + + fn add_repository(&mut self, repository: RepositoryInterfaceHandle) { + self.add_repository(repository); + } + + fn set_local_repository(&mut self, repository: RepositoryInterfaceHandle) { + self.set_local_repository(repository); + } +} diff --git a/crates/shirabe/src/repository/repository_set.rs b/crates/shirabe/src/repository/repository_set.rs index ba6373a..393639f 100644 --- a/crates/shirabe/src/repository/repository_set.rs +++ b/crates/shirabe/src/repository/repository_set.rs @@ -15,7 +15,7 @@ use crate::dependency_resolver::PoolOptimizer; use crate::dependency_resolver::Request; use crate::dependency_resolver::SecurityAdvisoryPoolFilter; use crate::downloader::TransportException; -use crate::event_dispatcher::EventDispatcher; +use crate::event_dispatcher::EventDispatcherInterface; use crate::io::IOInterface; use crate::io::NullIO; use crate::package::AliasPackageHandle; @@ -451,7 +451,7 @@ impl RepositorySet { &mut self, request: &mut Request, io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, - event_dispatcher: Option<std::rc::Rc<std::cell::RefCell<EventDispatcher>>>, + event_dispatcher: Option<std::rc::Rc<std::cell::RefCell<dyn EventDispatcherInterface>>>, pool_optimizer: Option<PoolOptimizer>, ignored_types: Vec<String>, allowed_types: Option<Vec<String>>, |
