aboutsummaryrefslogtreecommitdiff
path: root/src/phorkie/Notificator.php
blob: dc6a6af05febddfb6c2c7598b1889d05030a0906 (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
<?php
namespace phorkie;

/**
 * Send out webhook callbacks when something happens
 */
class Notificator
{
    protected $notificators = array();

    public function __construct()
    {
        $this->loadNotificators();
    }

    protected function loadNotificators()
    {
        foreach ($GLOBALS['phorkie']['cfg']['notificator'] as $type => $config) {
            $class = '\\phorkie\\Notificator_' . ucfirst($type);
            $this->notificators[] = new $class($config);
        }
    }

    /**
     * A repository has been created
     */
    public function create(Repository $repo)
    {
        $this->send('create', $repo);
    }

    /**
     * A repository has been modified
     */
    public function edit(Repository $repo)
    {
        $this->send('edit', $repo);
    }

    /**
     * A repository has been deleted
     */
    public function delete(Repository $repo)
    {
        $this->send('delete', $repo);
    }

    /**
     * Call all notificator plugins
     */
    protected function send($event, Repository $repo)
    {
        foreach ($this->notificators as $notificator) {
            $notificator->send($event, $repo);
        }
    }
}
?>