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

namespace Subscriber;

use Event\TaskEvent;
use Model\Task;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class WebhookSubscriber extends Base implements EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        return array(
            Task::EVENT_CREATE => array('onTaskCreation', 0),
            Task::EVENT_UPDATE => array('onTaskModification', 0),
            Task::EVENT_CLOSE => array('onTaskModification', 0),
            Task::EVENT_OPEN => array('onTaskModification', 0),
            Task::EVENT_MOVE_COLUMN => array('onTaskModification', 0),
            Task::EVENT_MOVE_POSITION => array('onTaskModification', 0),
            Task::EVENT_ASSIGNEE_CHANGE => array('onTaskModification', 0),
        );
    }

    public function onTaskCreation(TaskEvent $event)
    {
        $this->executeRequest('webhook_url_task_creation', $event);
    }

    public function onTaskModification(TaskEvent $event)
    {
        $this->executeRequest('webhook_url_task_modification', $event);
    }

    public function executeRequest($parameter, TaskEvent $event)
    {
        $url = $this->config->get($parameter);

        if (! empty($url)) {
            $this->webhook->notify($url, $event->getAll());
        }
    }
}