summaryrefslogtreecommitdiff
path: root/app/Subscriber/WebhookSubscriber.php
blob: e28675bd11e1fc20a93b1951ce300c1ef822fa84 (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
<?php

namespace Subscriber;

use Event\CommentEvent;
use Event\GenericEvent;
use Event\TaskEvent;
use Model\Comment;
use Model\Task;
use Model\File;
use Model\Subtask;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class WebhookSubscriber extends Base implements EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        return array(
            Task::EVENT_CREATE => array('execute', 0),
            Task::EVENT_UPDATE => array('execute', 0),
            Task::EVENT_CLOSE => array('execute', 0),
            Task::EVENT_OPEN => array('execute', 0),
            Task::EVENT_MOVE_COLUMN => array('execute', 0),
            Task::EVENT_MOVE_POSITION => array('execute', 0),
            Task::EVENT_ASSIGNEE_CHANGE => array('execute', 0),
            Task::EVENT_MOVE_PROJECT => array('execute', 0),
            Task::EVENT_MOVE_SWIMLANE => array('execute', 0),
            Comment::EVENT_CREATE => array('execute', 0),
            Comment::EVENT_UPDATE => array('execute', 0),
            File::EVENT_CREATE => array('execute', 0),
            Subtask::EVENT_CREATE => array('execute', 0),
            Subtask::EVENT_UPDATE => array('execute', 0),
        );
    }

    public function execute(GenericEvent $event, $event_name)
    {
        $payload = array(
            'event_name' => $event_name,
            'event_data' => $event->getAll(),
        );

        $this->webhook->notify($payload);
    }
}