diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-05-22 01:29:48 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-05-22 01:43:48 +0900 |
| commit | 0b06f54103490e3ce5658e82bbc0119633e26cd8 (patch) | |
| tree | 687b075131d3679725e77e0931ff7c503a6c3034 /crates/shirabe/src/installer/library_installer.rs | |
| parent | 2914770fba6b3cc03a68fae493f60470a41962ec (diff) | |
| download | php-shirabe-0b06f54103490e3ce5658e82bbc0119633e26cd8.tar.gz php-shirabe-0b06f54103490e3ce5658e82bbc0119633e26cd8.tar.zst php-shirabe-0b06f54103490e3ce5658e82bbc0119633e26cd8.zip | |
refactor(composer): unify Composer/PartialComposer via Rc handles
Model PHP's `Composer extends PartialComposer` as a PartialOrFullComposer
enum and merge partial_composer.rs into composer.rs. Introduce
ComposerHandle / PartialComposerHandle (plus their Weak variants) so the
graph can be shared, and build it at once with Rc::new_cyclic in the
factory to resolve the back-reference cycles.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/installer/library_installer.rs')
| -rw-r--r-- | crates/shirabe/src/installer/library_installer.rs | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/crates/shirabe/src/installer/library_installer.rs b/crates/shirabe/src/installer/library_installer.rs index 0b4ba78..4c3f201 100644 --- a/crates/shirabe/src/installer/library_installer.rs +++ b/crates/shirabe/src/installer/library_installer.rs @@ -9,14 +9,13 @@ use shirabe_php_shim::{ InvalidArgumentException, LogicException, is_link, preg_quote, realpath, rmdir, rtrim, strpos, }; -use crate::composer::Composer; +use crate::composer::PartialComposerWeakHandle; use crate::downloader::DownloadManager; use crate::installer::BinaryInstaller; use crate::installer::BinaryPresenceInterface; use crate::installer::InstallerInterface; use crate::io::IOInterface; use crate::package::PackageInterface; -use crate::partial_composer::PartialComposer; use crate::repository::InstalledRepositoryInterface; use crate::util::Filesystem; use crate::util::Platform; @@ -25,7 +24,7 @@ use crate::util::Silencer; /// Package installation manager. #[derive(Debug)] pub struct LibraryInstaller { - pub(crate) composer: PartialComposer, + pub(crate) composer: PartialComposerWeakHandle, pub(crate) vendor_dir: String, pub(crate) download_manager: Option<std::rc::Rc<std::cell::RefCell<DownloadManager>>>, pub(crate) io: Box<dyn IOInterface>, @@ -38,26 +37,26 @@ impl LibraryInstaller { /// Initializes library installer. pub fn new( io: Box<dyn IOInterface>, - composer: PartialComposer, + composer: PartialComposerWeakHandle, r#type: Option<String>, filesystem: Option<std::rc::Rc<std::cell::RefCell<Filesystem>>>, binary_installer: Option<BinaryInstaller>, ) -> Self { - // PHP: $this->downloadManager = $composer instanceof Composer ? $composer->getDownloadManager() : null; - // TODO(phase-b): PartialComposer cannot downcast to Composer in this Rust port. - let download_manager: Option<std::rc::Rc<std::cell::RefCell<DownloadManager>>> = - if let Some(_full_composer) = composer.as_any().downcast_ref::<Composer>() { - // TODO(phase-b): clone or borrow the DownloadManager from the full Composer - Some(todo!("composer.get_download_manager() as DownloadManager")) - } else { - None - }; + let composer_rc = composer + .upgrade() + .expect("LibraryInstaller must lives longer than Composer"); + + let download_manager = composer_rc + .as_full() + .map(|full| full.borrow().get_download_manager()); + + let composer_ref = composer_rc.borrow_partial(); let filesystem = filesystem .unwrap_or_else(|| std::rc::Rc::new(std::cell::RefCell::new(Filesystem::new(None)))); let vendor_dir = rtrim( // TODO(phase-b): Config::get returns PhpMixed; coerce to String via get_str. - &composer + &composer_ref .get_config() .borrow_mut() .get_str("vendor-dir") @@ -69,7 +68,7 @@ impl LibraryInstaller { // TODO(phase-b): pass io by reference/clone todo!("io reference"), rtrim( - &composer + &composer_ref .get_config() .borrow_mut() .get_str("bin-dir") @@ -77,7 +76,7 @@ impl LibraryInstaller { Some("/"), ), // TODO(phase-b): Config::get returns PhpMixed; coerce to String via get_str. - composer + composer_ref .get_config() .borrow_mut() .get_str("bin-compat") |
