aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/tests/plugin/fixtures/subscriber-v1/Subscriber/Plugin.php
blob: f75763ba0caa6ea4bb44717c079e11feaa8abac0 (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
<?php

namespace Subscriber;

use Composer\Composer;
use Composer\EventDispatcher\EventSubscriberInterface;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;

class Plugin implements PluginInterface, EventSubscriberInterface
{
    public $version = 'subscriber-v1';

    /** @var IOInterface */
    private $io;

    public function activate(Composer $composer, IOInterface $io)
    {
        $this->io = $io;
        $io->write('activate subscriber-v1');
    }

    public function deactivate(Composer $composer, IOInterface $io)
    {
    }

    public function uninstall(Composer $composer, IOInterface $io)
    {
    }

    public static function getSubscribedEvents()
    {
        return [
            'post-install-cmd' => 'onPostInstall',
            'shirabe-priority-event' => [['early', 10], ['late', -10]],
            'shirabe-false-event' => ['returnsFalse', 0],
        ];
    }

    public function onPostInstall($event)
    {
        $this->io->write('subscriber saw ' . $event->getName());
    }

    public function early($event)
    {
        $this->io->write('early listener');
    }

    public function late($event)
    {
        $this->io->write('late listener');
    }

    public function returnsFalse($event)
    {
        $this->io->write('failing listener');

        return false;
    }
}