aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/event_dispatcher/event_dispatcher.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/event_dispatcher/event_dispatcher.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/event_dispatcher/event_dispatcher.rs')
-rw-r--r--crates/shirabe/src/event_dispatcher/event_dispatcher.rs14
1 files changed, 4 insertions, 10 deletions
diff --git a/crates/shirabe/src/event_dispatcher/event_dispatcher.rs b/crates/shirabe/src/event_dispatcher/event_dispatcher.rs
index ef02660..49775d1 100644
--- a/crates/shirabe/src/event_dispatcher/event_dispatcher.rs
+++ b/crates/shirabe/src/event_dispatcher/event_dispatcher.rs
@@ -19,8 +19,7 @@ use shirabe_php_shim::{
};
use crate::autoload::ClassLoader;
-use crate::composer::PartialComposerHandle;
-use crate::composer::PartialComposerWeakHandle;
+use crate::composer::{AnyComposerHandle, AnyComposerWeakHandle, Composer, PartialComposer};
use crate::dependency_resolver::Transaction;
use crate::dependency_resolver::operation::OperationInterface;
use crate::event_dispatcher::Event;
@@ -62,7 +61,7 @@ pub enum Callable {
/// `$dispatcher->dispatch(ScriptEvents::POST_INSTALL_CMD);`
#[derive(Debug)]
pub struct EventDispatcher {
- pub(crate) composer: PartialComposerWeakHandle,
+ pub(crate) composer: AnyComposerWeakHandle,
pub(crate) io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>,
pub(crate) loader: Option<ClassLoader>,
pub(crate) process: std::rc::Rc<std::cell::RefCell<ProcessExecutor>>,
@@ -76,7 +75,7 @@ pub struct EventDispatcher {
impl EventDispatcher {
pub fn new(
- composer: PartialComposerWeakHandle,
+ composer: AnyComposerWeakHandle,
io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>,
process: Option<std::rc::Rc<std::cell::RefCell<ProcessExecutor>>>,
) -> Self {
@@ -704,7 +703,6 @@ impl EventDispatcher {
.composer
.upgrade()
.expect("Composer was dropped before EventDispatcher use")
- .borrow_partial()
.get_package()
.get_binaries();
if !possible_local_binaries.is_empty() {
@@ -1081,7 +1079,6 @@ impl EventDispatcher {
/// Finds all listeners defined as scripts in the package
fn get_script_listeners(&self, event: &Event) -> Vec<Callable> {
let composer = self.composer();
- let composer = composer.borrow_partial();
let package = composer.get_package();
let scripts = package.get_scripts();
@@ -1163,7 +1160,6 @@ impl EventDispatcher {
// add the bin dir to the PATH to make local binaries of deps usable in scripts
let bin_dir = self
.composer()
- .borrow_partial()
.get_config()
.borrow_mut()
.get("bin-dir")
@@ -1234,8 +1230,6 @@ impl EventDispatcher {
let Some(composer) = composer.as_full() else {
return;
};
- let composer = composer.borrow_mut();
-
let callable_key = match callable {
Callable::ArrayCallable(first, method) => {
let prefix = if let PhpMixed::String(s) = first.as_ref() {
@@ -1316,7 +1310,7 @@ impl EventDispatcher {
todo!("clone std::rc::Rc<std::cell::RefCell<dyn IOInterface>>")
}
- fn composer(&self) -> PartialComposerHandle {
+ fn composer(&self) -> AnyComposerHandle {
self.composer
.upgrade()
.expect("EventDispatcher must lives longer than Composer")