From 0b06f54103490e3ce5658e82bbc0119633e26cd8 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Fri, 22 May 2026 01:29:48 +0900 Subject: 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) --- crates/shirabe/src/partial_composer.rs | 102 --------------------------------- 1 file changed, 102 deletions(-) delete mode 100644 crates/shirabe/src/partial_composer.rs (limited to 'crates/shirabe/src/partial_composer.rs') diff --git a/crates/shirabe/src/partial_composer.rs b/crates/shirabe/src/partial_composer.rs deleted file mode 100644 index ec51b81..0000000 --- a/crates/shirabe/src/partial_composer.rs +++ /dev/null @@ -1,102 +0,0 @@ -//! ref: composer/src/Composer/PartialComposer.php - -use crate::config::Config; -use crate::event_dispatcher::EventDispatcher; -use crate::installer::InstallationManager; -use crate::package::RootPackageInterface; -use crate::repository::RepositoryManager; -use crate::util::r#loop::Loop; - -#[derive(Debug, Default)] -pub struct PartialComposer { - global: bool, - package: Option>, - r#loop: Option>>, - repository_manager: Option, - installation_manager: Option, - config: Option>>, - event_dispatcher: Option>>, -} - -impl PartialComposer { - pub fn set_package(&mut self, package: Box) { - self.package = Some(package); - } - - pub fn get_package(&self) -> &dyn RootPackageInterface { - self.package.as_deref().unwrap() - } - - pub fn set_config(&mut self, config: std::rc::Rc>) { - self.config = Some(config); - } - - pub fn get_config(&self) -> &std::rc::Rc> { - self.config.as_ref().unwrap() - } - - pub fn get_config_mut(&mut self) -> &mut std::rc::Rc> { - self.config.as_mut().unwrap() - } - - pub fn set_loop(&mut self, r#loop: std::rc::Rc>) { - self.r#loop = Some(r#loop); - } - - pub fn get_loop(&self) -> &std::rc::Rc> { - self.r#loop.as_ref().unwrap() - } - - pub fn set_repository_manager(&mut self, manager: RepositoryManager) { - self.repository_manager = Some(manager); - } - - pub fn get_repository_manager(&self) -> &RepositoryManager { - self.repository_manager.as_ref().unwrap() - } - - pub fn set_installation_manager(&mut self, manager: InstallationManager) { - self.installation_manager = Some(manager); - } - - pub fn get_installation_manager(&self) -> &InstallationManager { - self.installation_manager.as_ref().unwrap() - } - - pub fn get_installation_manager_mut(&mut self) -> &mut InstallationManager { - self.installation_manager.as_mut().unwrap() - } - - pub fn set_event_dispatcher( - &mut self, - event_dispatcher: std::rc::Rc>, - ) { - self.event_dispatcher = Some(event_dispatcher); - } - - pub fn get_event_dispatcher(&self) -> &std::rc::Rc> { - self.event_dispatcher.as_ref().unwrap() - } - - pub fn is_global(&self) -> bool { - self.global - } - - pub fn set_global(&mut self) { - self.global = true; - } - - /// TODO(phase-b): Emulates PHP `$composer instanceof Composer` check. - /// PartialComposer cannot be a Composer here (Composer is a separate struct - /// that wraps PartialComposer via composition), so this always returns false. - pub fn is_full_composer(&self) -> bool { - false - } - - /// TODO(phase-b): Emulates PHP downcast to `Composer`. - /// Returns self as `&dyn Any`; downcasting to Composer will always fail because - /// PartialComposer is not a Composer in this Rust port. - pub fn as_any(&self) -> &dyn std::any::Any { - self - } -} -- cgit v1.3.1