aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/plugin/pre_file_download_event.rs
blob: 0cd14d7ee6361b378cf357154cfd9cd9637b6aff (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
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
//! ref: composer/src/Composer/Plugin/PreFileDownloadEvent.php

use indexmap::IndexMap;
use shirabe_php_shim::PhpMixed;

use crate::event_dispatcher::Event;
use crate::event_dispatcher::EventInterface;
use crate::util::HttpDownloader;

#[derive(Debug)]
pub struct PreFileDownloadEvent {
    inner: Event,
    http_downloader: std::rc::Rc<std::cell::RefCell<HttpDownloader>>,
    processed_url: String,
    custom_cache_key: Option<String>,
    r#type: String,
    context: PhpMixed,
    transport_options: IndexMap<String, PhpMixed>,
}

impl PreFileDownloadEvent {
    pub fn new(
        name: String,
        http_downloader: std::rc::Rc<std::cell::RefCell<HttpDownloader>>,
        processed_url: String,
        r#type: String,
        context: PhpMixed,
    ) -> Self {
        Self {
            inner: Event::new(name, vec![], IndexMap::new()),
            http_downloader,
            processed_url,
            custom_cache_key: None,
            r#type,
            context,
            transport_options: IndexMap::new(),
        }
    }

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

    pub fn get_http_downloader(&self) -> &std::rc::Rc<std::cell::RefCell<HttpDownloader>> {
        &self.http_downloader
    }

    pub fn get_processed_url(&self) -> &str {
        &self.processed_url
    }

    pub fn set_processed_url(&mut self, processed_url: String) {
        self.processed_url = processed_url;
    }

    pub fn get_custom_cache_key(&self) -> Option<&str> {
        self.custom_cache_key.as_deref()
    }

    pub fn set_custom_cache_key(&mut self, custom_cache_key: Option<String>) {
        self.custom_cache_key = custom_cache_key;
    }

    pub fn get_type(&self) -> &str {
        &self.r#type
    }

    pub fn get_context(&self) -> &PhpMixed {
        &self.context
    }

    pub fn get_transport_options(&self) -> &IndexMap<String, PhpMixed> {
        &self.transport_options
    }

    pub fn set_transport_options(&mut self, options: IndexMap<String, PhpMixed>) {
        self.transport_options = options;
    }
}

impl EventInterface for PreFileDownloadEvent {
    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();
    }
}