aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/installer
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-27 08:44:57 +0900
committernsfisis <nsfisis@gmail.com>2026-06-27 08:44:57 +0900
commit901878ee3f2bee6605b02d321cc4c92bc32fd5b0 (patch)
tree83d8c8c9a24cb95c0656866d328b87c2d4c5127f /crates/shirabe/src/installer
parent5c2c72223cb6b4d77a332eeeeff7ee4e82e3f239 (diff)
downloadphp-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/installer')
-rw-r--r--crates/shirabe/src/installer/installation_manager.rs75
-rw-r--r--crates/shirabe/src/installer/library_installer.rs9
-rw-r--r--crates/shirabe/src/installer/project_installer.rs6
3 files changed, 84 insertions, 6 deletions
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<dyn InstallerInterface>);
+ 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<bool>;
+ fn ensure_binaries_presence(&mut self, package: PackageInterfaceHandle);
+ fn execute(
+ &mut self,
+ repo: &mut dyn InstalledRepositoryInterface,
+ operations: Vec<std::rc::Rc<dyn OperationInterface>>,
+ dev_mode: bool,
+ run_scripts: bool,
+ download_only: bool,
+ ) -> Result<()>;
+ fn get_install_path(&mut self, package: PackageInterfaceHandle) -> Option<String>;
+ fn set_output_progress(&mut self, output_progress: bool);
+ fn notify_installs(&mut self, io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>);
+}
+
+impl InstallationManagerInterface for InstallationManager {
+ fn add_installer(&mut self, installer: Box<dyn InstallerInterface>) {
+ 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<bool> {
+ 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<std::rc::Rc<dyn OperationInterface>>,
+ 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<String> {
+ 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<std::cell::RefCell<dyn IOInterface>>) {
+ self.notify_installs(io);
+ }
+}
diff --git a/crates/shirabe/src/installer/library_installer.rs b/crates/shirabe/src/installer/library_installer.rs
index e2c6c0c..e1c3aec 100644
--- a/crates/shirabe/src/installer/library_installer.rs
+++ b/crates/shirabe/src/installer/library_installer.rs
@@ -8,7 +8,7 @@ use shirabe_php_shim::{
};
use crate::composer::PartialComposerWeakHandle;
-use crate::downloader::DownloadManager;
+use crate::downloader::DownloadManagerInterface;
use crate::installer::BinaryInstaller;
use crate::installer::BinaryPresenceInterface;
use crate::installer::InstallerInterface;
@@ -24,7 +24,8 @@ use crate::util::Silencer;
pub struct LibraryInstaller {
pub(crate) composer: PartialComposerWeakHandle,
pub(crate) vendor_dir: String,
- pub(crate) download_manager: Option<std::rc::Rc<std::cell::RefCell<DownloadManager>>>,
+ pub(crate) download_manager:
+ Option<std::rc::Rc<std::cell::RefCell<dyn DownloadManagerInterface>>>,
pub(crate) io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>,
pub(crate) r#type: Option<String>,
pub(crate) filesystem: std::rc::Rc<std::cell::RefCell<Filesystem>>,
@@ -192,7 +193,9 @@ impl LibraryInstaller {
self.vendor_dir = realpath(&self.vendor_dir).unwrap_or_default();
}
- pub(crate) fn get_download_manager(&self) -> &std::rc::Rc<std::cell::RefCell<DownloadManager>> {
+ pub(crate) fn get_download_manager(
+ &self,
+ ) -> &std::rc::Rc<std::cell::RefCell<dyn DownloadManagerInterface>> {
// PHP: assert($this->downloadManager instanceof DownloadManager, new \LogicException(...))
assert!(
self.download_manager.is_some(),
diff --git a/crates/shirabe/src/installer/project_installer.rs b/crates/shirabe/src/installer/project_installer.rs
index 351fd35..83ffbb2 100644
--- a/crates/shirabe/src/installer/project_installer.rs
+++ b/crates/shirabe/src/installer/project_installer.rs
@@ -1,6 +1,6 @@
//! ref: composer/src/Composer/Installer/ProjectInstaller.php
-use crate::downloader::DownloadManager;
+use crate::downloader::DownloadManagerInterface;
use crate::installer::InstallerInterface;
use crate::package::PackageInterfaceHandle;
use crate::repository::InstalledRepositoryInterface;
@@ -10,14 +10,14 @@ use shirabe_php_shim::{InvalidArgumentException, PhpMixed};
#[derive(Debug)]
pub struct ProjectInstaller {
install_path: String,
- download_manager: std::rc::Rc<std::cell::RefCell<DownloadManager>>,
+ download_manager: std::rc::Rc<std::cell::RefCell<dyn DownloadManagerInterface>>,
filesystem: std::rc::Rc<std::cell::RefCell<Filesystem>>,
}
impl ProjectInstaller {
pub fn new(
install_path: &str,
- dm: std::rc::Rc<std::cell::RefCell<DownloadManager>>,
+ dm: std::rc::Rc<std::cell::RefCell<dyn DownloadManagerInterface>>,
fs: std::rc::Rc<std::cell::RefCell<Filesystem>>,
) -> Self {
let install_path = format!("{}/", install_path.replace('\\', "/").trim_end_matches('/'));