From 901878ee3f2bee6605b02d321cc4c92bc32fd5b0 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 27 Jun 2026 08:44:57 +0900 Subject: 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> 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) --- .../shirabe/src/installer/installation_manager.rs | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) (limited to 'crates/shirabe/src/installer/installation_manager.rs') diff --git a/crates/shirabe/src/installer/installation_manager.rs b/crates/shirabe/src/installer/installation_manager.rs index ac5f8e4..bee14cc 100644 --- a/crates/shirabe/src/installer/installation_manager.rs +++ b/crates/shirabe/src/installer/installation_manager.rs @@ -791,3 +791,78 @@ impl InstallationManager { } } } + +// Composer's PartialComposer::setInstallationManager() accepts any InstallationManager subclass, so +// plugins may swap in a replacement. The interface captures the methods reached through Composer's +// accessor and through the `&mut dyn InstallationManagerInterface` references fed from it. +pub trait InstallationManagerInterface: std::fmt::Debug { + fn add_installer(&mut self, installer: Box); + fn remove_installer(&mut self, installer: &dyn InstallerInterface); + fn disable_plugins(&mut self); + fn is_package_installed( + &mut self, + repo: &dyn InstalledRepositoryInterface, + package: PackageInterfaceHandle, + ) -> Result; + fn ensure_binaries_presence(&mut self, package: PackageInterfaceHandle); + fn execute( + &mut self, + repo: &mut dyn InstalledRepositoryInterface, + operations: Vec>, + dev_mode: bool, + run_scripts: bool, + download_only: bool, + ) -> Result<()>; + fn get_install_path(&mut self, package: PackageInterfaceHandle) -> Option; + fn set_output_progress(&mut self, output_progress: bool); + fn notify_installs(&mut self, io: std::rc::Rc>); +} + +impl InstallationManagerInterface for InstallationManager { + fn add_installer(&mut self, installer: Box) { + self.add_installer(installer); + } + + fn remove_installer(&mut self, installer: &dyn InstallerInterface) { + self.remove_installer(installer); + } + + fn disable_plugins(&mut self) { + self.disable_plugins(); + } + + fn is_package_installed( + &mut self, + repo: &dyn InstalledRepositoryInterface, + package: PackageInterfaceHandle, + ) -> Result { + self.is_package_installed(repo, package) + } + + fn ensure_binaries_presence(&mut self, package: PackageInterfaceHandle) { + self.ensure_binaries_presence(package); + } + + fn execute( + &mut self, + repo: &mut dyn InstalledRepositoryInterface, + operations: Vec>, + dev_mode: bool, + run_scripts: bool, + download_only: bool, + ) -> Result<()> { + self.execute(repo, operations, dev_mode, run_scripts, download_only) + } + + fn get_install_path(&mut self, package: PackageInterfaceHandle) -> Option { + self.get_install_path(package) + } + + fn set_output_progress(&mut self, output_progress: bool) { + self.set_output_progress(output_progress); + } + + fn notify_installs(&mut self, io: std::rc::Rc>) { + self.notify_installs(io); + } +} -- cgit v1.3.1