summaryrefslogtreecommitdiff
path: root/app/Event/WebhookListener.php
blob: 4668b66ec69a104b2a66aff933d8ccb22f40f1d9 (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
<?php

namespace Event;

use Core\Listener;
use Model\Webhook;

/**
 * Webhook task events
 *
 * @package event
 * @author  Frederic Guillot
 */
class WebhookListener implements Listener
{
    /**
     * Webhook model
     *
     * @accesss private
     * @var \Model\Webhook
     */
    private $webhook;

    /**
     * Url to call
     *
     * @access private
     * @var string
     */
    private $url = '';

    /**
     * Constructor
     *
     * @access public
     * @param  string           $url       URL to call
     * @param  \Model\Webhook   $webhook   Webhook model instance
     */
    public function __construct($url, Webhook $webhook)
    {
        $this->url = $url;
        $this->webhook = $webhook;
    }

    /**
     * Execute the action
     *
     * @access public
     * @param  array   $data   Event data dictionary
     * @return bool            True if the action was executed or false when not executed
     */
    public function execute(array $data)
    {
        $this->webhook->notify($this->url, $data);
        return true;
    }
}