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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
//! ref: composer/src/Composer/Script/Event.php
use crate::composer::ComposerWeakHandle;
use crate::event_dispatcher::Event as BaseEvent;
use crate::event_dispatcher::EventInterface;
use crate::io::IOInterface;
use indexmap::IndexMap;
use shirabe_php_shim::PhpMixed;
#[derive(Debug)]
pub struct Event {
inner: BaseEvent,
composer: ComposerWeakHandle,
io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>,
dev_mode: bool,
originating_event: Option<OriginatingEvent>,
}
#[derive(Debug)]
pub enum OriginatingEvent {
Base(BaseEvent),
Script(Box<Event>),
}
impl Event {
pub fn new(
name: String,
composer: ComposerWeakHandle,
io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>,
dev_mode: bool,
args: Vec<String>,
flags: IndexMap<String, PhpMixed>,
) -> Self {
Self {
inner: BaseEvent::new(name, args, flags),
composer,
io,
dev_mode,
originating_event: None,
}
}
pub fn get_composer(&self) -> &ComposerWeakHandle {
&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_originating_event(&self) -> Option<&OriginatingEvent> {
self.originating_event.as_ref()
}
pub fn set_originating_event(&mut self, event: OriginatingEvent) -> &mut Self {
self.originating_event = Some(Self::calculate_originating_event(event));
self
}
fn calculate_originating_event(event: OriginatingEvent) -> OriginatingEvent {
if let OriginatingEvent::Script(boxed) = event {
let mut inner_event = *boxed;
if let Some(originating) = inner_event.originating_event.take() {
return Self::calculate_originating_event(originating);
}
return OriginatingEvent::Script(Box::new(inner_event));
}
event
}
}
impl EventInterface for Event {
fn get_name(&self) -> &str {
self.inner.get_name()
}
fn get_arguments(&self) -> &Vec<String> {
self.inner.get_arguments()
}
fn get_flags(&self) -> &IndexMap<String, PhpMixed> {
self.inner.get_flags()
}
fn is_propagation_stopped(&self) -> bool {
self.inner.is_propagation_stopped()
}
fn stop_propagation(&mut self) {
self.inner.stop_propagation();
}
}
impl EventInterface for OriginatingEvent {
fn get_name(&self) -> &str {
match self {
OriginatingEvent::Base(e) => e.get_name(),
OriginatingEvent::Script(e) => e.get_name(),
}
}
fn get_arguments(&self) -> &Vec<String> {
match self {
OriginatingEvent::Base(e) => e.get_arguments(),
OriginatingEvent::Script(e) => e.get_arguments(),
}
}
fn get_flags(&self) -> &IndexMap<String, PhpMixed> {
match self {
OriginatingEvent::Base(e) => e.get_flags(),
OriginatingEvent::Script(e) => e.get_flags(),
}
}
fn is_propagation_stopped(&self) -> bool {
match self {
OriginatingEvent::Base(e) => e.is_propagation_stopped(),
OriginatingEvent::Script(e) => e.is_propagation_stopped(),
}
}
fn stop_propagation(&mut self) {
match self {
OriginatingEvent::Base(e) => e.stop_propagation(),
OriginatingEvent::Script(e) => e.stop_propagation(),
}
}
}
|