1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Jitamin. |
5
|
|
|
* |
6
|
|
|
* Copyright (C) Jitamin Team |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Jitamin\Notification; |
13
|
|
|
|
14
|
|
|
use Jitamin\Foundation\Base; |
15
|
|
|
use Jitamin\Foundation\Notification\NotificationInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Webhook Notification. |
19
|
|
|
*/ |
20
|
|
|
class WebhookNotification extends Base implements NotificationInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Send notification to a user. |
24
|
|
|
* |
25
|
|
|
* @param array $user |
26
|
|
|
* @param string $event_name |
27
|
|
|
* @param array $event_data |
28
|
|
|
*/ |
29
|
|
|
public function notifyUser(array $user, $event_name, array $event_data) |
30
|
|
|
{ |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Send notification to a project. |
35
|
|
|
* |
36
|
|
|
* @param array $project |
37
|
|
|
* @param string $event_name |
38
|
|
|
* @param array $event_data |
39
|
|
|
*/ |
40
|
|
|
public function notifyProject(array $project, $event_name, array $event_data) |
41
|
|
|
{ |
42
|
|
|
$url = $this->settingModel->get('webhook_url'); |
|
|
|
|
43
|
|
|
$token = $this->settingModel->get('webhook_token'); |
|
|
|
|
44
|
|
|
|
45
|
|
|
if (!empty($url)) { |
46
|
|
|
if (strpos($url, '?') !== false) { |
47
|
|
|
$url .= '&token='.$token; |
48
|
|
|
} else { |
49
|
|
|
$url .= '?token='.$token; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$payload = [ |
53
|
|
|
'event_name' => $event_name, |
54
|
|
|
'event_data' => $event_data, |
55
|
|
|
]; |
56
|
|
|
|
57
|
|
|
$this->httpClient->postJson($url, $payload); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.