diff options
author | Frédéric Guillot <fred@kanboard.net> | 2014-12-27 19:10:38 -0500 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2014-12-27 19:10:38 -0500 |
commit | 17dc5bdc9ede52ad618bbf326e67e3b6988170f7 (patch) | |
tree | 9cf4d325667f11fa735bca84042fb385e3273329 /app/Subscriber/WebhookSubscriber.php | |
parent | cf821e117ce8b937cff7f386a107aaa81ba6bf9b (diff) |
Move events handling to Symfony\EventDispatcher
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()); + } + } +} |