diff options
Diffstat (limited to 'app/Subscriber/WebhookSubscriber.php')
-rw-r--r-- | app/Subscriber/WebhookSubscriber.php | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/app/Subscriber/WebhookSubscriber.php b/app/Subscriber/WebhookSubscriber.php new file mode 100644 index 00000000..20d765e2 --- /dev/null +++ b/app/Subscriber/WebhookSubscriber.php @@ -0,0 +1,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'); + } + + public function onTaskModification(TaskEvent $event) + { + $this->executeRequest('webhook_url_task_modification'); + } + + public function executeRequest($parameter) + { + $url = $this->config->get($parameter); + + if (! empty($url)) { + $this->webhook->notify($url, $event->getAll()); + } + } +} |