|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* Copyright (C) 2018 |
|
5
|
|
|
* Nathan Boiron <[email protected]> |
|
6
|
|
|
* Romain Canon <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This file is part of the TYPO3 NotiZ project. |
|
9
|
|
|
* It is free software; you can redistribute it and/or modify it |
|
10
|
|
|
* under the terms of the GNU General Public License, either |
|
11
|
|
|
* version 3 of the License, or any later version. |
|
12
|
|
|
* |
|
13
|
|
|
* For the full copyright and license information, see: |
|
14
|
|
|
* http://www.gnu.org/licenses/gpl-3.0.html |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
namespace CuyZ\Notiz\Domain\Notification\Slack\Application\EntitySlack\Service; |
|
18
|
|
|
|
|
19
|
|
|
use CuyZ\Notiz\Core\Channel\Payload; |
|
20
|
|
|
use CuyZ\Notiz\Domain\Notification\Slack\Application\EntitySlack\Data\SlackChannel; |
|
21
|
|
|
use CuyZ\Notiz\Domain\Notification\Slack\Application\EntitySlack\EntitySlackNotification; |
|
22
|
|
|
use CuyZ\Notiz\Domain\Notification\Slack\Application\EntitySlack\Settings\EntitySlackSettings; |
|
23
|
|
|
|
|
24
|
|
|
class EntitySlackChannelMapper |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var EntitySlackNotification |
|
28
|
|
|
*/ |
|
29
|
|
|
private $notification; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var EntitySlackSettings |
|
33
|
|
|
*/ |
|
34
|
|
|
private $notificationSettings; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param Payload $payload |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct(Payload $payload) |
|
40
|
|
|
{ |
|
41
|
|
|
$this->notification = $payload->getNotification(); |
|
42
|
|
|
$this->notificationSettings = $payload->getNotificationDefinition()->getSettings(); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Returns an array of channels from a custom one and/or from one or |
|
47
|
|
|
* more defined ones. |
|
48
|
|
|
* |
|
49
|
|
|
* @return SlackChannel[] |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getChannels() |
|
52
|
|
|
{ |
|
53
|
|
|
$channels = []; |
|
54
|
|
|
|
|
55
|
|
|
if ($this->notification->hasCustomSlackChannel()) { |
|
56
|
|
|
$channels[] = SlackChannel::fromNotification($this->notification); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
$identifiers = explode(',', $this->notification->getSlackChannel()); |
|
60
|
|
|
|
|
61
|
|
|
foreach ($this->notificationSettings->getChannels() as $channel) { |
|
62
|
|
|
if (in_array($channel->getIdentifier(), $identifiers)) { |
|
63
|
|
|
$channels[] = SlackChannel::fromDefinition($channel); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return $channels; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|