aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/installer/package_event.rs
blob: 62bc395cf28ef700bfa4b43120a47a2f49790ead (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//! ref: composer/src/Composer/Installer/PackageEvent.php

use crate::composer::FullComposerWeakHandle;
use crate::dependency_resolver::operation::OperationInterface;
use crate::event_dispatcher::Event;
use crate::io::IOInterface;
use crate::repository::RepositoryInterface;
use indexmap::IndexMap;

#[derive(Debug)]
pub struct PackageEvent {
    inner: Event,
    composer: FullComposerWeakHandle,
    io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>,
    dev_mode: bool,
    local_repo: Box<dyn RepositoryInterface>,
    operations: Vec<Box<dyn OperationInterface>>,
    operation: Box<dyn OperationInterface>,
}

impl PackageEvent {
    pub fn new(
        event_name: String,
        composer: FullComposerWeakHandle,
        io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>,
        dev_mode: bool,
        local_repo: Box<dyn RepositoryInterface>,
        operations: Vec<Box<dyn OperationInterface>>,
        operation: Box<dyn OperationInterface>,
    ) -> Self {
        Self {
            inner: Event::new(event_name, vec![], IndexMap::new()),
            composer,
            io,
            dev_mode,
            local_repo,
            operations,
            operation,
        }
    }

    pub fn get_name(&self) -> &str {
        self.inner.get_name()
    }

    pub fn get_composer(&self) -> &FullComposerWeakHandle {
        &self.composer
    }

    pub fn get_io(&self) -> std::rc::Rc<std::cell::RefCell<dyn IOInterface>> {
        self.io.clone()
    }

    pub fn is_dev_mode(&self) -> bool {
        self.dev_mode
    }

    pub fn get_local_repo(&self) -> &dyn RepositoryInterface {
        self.local_repo.as_ref()
    }

    pub fn get_operations(&self) -> &Vec<Box<dyn OperationInterface>> {
        &self.operations
    }

    pub fn get_operation(&self) -> &dyn OperationInterface {
        self.operation.as_ref()
    }
}