aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/plugin/plugin_interface.rs
blob: 54fa6009de5d54fb0ea39716596dcb2ab39d5d46 (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
//! ref: composer/src/Composer/Plugin/PluginInterface.php

use crate::composer::ComposerHandle;
use crate::io::IOInterface;
use crate::plugin::Capable;

pub const PLUGIN_API_VERSION: &str = "2.9.0";

pub trait PluginInterface: std::fmt::Debug {
    // The PHP methods return void but may throw; the owned `ComposerHandle` follows the shared
    // handle policy — plugins typically store `$composer` beyond the call.
    fn activate(
        &mut self,
        composer: ComposerHandle,
        io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>,
    ) -> anyhow::Result<()>;

    fn deactivate(
        &mut self,
        composer: ComposerHandle,
        io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>,
    ) -> anyhow::Result<()>;

    fn uninstall(
        &mut self,
        composer: ComposerHandle,
        io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>,
    ) -> anyhow::Result<()>;

    /// PHP: `get_class($plugin)`. Rust has no runtime class name, so each implementor carries
    /// the name PHP would report.
    fn get_class_name(&self) -> String;

    // TODO(plugin): PHP-side `instanceof` checks for EventSubscriberInterface / Capable.
    // EventSubscriberInterface is not dyn-compatible (its only method is associated, not
    // a `&self` method), so we expose a boolean predicate instead.
    fn is_event_subscriber_interface(&self) -> bool {
        false
    }

    fn as_capable(&self) -> Option<&dyn Capable> {
        None
    }

    /// For testing only: recovers the PHP-backed proxy so tests can read plugin properties the
    /// way PHPUnit asserts `$plugins[0]->version`.
    fn as_php_plugin_proxy(&self) -> Option<&crate::plugin::PhpPluginProxy> {
        None
    }
}