aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/plugin/plugin_manager.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-28 03:31:41 +0900
committernsfisis <nsfisis@gmail.com>2026-05-28 03:32:04 +0900
commitc7f53c5d7d581ebf76803650c63ec615b1558dc8 (patch)
treec6d83819e82a83cf93ca737b661094a8ea800cec /crates/shirabe/src/plugin/plugin_manager.rs
parentcc5d73c05a0abca2eebcc8a6afa0b1543ee49850 (diff)
downloadphp-shirabe-refactor/composer-handles.tar.gz
php-shirabe-refactor/composer-handles.tar.zst
php-shirabe-refactor/composer-handles.zip
refactor(composer): represent composer via trait-based handlesrefactor/composer-handles
Replace the PartialComposer/Composer structs and the single Rc<RefCell<PartialOrFullComposer>> enum with PartialComposer and Composer traits (Composer: PartialComposer), InnerPartialComposer / InnerFullComposer data structs, and the handle types FullComposerHandle (impl Composer) and AnyComposerHandle (polymorphic enum, impl PartialComposer), plus their weak variants. Factory builds the full and partial graphs via separate Rc::new_cyclic branches that share a build_composer_base helper. Call sites now use trait methods that encapsulate borrowing instead of borrow_partial() / composer_full*(). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/plugin/plugin_manager.rs')
-rw-r--r--crates/shirabe/src/plugin/plugin_manager.rs39
1 files changed, 12 insertions, 27 deletions
diff --git a/crates/shirabe/src/plugin/plugin_manager.rs b/crates/shirabe/src/plugin/plugin_manager.rs
index e2528ff..5f62047 100644
--- a/crates/shirabe/src/plugin/plugin_manager.rs
+++ b/crates/shirabe/src/plugin/plugin_manager.rs
@@ -16,8 +16,9 @@ use shirabe_php_shim::{
use shirabe_semver::constraint::AnyConstraint;
use shirabe_semver::constraint::SimpleConstraint;
-use crate::composer::PartialComposerHandle;
-use crate::composer::{ComposerHandle, ComposerWeakHandle};
+use crate::composer::{
+ AnyComposerHandle, Composer, FullComposerHandle, FullComposerWeakHandle, PartialComposer,
+};
use crate::event_dispatcher::EventSubscriberInterface;
use crate::factory::DisablePlugins;
use crate::installer::InstallerInterface;
@@ -42,9 +43,9 @@ use crate::util::PackageSorter;
#[derive(Debug)]
pub struct PluginManager {
- pub(crate) composer: ComposerWeakHandle,
+ pub(crate) composer: FullComposerWeakHandle,
pub(crate) io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>,
- pub(crate) global_composer: Option<PartialComposerHandle>,
+ pub(crate) global_composer: Option<AnyComposerHandle>,
pub(crate) version_parser: VersionParser,
pub(crate) disable_plugins: DisablePlugins,
pub(crate) plugins: Vec<Box<dyn PluginInterface>>,
@@ -65,20 +66,19 @@ static mut CLASS_COUNTER: i64 = 0;
impl PluginManager {
pub fn new(
io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>,
- composer: ComposerWeakHandle,
- global_composer: Option<PartialComposerHandle>,
+ composer: FullComposerWeakHandle,
+ global_composer: Option<AnyComposerHandle>,
disable_plugins: DisablePlugins,
) -> Self {
let composer_rc = composer
.upgrade()
.expect("PluginManager must not outlive Composer");
let allow_plugins_config = composer_rc
- .borrow()
.get_config()
.borrow()
.get("allow-plugins")
.clone();
- let locker = composer_rc.borrow().get_locker().clone();
+ let locker = composer_rc.get_locker().clone();
let mut locker = locker.borrow_mut();
let allow_plugin_rules =
Self::parse_allowed_plugins(allow_plugins_config, Some(&mut *locker));
@@ -86,13 +86,7 @@ impl PluginManager {
let allow_global_plugin_rules = Self::parse_allowed_plugins(
global_composer
.as_ref()
- .map(|gc| {
- gc.borrow_partial()
- .get_config()
- .borrow_mut()
- .get("allow-plugins")
- .clone()
- })
+ .map(|gc| gc.get_config().borrow_mut().get("allow-plugins").clone())
.unwrap_or(PhpMixed::Bool(false)),
None,
);
@@ -116,7 +110,7 @@ impl PluginManager {
/// Upgrades the weak Composer back-reference to a full handle. PHP holds a strong
/// `Composer`; the Rust port keeps it weak to break the Composer/PluginManager cycle.
- fn composer_full(&self) -> ComposerHandle {
+ fn composer_full(&self) -> FullComposerHandle {
self.composer
.upgrade()
.expect("PluginManager must not outlive Composer")
@@ -131,14 +125,13 @@ impl PluginManager {
// `&mut self`. The Rust port should eventually share via Rc<RefCell<_>>.
let repo: Box<dyn RepositoryInterface> = self
.composer_full()
- .borrow()
.get_repository_manager()
.borrow()
.get_local_repository()
.clone_box();
// The root package borrow is also tied to `self.composer`; clone the package handle
// (shared Rc) for the same reason as above.
- let root_package = self.composer_full().borrow().get_package().clone();
+ let root_package = self.composer_full().get_package().clone();
self.load_repository(&*repo, false, Some(root_package))?;
}
@@ -147,7 +140,6 @@ impl PluginManager {
.global_composer
.as_ref()
.unwrap()
- .borrow_partial()
.get_repository_manager()
.borrow()
.get_local_repository()
@@ -163,7 +155,6 @@ impl PluginManager {
if !self.are_plugins_disabled("local") {
let repo: Box<dyn RepositoryInterface> = self
.composer_full()
- .borrow()
.get_repository_manager()
.borrow()
.get_local_repository()
@@ -176,7 +167,6 @@ impl PluginManager {
.global_composer
.as_ref()
.unwrap()
- .borrow_partial()
.get_repository_manager()
.borrow()
.get_local_repository()
@@ -198,7 +188,7 @@ impl PluginManager {
}
/// Gets global composer or null when main composer is not fully loaded
- pub fn get_global_composer(&self) -> Option<&PartialComposerHandle> {
+ pub fn get_global_composer(&self) -> Option<&AnyComposerHandle> {
self.global_composer.as_ref()
}
@@ -357,7 +347,6 @@ impl PluginManager {
match plugin {
PluginOrInstaller::Installer(inst) => {
self.composer_full()
- .borrow()
.get_installation_manager()
.borrow_mut()
.remove_installer(&*inst);
@@ -384,7 +373,6 @@ impl PluginManager {
match plugin {
PluginOrInstaller::Installer(inst) => {
self.composer_full()
- .borrow()
.get_installation_manager()
.borrow_mut()
.remove_installer(&*inst);
@@ -635,7 +623,6 @@ impl PluginManager {
if !global {
return self
.composer_full()
- .borrow()
.get_installation_manager()
.borrow_mut()
.get_install_path(package);
@@ -645,7 +632,6 @@ impl PluginManager {
self.global_composer
.as_ref()
.unwrap()
- .borrow_partial()
.get_installation_manager()
.borrow_mut()
.get_install_path(package)
@@ -862,7 +848,6 @@ impl PluginManager {
.composer
.upgrade()
.expect("PluginManager must not outlive Composer")
- .borrow()
.get_config()
.clone();